简体   繁体   English

Magento表格费率自定义选项

[英]Magento table rates custom options

In Tablerate.php I want to change the calculation. 在Tablerate.php中,我想更改计算。

So for some Products with custom options like width, height the shipping cost must change. 因此,对于某些具有自定义选项(例如宽度,高度)的产品,运输成本必须更改。 I tried with this method to find out if one product in cart has width or height greater than 60cm (example). 我尝试使用这种方法来确定购物车中的一种产品的宽度或高度是否大于60厘米(示例)。

But currently I have no Idea how to get custom option values... 但是目前我不知道如何获取自定义选项值...

this code working well. 该代码运行良好。

foreach ($request->getAllItems() as $item) {

        echo 'Name: '.$item->getName().
            '<br/> SKU:'.$item->getSku().
            '<br/> ProductID: '.$item->getProductId().
            '<br/> Price: '.$item->getPrice().'<br/>';   }

If the custom attribute is, for example cm_size then do: 如果自定义属性,例如cm_size然后执行:

$item->getCmSize()

or $item->getData('cm_size') $item->getData('cm_size')

this worked 这工作

foreach ($request->getAllItems() as $item) {
    $selectedOpt = $item->getProduct()->getTypeInstance(true)->getOrderOptions($item->getProduct());
    $counted =  count($selectedOpt['options']);
    for ($i = 0; $i < $counted; $i++) {
        echo '<br/>'. var_dump($selectedOpt['options'][$i]['option_value']);
    }
    echo '<br/>';
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM