0

我正在寻找一个片段,它将为我提供包装的长度、宽度和高度,以运送当前在购物车中的物品。

我正在创建一个运费模块,这是拼图的最后一块。

非常感谢任何信息!

杰夫

4

2 回答 2

3

看看@Create Shipping Method Module

collectRates(Mage_Shipping_Model_Rate_Request $request)您可以使用

 $request->getAllItems()

见/app/code/core/Mage/Shipping/Model/Rate/Request.php

所以你可以循环遍历每个项目以获取它们的尺寸

foreach($request->getAllItems() as $item){
    //do you logic per item
     $item->getLength();
     $item->getWidth();
     $item->getHeight();
}
于 2013-01-15T18:52:47.010 回答
0

上面的答案对我不起作用,也许是因为它是 5 年前写的,从那时起事情可能发生了很大变化......

它不起作用的原因是 $item 对象没有返回(长度,宽度或高度)。

我通过使用 $Item 对象中的相同 $Product 对象重新加载产品来解决它,如下所示:

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

   $ProductID = $Item->getProductId();
   $Product = $Item->getProduct();             // Product Object

   if ($Product)
   {
       $ProductFull = $Product->load($ProductID); // This is the important part, mainly because the original $Product doesn't have the extended attributes loaded, this way we get them all and then you could read any attribute you like without having additional classes on the constructor...

       $W = $ProductFull->getWidth();
       $H = $ProductFull->getHeight();
       $D = $ProductFull->getDepth();

       $WHATEVER = $ProductFull->getWhateverCustomAttributeYouNeed();
   }
}

H

于 2021-01-28T20:34:22.350 回答