【问题标题】:Mag custom options issueMag自定义选项问题
【发布时间】:2012-12-14 15:10:26
【问题描述】:

我正在使用以下代码来获取和处理自定义选项

$orderIncrementId = $order->getIncrementId();
                $orderReal = Mage::getModel('sales/order')->loadByIncrementId($orderIncrementId);    


    $orderItems = $orderReal->getAllItems();   

    $sk = "";
    foreach ($orderItems as $item)
                {
      $options = $item->getProductOptions();      
      foreach ($options as $option) {
       if (is_array($option)) {
       $firstElement = array_shift($option);

   foreach ($option as $firstElement){
           if (isset($firstElement['label']) && isset($firstElement['option_value'])){
         if ($firstElement['label'] == 'Delivery Date') {
             $deliveryDate = $firstElement['option_value'];

                                }
                            }
                        }
                    }   
                  }
                }

我的用法是像这样将其写入CSV

if (isset($deliveryDate)) {
    $outputString.= '"'.$deliveryDate.'",'; 
} else {
    $outputString.= '"deliverydate error",'; 
}

现在,我已经确定了

  • 标签交货日期可在数据库“目录产品选项标题表”中获得
  • 自定义选项交货日期在“目录产品选项”中具有值 表”

似乎没有通过脚本访问交货日期,因此我的自定义消息“交货日期错误”保存在 CSV 中

实际上我正在尝试调试无法正常工作的 mag 扩展...

对我来说,代码还可以,但不知道为什么它不起作用....

有人可以指导我吗?

【问题讨论】:

    标签: php arrays magento loops csv


    【解决方案1】:

    虽然这不是完美的解决方案,但假设您的产品自定义选项是“字段”类型,这将返回您订购商品的自定义选项值。

    foreach ($orderItems as $item) {
      $optionsArray = $item->getProductOptions();
      if(isset($optionsArray['options'])) {
        foreach ($optionsArray['options'] as $option) {
          if($option['label'] == 'Delivery Date') {
            $deliveryDate = $option['value'];
          }
        }
      }
    }
    

    【讨论】:

    • 感谢您的帮助,您能告诉我我的代码有什么错误吗?为什么它不工作?我确定没问题
    • 您拥有的整个逻辑都是无用的。只需使用我的 foreach 循环而不是您的循环,它应该可以完美运行。
    猜你喜欢
    • 2014-09-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多