问题
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