1

I am trying to get an attribute value to fill in to prefix on some mini cart items if the custom attribute value is filled in. However I am getting a value for previous cart items in the same shopping cart. The following is the code for getting the attribute and adding it to the item data that is used to fill the mini cart:

    public function aroundGetItemData(AbstractItem $abstractItem, \Closure $result, Item $item)
{
    $returnedArray = $result($item);
    $objectManager = \Magento\Framework\App\ObjectManager::getInstance();
    $product = $objectManager->get('Magento\Catalog\Model\Product')->load($item->getProduct()->getId());

    error_log($item->getSku() . " - " . $product->getSku() . " - " . $product->getCustomAttribute());
    return \array_merge(
        ['product_sku' => $item->getSku(), 'product_custom_attribute' => $product->getCustomAttribute()],
        $returnedArray
    );
}

When I log the values out I get:

[23-Aug-2016 00:35:01 UTC] BC6CANL - BC6CANL - custom attribute text
[23-Aug-2016 00:35:01 UTC] BCIIA2F14 - BCIIA2F14 - custom attribute text

The text of the first log entry is correct for SKU 123456, but the text for 654321 should be empty as that attribute is blank for that product. Any ideas?

1
  • U need to put condition if product's attribute has value then it only logs otherwise not?
    – Jackson
    Sep 29, 2016 at 9:59

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Browse other questions tagged or ask your own question.