dousong5161 2013-11-03 15:16
浏览 34
已采纳

过滤PHP中的数组

im doing some work with the Magento SOAP API and i am trying to create a valid list of orders. I have got the list but it shows both the configurable products as well as simple product giving me duplicating like the image below: item list

The first listing of the same product is the configurable product, the second is the simple product. What i need to do is filter out the simple products so they dont shown in the list or get stored. This sounds simple but there is one problem that im struggling to get my head around how to solve, and that is products like the Nokia in the image above are standard simple products and have no configurable properties and they also need to be shown!

So basically i need to get rid of the simple products relating to the configurable products but none others.

Here is my loop and array push:

foreach($sales_order_info->items as $i){
                $nextItem = new item();
                $nextItem->set_order_id($i->order_id);
                $nextItem->set_sku($i->sku);
                $nextItem->set_name($i->name);
                $nextItem->set_qty_ordered($i->qty_ordered);
                $nextItem->set_price($i->price);
                $nextItem->set_row_total($i->row_total);

                array_push($this->items, $nextItem);
            }

Thanks very much

  • 写回答

1条回答 默认 最新

  • doudai8783 2013-11-03 16:40
    关注

    If you need to filter simple product of a configurable product:

     if ($product->getProductType() == Mage_Catalog_Model_Product_Type::TYPE_SIMPLE) {              
        if ( $product->getParentItemId()) {
                            $parent_product_type = Mage::getModel('sales/order_item')->load($product->getParentItemId())->getProductType();
                            //if Parent product type is configurable don't output its simple product
                            if ($parent_product_type == Mage_Catalog_Model_Product_Type::TYPE_CONFIGURABLE) {
                                continue; 
                            }
                        }
    }
    

    If you don't want to extend Magento API and write your own custom calls you can try the following.

    The second option is to try using (not sure how you load it, with what Call):

    $i->type
    

    and then filter the array with PHP (i.e. if there are 2 elements with the same name and quantity remove the one that has type==simple)

    Or the third option would be (if you don't have any free products) just check if price is equal to zero, as simple products which belong to configurable has price = 0.0000

    if ($i->price==0.0000) {
        continue;
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 抖音咸鱼付款链接转码支付宝
  • ¥15 ubuntu22.04上安装ursim-3.15.8.106339遇到的问题
  • ¥15 求螺旋焊缝的图像处理
  • ¥15 blast算法(相关搜索:数据库)
  • ¥15 请问有人会紧聚焦相关的matlab知识嘛?
  • ¥15 网络通信安全解决方案
  • ¥50 yalmip+Gurobi
  • ¥20 win10修改放大文本以及缩放与布局后蓝屏无法正常进入桌面
  • ¥15 itunes恢复数据最后一步发生错误
  • ¥15 关于#windows#的问题:2024年5月15日的win11更新后资源管理器没有地址栏了顶部的地址栏和文件搜索都消失了