1

Using the SKU as a guide (sales_order_item.sku), how can I get the simple product name of the configurable product?

This code gets the configurable product name (should be simple)

public function applyBaseFilters($collection)
{
    $this->joinCategoryTable($collection);
    $collection->getSelect()
        ->reset(\Zend_Db_Select::COLUMNS);

   $collection->getSelect()
       ->columns([
           'total' => 'SUM(sales_order_item.base_row_total)',
           'qty' => 'FLOOR(SUM(sales_order_item.qty_ordered))',
           'sku' => 'sales_order_item.sku',
           'name' => 'sales_order_item.name',
           'order_id' => 'CONCAT(sales_order_item.order_id,\''.$this->createUniqueEntity().'\')'
       ])
   ;
}

This code gets the correct simple product name but the quantity is not correct

public function applyBaseFilters($collection)
{
    $this->joinCategoryTable($collection);
    $collection->getSelect()
        ->reset(\Zend_Db_Select::COLUMNS);


    $collection->getSelect()->join(
        ['catalog_product_entity' => $this->getTable('catalog_product_entity')],
        'catalog_product_entity.sku = sales_order_item.sku',
        []
    )->join(
        ['catalog_product_entity_varchar' => $this->getTable('catalog_product_entity_varchar')],
        'catalog_product_entity_varchar.entity_id = catalog_product_entity.entity_id',
        []
    );

    $collection->getSelect()
        ->columns([
            'total' => 'SUM(sales_order_item.base_row_total)',
            'qty' => 'FLOOR(SUM(sales_order_item.qty_ordered))',
            'sku' => 'sales_order_item.sku',
            'name' => 'catalog_product_entity_varchar.value',
            'order_id' => 'CONCAT(sales_order_item.order_id,\''.$this->createUniqueEntity().'\')'
        ]);
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.