doucha7329 2013-11-26 06:28
浏览 15

添加到购物车中,并在Magento中提供产品定制选项

I have a virtual product with custom option (type-1 and type-2). Price may change depend on type. How can I add to cart with this option directly and change the price depend on custom option. I tried this code but it doesn't work.

<?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');

?>
  • 写回答

1条回答 默认 最新

  • dougu2240 2013-11-26 14:10
    关注

    Please try following code to add option to your product :

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

    Ref Here : add product to cart with custom options

    评论

报告相同问题?

悬赏问题

  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测