【问题标题】:Why cart is empty after add product为什么添加产品后购物车为空
【发布时间】:2014-09-11 03:30:47
【问题描述】:

我使用数组选择商品到购物车数据库销售平面报价商品 第 2 行是来自销售平面报价的数组 行是数组形式的产品订单

mysqli_query($cn,"INSERT INTO sales_flat_quote_item (quote_id,product_id,qty) values ({$row2['entity_id']},$product_id,{$row['qty']})");

此数据添加到购物车数据库销售平面报价项目,但

如果我插入数据库后我的购物车不是空的,产品将显示在购物车中 但是如果我的购物车在插入购物车后是空的,我会去添加到购物车并发送其他产品来展示这个产品

如何通过插入代码写入购物车更新

感谢每一个回答

如果我有机会在 'cart.php' 中使用 'function chooseTemplate()' 以不显示空模板在购物车中有项目,请编辑

如果我通过插入添加到此检查中,如何 + 项目计数 $itemsCount = $this->getItemsCount() ? $this->getItemsCount() : $this->getQuote()->getItemsCount();

使用空项目

【问题讨论】:

    标签: php mysql sql magento shopping-cart


    【解决方案1】:
    <?php
    require_once 'app/Mage.php'; //path to app/Mage.php
    Mage::app(); //run
    Mage::getSingleton('core/session', array('name'=>'frontend')); //load customer session
    
    $products = Mage::getModel('catalog/product');
    $sku = '123'; //your sku here
    $pid = $products->getIdBySku($sku); //product id
    $product = $products->load($pid);
    $qty = 1; //your quantity here
    
    $cart = Mage::getModel('checkout/cart');
    $cart->init();
    $cart->addProduct($product, array('qty' => $qty));
    $cart->save();
    
    Mage::getSingleton('checkout/session')->setCartWasUpdated(true);
    echo "SKU [".$sku ."] was added to cart";
    

    【讨论】:

      猜你喜欢
      • 2015-05-03
      • 2016-12-19
      • 1970-01-01
      • 2020-05-30
      • 1970-01-01
      • 2014-08-02
      • 2015-10-24
      • 1970-01-01
      • 2012-06-09
      相关资源
      最近更新 更多