Magento - Get Product Parameters from $ item

There is the following foreach loop on the cart page:

foreach($this->getItems() as $_item) { } 

I need to get product parameters for these elements, I tried several methods, but I can not get the desired results.

I tried:

 foreach($this->getItems() as $_item) { print_r($_item->getProductOptions()); } 

and

 foreach($this->getItems() as $_item) { print_r($_item->getOptionList()); } 

Are there any other features that I could use?

+7
source share
5 answers

Try using:

 $_item->getProduct()->getTypeInstance(true)->getOrderOptions($_item->getProduct()); 
+24
source

This can lead to a start in the right direction ...

 $productSku = "ABCDE"; $product = Mage::getModel('catalog/product'); $productId = $product->getIdBySku( $productSku ); $product->load($productId); /** * In Magento Models or database schema level, the product Custom Options are * executed & maintained as only "options". So, when checking whether any product has * Custom Options or not, we should check by using this method "hasOptions()" only. */ if($product->hasOptions()) { echo '<pre>'; foreach ($product->getOptions() as $o) { $optionType = $o->getType(); echo 'Type = '.$optionType; if ($optionType == 'drop_down') { $values = $o->getValues(); foreach ($values as $k => $v) { print_r($v); } } else { print_r($o); } } echo '</pre>'; } 
+1
source

Maybe so:

 foreach($items as $product) { $options = $product->getProduct()->getTypeInstance(true)->getOrderOptions($product->getProduct()); if ($options) { if (isset($options['options'])) { $result = $options['options']; } if(count($result)>0){ foreach($result as $key =>$value){ $resultoption = $value['value']; } } } 
0
source

The current answer in its current form is not for me. Whatever type $_item a getProduct() method can have.

On the other hand, you will likely have an id available with which you can directly download. In my example, I needed to get a product object from an element in $_items = $this->helper('catalog/product_compare')->getItemCollection() .

This allows me to use: <?php $product = Mage::getModel('catalog/product')->load($_item->getId()) ?>

0
source

You cannot get the list of options on cart.phtml, you need to update / change the file below for the list of options:

 app\design\frontend\YOUR_PACKAGE_NAME\YOUR_TEMPLATE_NAME\template\checkout\cart\item\default.phtml 

Hope this helps!

-7
source

Source: https://habr.com/ru/post/956412/