我想输出我的产品数量,但如果产品有组合,我无法得到数量。
我用:$product[ 'quantity' ]来获取产品数量。如果我有没有组合的产品,它就能工作。
奇怪的是,在BO中,如果我打开产品标签,我可以看到总量: 20 (10 qnt红梳,10 qnt黑梳)。所以对我来说没问题。但当我输出数据时,我得到的数量:0,因为主要产品数量:0和产品有10个红色qnt和10个黑色qnt组合。我可以得到属性列表,但如何得到组合列表与数量或只是总量?
发布于 2014-08-11 10:44:30
如果在Front模板上需要它,则需要调用is作为对象属性:
{$product->quantity}这将返回所有组合的总数量。
如果您需要它在控制器,它是相同的:
$product = new Product($id_product);
echo $product->quantity;这将再次返回所有组合的总数量。
关于数据库:数量保存在: ps_stock_available表中。如果您需要获得产品的总数量(包括组合),请获取" quantity“字段,其中"id_product_attribute”= 0。
下面是一个使用ID=1的产品示例查询:
SELECT p.id_product, sa.quantity
FROM ps_product p
INNER JOIN ps_stock_available sa ON p.id_product = sa.id_product AND id_product_attribute = 0
WHERE p.id_product = 1如果循环遍历来自$products =Product::getProducts(.)的产品
foreach ($products as $product)
echo Product::getQuantity($product['id_product']);发布于 2015-03-31 13:28:50
在模板(Smarty)中,可以使用:
{$product->quantity_all_versions}
{$product.quantity_all_versions}发布于 2016-06-17 18:08:19
要获得尺寸的数量,我使用高级-> SQL管理器。
SELECT DISTINCT CONCAT(ps_product_lang.id_product) AS ID, CONCAT(ps_product_lang.name) AS Nazwa, CONCAT(ps_attribute_lang.name) AS Rozmiar, CONCAT(ROUND(ps_product_shop.price*1.23,2)) AS Cena, CONCAT(ps_stock_available.quantity) AS Ilość, CONCAT('http://pasujemito.pl/',ps_category_lang.link_rewrite,'/',ps_product_lang.id_product,'-',ps_product_lang.link_rewrite,'.html') AS Link
FROM ps_stock_available INNER JOIN ps_product_lang
USING (id_product) INNER JOIN ps_product_attribute_combination
USING (id_product_attribute) INNER JOIN ps_attribute_lang
USING (id_attribute) INNER JOIN ps_product_shop
USING (id_product) INNER JOIN ps_category_product
USING (id_product) INNER JOIN ps_category_lang
USING (id_category)
WHERE quantity=0 AND id_category NOT IN (1 ,2, 44, 45, 46, 75) AND (id_product_attribute!=0)
ORDER BY Nazwa;或者如果我想看到图像链接:
SELECT DISTINCT CONCAT(ps_product_lang.id_product) AS ID, CONCAT(ps_product_lang.name) AS Nazwa, CONCAT(ps_attribute_lang.name) AS Rozmiar, CONCAT(ROUND(ps_product_shop.price*1.23,2)) AS Cena, CONCAT(ps_stock_available.quantity) AS Ilość, CONCAT('http://pasujemito.pl/',ps_image.id_image,'-tm_thickbox_default/',ps_product_lang.link_rewrite,'.jpg') AS Zdjęcie
FROM ps_stock_available INNER JOIN ps_product_lang
USING (id_product) INNER JOIN ps_product_attribute_combination
USING (id_product_attribute) INNER JOIN ps_attribute_lang
USING (id_attribute) INNER JOIN ps_product_shop
USING (id_product) INNER JOIN ps_image
USING (id_product)
WHERE quantity=0 AND (ps_image.position=1) AND (id_product_attribute!=0)
ORDER BY Nazwa;https://stackoverflow.com/questions/25183466
复制相似问题