duanpang2751 2014-07-05 14:15
浏览 46
已采纳

Magento添加到购物车按钮

So I am working freelance on a project and need to know how to create a working 'add to cart' button using Magento that takes the user to the cart with the product populated. The company uses specific SKU's to identify the individual products. So, how do create such a button? The button needs to pass the SKU to the cart page (which uses a simple URL, the same one for all products). Thanks.

  • 写回答

1条回答 默认 最新

  • dongnao3990 2014-07-07 05:11
    关注

    That is provided with the default installation of magento, ain't it?

    But if you are referring to custom Add To cart button for a customized page/product then create a button/link and pass product ID and quantity and options value to the controller and handle as shown below:

    For simple product

    $params = array(
        'product' => 1, //prooduct ID
        'qty' => 2, //Quantity
    );
    $cart = Mage::getSingleton('checkout/cart'); 
    $product = Mage::getModel('catalog/product')->load(1); //loading product obj
    $cart->addProduct($product, $params); //adding to cart
    $cart->save(); 
    Mage::getSingleton('checkout/session')->setCartWasUpdated(true);
    //now redirect user to either cart or checkout
    

    For Configurable product

    the param set up will be a little different

    $params = array(
        'product' => 1,
        'super_attribute' => array(
             51 =>25, //this is for the options 51 - option code //25 is the option selected
        ),
        'qty' => 2,
    );
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 对于相关问题的求解与代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 信号傅里叶变换在matlab上遇到的小问题请求帮助
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作