0

I'm trying to get custom attribute from product, I've make 3 news attributes (width, height, length). I want get it to quote shipping value.

$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
$cart = $objectManager->get('\Magento\Checkout\Model\Cart'); 
$items = $cart->getQuote()->getAllVisibleItems();

foreach($items as $item){
$width = $item->getData('width');
//NOT WORKING
}
0

You added custom attribute on product level, So in this code you will not be able to get the attribute value because the $item variable is a Quote Item Object and not Product Object.

You should be able to get the custom attribute value by this way

foreach($items as $item){
    $width = $item->getProduct()->getData('width');
}
| improve this answer | |
  • Is not working, i need use something more? use Magento\Framework\Webapi\Soap\ClientFactory; use Magento\Quote\Model\Quote\Address\RateRequest; use Magento\Shipping\Model\Rate\Result; use Magento\Shipping\Model\Carrier\AbstractCarrier; use Magento\Shipping\Model\Carrier\AbstractCarrierOnline; use Magento\Shipping\Model\Carrier\CarrierInterface; use Magento\Shipping\Model\Simplexml\Element; use Magento\Framework\Xml\Security; – Kan Mar 29 '18 at 12:39
0

Create a file app/code/[YourCompany]/[YourModule]/etc/catalog_attributes.xml with following content:

<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Catalog:etc/catalog_attributes.xsd">
    <group name="quote_item">
        <attribute name="width"/>
        <attribute name="height"/>
        <attribute name="length"/>
    </group>
</config>

and call it like this:

$item->getProduct()->getAttributeText('width');

Note: You should not use ObjectManager to load any model directly, use dependency injection for that.

| improve this answer | |

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.