Skip to content
Snippets Groups Projects

Fixed order items getting an empty title if the source line item’s product has been deleted or had its title changed.

1 file
+ 25
6
Compare changes
  • Side-by-side
  • Inline
@@ -56,12 +56,31 @@ class LineItem extends FieldableEntity {
// Get the product title from the commerce_product table.
if ($row->getSourceProperty('type') === 'product') {
$label = $row->getSourceProperty('line_item_label');
$query = $this->select('commerce_product', 'cp')
->fields('cp', ['title'])
->condition('cp.sku', $label);
$title = $query->execute()->fetchCol();
$row->setSourceProperty('title', reset($title));
// If the line item has a single product ID in its context data, use that
// to look up the product. If not, fall back on trying to match the line
// item title, which may fail if the product has had its title changed
// since the order was created.
$data = $row->getSourceProperty('data');
if (isset($data['context']['product_ids']) && count($data['context']['product_ids']) == 1) {
$product_id = reset($data['context']['product_ids']);
$query = $this->select('commerce_product', 'cp')
->fields('cp', ['title'])
->condition('cp.product_id', $product_id);
$title = $query->execute()->fetchField();
}
else {
$label = $row->getSourceProperty('line_item_label');
$query = $this->select('commerce_product', 'cp')
->fields('cp', ['title'])
->condition('cp.sku', $label);
$title = $query->execute()->fetchField();
}
// Override the title source field if we got a title from the product.
if (!empty($title)) {
$row->setSourceProperty('title', $title);
}
}
// Get Field API field values.
Loading