Forum
Product variant id
Hi,
I am trying to figure out if is possible to retrieve the product variant ID inside my product detail view template.
In other words I have a product with variations and before i add to cart a product variant i would like to get his id.
Is it possible?
Also i am trying to use the function
perch_shop_product_variants(perch_get('item'));
but it seems that doesn't work for me. I have perch (2.8.32) and shop (1.0.10) to the latest versions.
here the debug if i try to use that function:
Debug Message
[1] SELECT * FROM perch2_members_sessions WHERE sessionID='c1ee12914a21483fbabc36e1af160c365e0a3880' AND sessionHttpFootprint='0fa3fd9f130dec88ef95f184a1a7543b59d2951d' AND sessionExpires>'2016-12-16 18:33:34' LIMIT 1
User is logged in
[1] SELECT * FROM perch2_pages WHERE pagePath='/product-detail.php' LIMIT 1
[1] SELECT * FROM perch2_shop_cart WHERE cartID=126
[1] SELECT * FROM perch2_shop_cart WHERE cartID=126
[1] SELECT * FROM perch2_shop_products WHERE productSlug='special-italian-special-ita' AND productDeleted IS NULL LIMIT 1
[31] SELECT DISTINCT idx.itemID FROM perch2_shop_index idx JOIN perch2_shop_products main ON idx.itemID=main.productID AND idx.itemKey='productID' AND ((idx.indexKey='status' AND idx.indexValue='1')) GROUP BY idx.itemID HAVING COUNT(idx.itemID)=1
[7] SELECT DISTINCT idx.itemID FROM perch2_shop_index idx JOIN perch2_shop_products main ON idx.itemID=main.productID AND idx.itemKey='productID' AND ((idx.indexKey='parentID' AND idx.indexValue='')) GROUP BY idx.itemID HAVING COUNT(idx.itemID)=1
[nil] SELECT tbl.* FROM ( SELECT idx.itemID, main.*, idx2.indexValue as sortval FROM perch2_shop_index idx JOIN perch2_shop_products main ON idx.itemID=main.productID AND idx.itemKey='productID' JOIN perch2_shop_index idx2 ON idx.itemID=idx2.itemID AND idx.itemKey='productID' AND idx2.indexKey='title' AND idx.itemID IN ('1', '38', '39', '40', '41', '42', '43', '44', '45', '46', '47', '48', '49', '50', '51', '52', '53', '54', '55', '56', '57', '58', '59', '60', '61', '62', '63', '64', '65', '66', '67') AND idx.itemID NOT IN ('1', '58', '63', '64', '65', '66', '67') WHERE 1=1 AND ((idx.indexKey='parentID' AND idx.indexValue=58)) AND idx.itemID=idx2.itemID AND idx.itemKey=idx2.itemKey ) as tbl WHERE (productDeleted IS NULL AND productStatus=1 AND parentID IS NULL) GROUP BY itemID, sortval ORDER BY sortval ASC
[25] SELECT DISTINCT settingID, settingValue FROM perch2_settings WHERE userID=0
Using template: /addons/apps/perch_shop/templates/shop/products/variant_list.html
perch_get('item') is my product slug.
Thanks, Vince.
When templating a variant, the
productID
is the ID you need. Each variant is a product with a parent relationship to the main product. So they all have their own productID.