【问题标题】:Add to cart with product custom option in Magento在 Magento 中使用产品自定义选项添加到购物车
【发布时间】:2013-11-26 06:28:50
【问题描述】:

我有一个带有自定义选项(类型 1 和类型 2)的虚拟产品。价格可能会因类型而异。如何使用此选项直接添加到购物车并根据自定义选项更改价格。我试过这段代码,但它不起作用。

<?php
// the ID of the product
$product_id  = "123";

$product     = Mage::getModel('catalog/product')->load($product_id);

$cart = Mage::getModel('checkout/cart');
$cart->init();
$params = array(
    'product' => $product_id,
    'qty' => 1,
    'options' => array(
        'options' => array(
            '7462' => 'Type Option Id' ,
            '3731' => 'Type-1',
        )

    )
);

$cart->addProduct($product, $params);
$cart->save();

Mage::getSingleton('checkout/session')->setCartWasUpdated(true);
$this->_redirect('checkout/cart');

?>

【问题讨论】:

    标签: php magento-1.7 shopping-cart


    【解决方案1】:

    请尝试以下代码为您的产品添加选项:

    $quoteItem->addOption(new Varien_Object(
        array(
            'product' => $quoteItem->getProduct(),
            'code' => 'additional_options',
            'value' => serialize($a_options)
        )
    ));
    

    参考这里:add product to cart with custom options

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2013-06-26
      • 1970-01-01
      • 1970-01-01
      • 2020-09-06
      • 2023-04-02
      • 1970-01-01
      • 2023-03-10
      相关资源
      最近更新 更多