In Tablerate.php I want to change the calculation.

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).

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/>';   }
有帮助吗?

解决方案 2

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/>';
}

其他提示

If the custom attribute is, for example cm_size then do:

$item->getCmSize()

or $item->getData('cm_size')

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top