在购物车中显示Magento自定义选项值

Sam*_*ger 1 php magento e-commerce

我的Magento网站上的一些产品有自定义选项(不是属性).如果有一种产品有金色或银色可供选择,那么它有两种选择.如何获取用户选择在购物车页面上的产品名称旁边显示的选项的名称?

小智 9

要在购物车页面上获取设置为"AddtoCart"的产品自定义选项值,请尝试使用以下代码.

$cart = Mage::helper('checkout/cart')->getCart()->getQuote()->getAllItems();

/* cart item loop */
foreach($cart as $item) {

    /* This will get custom option value of cart item */
    $_customOptions = $item->getProduct()->getTypeInstance(true)->getOrderOptions($item->getProduct());

    /* Each custom option loop */
    foreach($_customOptions['options'] as $_option){
        echo $_option['label'] .'=>'. $_option['value']."<br/>";
        // Do your further logic here
    }
}
Run Code Online (Sandbox Code Playgroud)