为什么添加产品后购物车为空 [英] Why cart is empty after add product
问题描述
我使用数组选择要购物车数据库销售单位报价的项目 第2行是销售单位报价中的数组 行是数组形式的产品订单
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
感谢每个答案
编辑是否有机会在'cart.php'中的'function choiceTemplate()'不显示空模板是购物车中有物品
Edit if i chance 'function chooseTemplate() ' in 'cart.php' to don't show empty template is have item in cart
如果我通过插入添加此检查,如何+项计数
$itemsCount = $this->getItemsCount() ? $this->getItemsCount() : $this->getQuote()->getItemsCount();
how to +items count if i add by insert into for this check
$itemsCount = $this->getItemsCount() ? $this->getItemsCount() : $this->getQuote()->getItemsCount();
使用空项
推荐答案
<?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";
这篇关于为什么添加产品后购物车为空的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!