php magento选择捆绑

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了php magento选择捆绑相关的知识,希望对你有一定的参考价值。

<?php
//ini_set('memory_limit','10G');
require_once('abstract.php');

class Bundle_Cart_Item_Option_Items extends Mage_Shell_Abstract
{
    /**
     * Entry point
     */
    public function run()
    {
        $selections = array();
        $cart = Mage::getModel('checkout/cart')->getQuote();
        if(!$cart->getAllItems()){
            var_dump('empty cart');
            return;
        }
        foreach ($cart->getAllItems() as $_item) {
            $selections = $this->getBundleOrderItemSelections($_item->getProduct());
        }

        var_dump($selections);
    }

    /**
     * @param $bundleProduct Mage_Catalog_Model_Product
     * @return array
     */
    public function getBundleOrderItemSelections($bundleProduct)
    {
        $selectionSkus = array();
        if($bundleProduct->getTypeId()==='bundle') {
            /** @var Mage_Bundle_Model_Product_Type $instance */
            $instance = $bundleProduct->getTypeInstance(true);

            $customOption = $bundleProduct->getCustomOption('bundle_selection_ids');
            $selectionIds = unserialize($customOption->getValue());

            $selections = $instance->getSelectionsByIds($selectionIds, $bundleProduct);

            foreach ($selections->getItems() as $selection) {
                $selectionSkus[] = $selection->getSku();
            }

        }

        return array_unique($selectionSkus);
    }


}



$ids = new Bundle_Cart_Item_Option_Items();
$ids->run();

以上是关于php magento选择捆绑的主要内容,如果未能解决你的问题,请参考以下文章

Magento:添加了捆绑项目,但重新加载时它们是空的

Magento - 以编程方式添加的捆绑产品不适用于购物篮/前端

php 获取具有选择的捆绑选项

php 获取具有选择的捆绑选项

Magento2 php商城在windows10上安装

php 获取具有选项的捆绑产品的产品ID,该选项多于客户必须选择选项的产品ID