首页 文章

Magento - 捆绑产品内捆绑产品(几乎工作)

提问于
浏览
3

我'm trying to add bundle products inside another bundle product. It'很容易实现我的状态 . 像这样编辑文件 /app/code/Mage/Bundle/etc/config.xml

...
                <allowed_selection_types>
                    <simple/>
                    <bundle/> <!-- Add this at line 104-->
                    <virtual/>
                </allowed_selection_types>
                ...

通过这样做,您将能够成功地创建捆绑产品与其中的其他捆绑产品!

我的问题是我无法通过AdminPanel或SOAP将此产品添加到订单中(未尝试通过前端,但可能也不起作用) .

当我在管理面板中单击“将所选产品添加到订单”时,出现以下错误:

[19-Jun-2013 15:52:48 UTC] PHP Fatal error:  Call to a member function getPosition() on a non-object in app\code\core\Mage\Bundle\Model\Product\Type.php on line 865

崩溃发生在 shakeSelections($a, $b) :代码 $a->getOption() 不是't returns a object. It'不是空的它's also not an object (I'是一个PHP noobie,所以它对我来说没有意义) .

==Update==

现在我可以将这种新产品添加到购物车中!我编辑了文件app \ code \ core \ Mage \ Bundle \ Model \ Product \ Type.php,所以现在我有以下代码:

...
/*
 * Create extra attributes that will be converted to product options in order item
* for selection (not for all bundle)
*/
$price = $product->getPriceModel()->getSelectionFinalTotalPrice($product, $selection, 0, $qty);
$attributes = array(
        'price'         => Mage::app()->getStore()->convertPrice($price),
        'qty'           => $qty,
        'option_label'  => is_null($selection->getOption()) ? '' : $selection->getOption()->getTitle(),
        'option_id'     => is_null($selection->getOption()) ? 0 : $selection->getOption()->getId()
);

$type = $selection->getTypeInstance(true);
if (get_class($type) != 'Mage_Bundle_Model_Product_Type'){
    $_result = $selection->getTypeInstance(true)->prepareForCart($buyRequest, $selection);
}
...

以及下面的功能:

public function shakeSelections($a, $b)
{
    $ta = $a->getOption();
    $tb = $b->getOption();

    $aPosition = array(
            is_null($ta) ? 0 : $ta->getPosition(),
            $a->getOptionId(),
            $a->getPosition(),
            $a->getSelectionId()
    );
    $bPosition = array(
            is_null($tb) ? 0 : $tb->getPosition(),
            $b->getOptionId(),
            $b->getPosition(),
            $b->getSelectionId()
    );
    if ($aPosition == $bPosition) {
        return 0;
    } else {
        return $aPosition < $bPosition ? -1 : 1;
    }
}

我正在调查,以发现我引入的可能的副作用 . 此时我发现这捆捆绑产品的库存管理存在问题 .

如果您继续进行,请发布您的更新 . 非常感谢!

==第二次编辑==

我已经在github上开始了这个回购,所以你可以跟进我的进展,也许可以帮助我 .

https://github.com/matheusjadimb/MagentoBundleOfBundled

1 回答

  • 2

    就是不要这样做!

    我有很多困难,试图让这个工作正常 . 我了解到您应该创建自己的产品类型而不是编辑现有的产品类型 .

相关问题