Why cart is empty after add product

≡放荡痞女 提交于 2019-12-23 06:12:05

问题


i use array to select item to cart database sales flat quote item row 2 is array from sales flat quote row is array form product order

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

this data add to cart database sales flat quote item but

if my cart is not empty after i insert into database product will show in cart but if my cart is empty after insert into cart will empty to show this product i will go to add to cart and send other product to show this product

how i can write to cart update with my insert into code

thank for every answer

Edit if i chance 'function chooseTemplate() ' in 'cart.php' to don't show empty template is have item in cart

how to +items count if i add by insert into for this check $itemsCount = $this->getItemsCount() ? $this->getItemsCount() : $this->getQuote()->getItemsCount();

to use empty item


回答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";


来源:https://stackoverflow.com/questions/25778585/why-cart-is-empty-after-add-product

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!