1

I'm trying to list all the products in the cart, and list the chosen color/size, etc.. that they have. On the main website, Magento seems to do that. However, when I try to do it programmatically, I get the custom attributes as null.

This is my current code:

    $quote->getAllVisibleItems();

    foreach ($allCartItems as $item) {

        $productInfo = array();
        $product = $item->getProduct();
        $productInfo["size"] = $product->getSize();
        ...
    }

If I use getAllItems() instead of getAllVisibleItems(), then I will end up with simple/configurable products, which will cause an issue as to which item id the app has to use when updating the product (as well as listing duplicate items).

The only solution I found online was to load the product again using $product = $model->load($model->getIdBySku($sku)); for every product listed, but that seems to be like it will quite the performance hog!

How can I have the getAllVisibleItems() return the chosen attributes and attribute values of the configurable products it returns?

enter image description here

[
    {
    name: "Tori Tank",
    price: "60.0000",
    id: "418",
    product_id: "418",
    item_id: "2481",
    sku: "wbk004",
    color: null,
    size: null,
    quantity: 1
    },
    {
    name: "Chelsea Tee",
    price: "75.0000",
    id: "410",
    product_id: "410",
    item_id: "2483",
    sku: "mtk005",
    color: null,
    size: null,
    quantity: 1
    }
]

As you can see, the color/size are being returned as null.

2

Quick solution:

$item->getProduct()->getTypeInstance(true)->getOrderOptions($item->getProduct());

Explanation:

You have an issue because when you run $item->getProduct(); you just receive this configurable product. Its the same if you run Mage::getModel('catalog/product')->load($someConfigurableProductId)

  • Thank you for your reply. I tried it, and it works great! – Pat Apr 9 '15 at 5:28
  • I just had 1 question. Is it normal for the request to benchmark around 1 second for, say, 10 products? Before I was getting the option, the benchmark was around 0.3 seconds. Now I'm getting around 0.9-1.1 seconds benchmark. I want to see if it that's normal or not. – Pat Apr 9 '15 at 5:47
  • Unfortunately I can't provide you figures. I don't know how much time should take any procedure. On practice I noticed that procedure of loading product is very complicated. And for best performance you need to decrease the number of loading products. Also using flat in that case can be one of solutions. – zhartaunik Apr 9 '15 at 10:43

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.