Posting in the Magento forums has been disabled pending the implementation of a new and improved forum solution which should better serve the community.

For new questions please post at magento.stackexchange.com, the community-run support site for the Magento community. We will be providing updates on the new forum solution soon. For questions or concerns please email community@magento.com.

Magento Forum

Loading configurable products
 
stevensurowiec
Jr. Member
 
Total Posts:  15
Joined:  2008-06-23
 

I’m setting up a best sellers module and most of the site is configurable products, but for some reason the best sellers code I have so far is only loading the simple products that are part of the configurable product, so it’s not displaying the correct data. I tried adding a type filter but that found no results instead of loading the configurable product. I’ve scoured the forums to figure out what’s wrong as well as having read through the knowledge base, the wiki and a large chunk of the core code and haven’t been able to figure out anything.

The code I have so far is below, and the block is using the default catalog/product/list.phtml template.

public function _construct() {
        
// get the store id
        
$storeId Mage::app()->getStore()->getId();

        
// load the collection
        
$collection Mage::getResourceModel('reports/product_collection')
            ->
addOrderedQty()
            ->
addAttributeToSelect('*')
            ->
setStoreId($storeId)
            ->
addStoreFilter($storeId)
            ->
setOrder('ordered_qty''desc')
            ->
setPageSize(6)
            ->
setCurPage(1);

        
// assign some filters to the collection
        
Mage::getSingleton('catalog/product_status')->addVisibleFilterToCollection($collection);
        
Mage::getSingleton('catalog/product_visibility')->addVisibleInCatalogFilterToCollection($collection);

        
// load the collection and save it
        
$collection->load();
        
$this->setLoadedProductCollection($collection);
    
}

Any help would be greatly appreciated.
Thanks

 
Magento Community Magento Community
Magento Community
Magento Community
 
Vova Y.
Jr. Member
 
Total Posts:  1
Joined:  2008-08-10
 

I have the same problem.
Customers buying some variation of configurable product, and bestseller module gives the link to this simple products, not to main (configurable) product.
It would be great if there were some function ‘getParent’ that returns configurable product, which this simple belongs to.

 
Magento Community Magento Community
Magento Community
Magento Community
 
joyously
Guru
 
Total Posts:  447
Joined:  2008-08-21
 

The bestseller report looks at the quote tables and those do contain a field for parent_id.  Maybe all you need to do is add a field to the filter for parent_id = NULL.

Edit: I take that back. It’s not that simple. There is a parent_id field, but just checking it for NULL would mess up the count for bundles and groups. So there should be a way to distinguish configurables from bundles and groups and count them like simples and virtuals but not counted twice.  I’m looking in app\code\core\Mage\Reports\Model\Mysql4\Product\Collection.php in the addOrderedQty function where it does the check for simple or virtual.

 
Magento Community Magento Community
Magento Community
Magento Community
 
joyously
Guru
 
Total Posts:  447
Joined:  2008-08-21
 

OK, I got mine to show only the configurable products. Be aware that I don’t have any bundles or groups, so I’m not certain it doesn’t affect those, but it shouldn’t.
I modified app/code/core/Mage/Reports/Model/Mysql4/Product/Collection.php in the addOrderedQty function as follows

$this->getSelect()->reset()
            ->
from(
                array(
'order_items' => $qtyOrderedTableName),
                array(
'ordered_qty' => "SUM(order_items.{$qtyOrderedFieldName})"))
            ->
joinInner(
                array(
'order' => $this->getTable('sales/order')),
//                'order.entity_id = order_items.order_id'.$dateFilter,
                
'order.entity_id = order_items.order_id AND order_items.price > 0'.$dateFilter,
                array())
            ->
joinInner(array('e' => $this->getProductEntityTableName()),
//                "e.entity_id = order_items.{$productIdFieldName} AND e.entity_type_id = {$this->getProductEntityTypeId()}{$productTypes}")
                
"e.entity_id = order_items.{$productIdFieldName}")
            ->
group('e.entity_id')
            ->
having('ordered_qty > 0');

Changing it to take out the check for the product type results in both the configurable and the simple products showing on the report. This might be the way you want it since you can see results for whatever your simple product represents. In my case it’s shoe size, so that might actually be useful to find out what sizes are selling the most. But if you also do the first change to check for price greater than zero, you eliminate whichever ones don’t have a price. In my case, that’s my simple products. If yours have prices, this won’t do it. You might have to change it to check for something else that makes the one you want to see unique.

While I was in that file, I also changed the addCartsCount function to check for price > 0 as well. Now I only see my configurables in the Shopping Cart -> Products In Carts report instead of both simples and configurables (and before it was just simples).

This collection is also used for the Bestsellers dashboard report.

 
Magento Community Magento Community
Magento Community
Magento Community
 
roeschen
Jr. Member
 
Total Posts:  18
Joined:  2008-11-02
 

Me, too. Can someone help? I get also this error:

Error in file: “/home/lighting/domains/lightingdeluxe.com/public_html/app/code/core/Mage/Sales/sql/sales_setup/mysql4-upgrade-0.9.28-0.9.29.php” - SQLSTATE[42000]: Syntax error or access violation: 1103 Incorrect table name ‘’
Trace:
#0 /home/lighting/domains/lightingdeluxe.com/public_html/app/code/core/Mage/Core/Model/Resource/Setup.php(287): Mage::exception(’Mage_Core’, ‘Error in file: ...’)
#1 /home/lighting/domains/lightingdeluxe.com/public_html/app/code/core/Mage/Core/Model/Resource/Setup.php(179): Mage_Core_Model_Resource_Setup->_modifyResourceDb(’upgrade’, ‘0.9.28’, ‘0.9.29’)
#2 /home/lighting/domains/lightingdeluxe.com/public_html/app/code/core/Mage/Core/Model/Resource/Setup.php(146): Mage_Core_Model_Resource_Setup->_upgradeResourceDb(’0.9.28’, ‘0.9.29’)
#3 /home/lighting/domains/lightingdeluxe.com/public_html/app/code/core/Mage/Core/Model/Resource/Setup.php(121): Mage_Core_Model_Resource_Setup->applyUpdates()
#4 /home/lighting/domains/lightingdeluxe.com/public_html/app/code/core/Mage/Core/Model/Config.php(215): Mage_Core_Model_Resource_Setup::applyAllUpdates()
#5 /home/lighting/domains/lightingdeluxe.com/public_html/app/code/core/Mage/Core/Model/App.php(241): Mage_Core_Model_Config->init(Array)
#6 /home/lighting/domains/lightingdeluxe.com/public_html/app/Mage.php(427): Mage_Core_Model_App->init(’’, ‘store’, Array)
#7 /home/lighting/domains/lightingdeluxe.com/public_html/app/Mage.php(446): Mage::app(’’, ‘store’, Array)
#8 /home/lighting/domains/lightingdeluxe.com/public_html/index.php(52): Mage::run()
#9 {main}

 
Magento Community Magento Community
Magento Community
Magento Community
Magento Community
Magento Community
Back to top