Forum

Thread tagged as: Shop

Perch variants...

I'm having trouble with variants.

                perch_shop_product('events'); 

with <perch:showall /> gives me:

has_variants    true
_variant_opts   Member|4,Non-member|5
options 
Array
(
    [0] => Array
        (
            [title] => Member prices
            [precendence] => 1
            [optionID] => 2
            [optionTitle] => Member prices
            [optionPrecendence] => 1
            [optionDynamicFields] => {"title":"Member prices","precendence":"1"}
            [optionCreated] => 2017-01-04 12:56:33
            [optionUpdated] => 2017-01-04 12:56:33
            [optionDeleted] => 
            [perch_title] => Member prices
            [perch_precendence] => 1
            [options] => Array
                (
                    [0] => Array
                        (
                            [id] => 2
                            [title] => Member
                            [skucode] => MBR
                        )

                    [1] => Array
                        (
                            [id] => 3
                            [title] => Non-member
                            [skucode] => NON
                        )

                )

            [productvalues] => Array
                (
                    [0] => Array
                        (
                            [prodoptID] => 2
                            [optionID] => 2
                            [valueID] => 2
                            [optionTitle] => Member prices
                            [valueTitle] => Member
                            [valueSKUCode] => MBR
                            [valueOrder] => 1
                            [valueDynamicFields] => {}
                            [valueCreated] => 2017-01-04 12:56:33
                            [valueUpdated] => 2017-01-04 12:56:33
                            [valueDeleted] => 
                        )

                    [1] => Array
                        (
                            [prodoptID] => 3
                            [optionID] => 2
                            [valueID] => 3
                            [optionTitle] => Member prices
                            [valueTitle] => Non-member
                            [valueSKUCode] => NON
                            [valueOrder] => 2
                            [valueDynamicFields] => {}
                            [valueCreated] => 2017-01-04 12:56:33
                            [valueUpdated] => 2017-01-04 12:56:33
                            [valueDeleted] => 
                        )

                )

        )

)

But perch_shop_product_variants('events'); gives me nothing!

I've got debug enabled and there is a bit of the query that looks a bit odd (parentID IS NULL) :

SELECT tbl.* FROM ( SELECT idx.itemID, main.*, idx2.indexValue as sortval FROM swt_shop_index idx JOIN swt_shop_products main ON idx.itemID=main.productID AND idx.itemKey='productID' JOIN swt_shop_index idx2 ON idx.itemID=idx2.itemID AND idx.itemKey='productID' AND idx2.indexKey='title' AND idx.itemID IN ('1', '2', '3', '4', '5') AND idx.itemID NOT IN ('1', '3') WHERE 1=1 AND ((idx.indexKey='parentID' AND idx.indexValue=3)) 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

Any ideas?

Phil Smith

Phil Smith 0 points

  • 4 years ago
Drew McLellan

Drew McLellan 2638 points
Perch Support

Can you try this and let me know what you get between the blue markers?

PerchUtil::mark('A');
perch_shop_product_variants('events');
PerchUtil::mark('B');
SELECT * FROM swt_shop_products WHERE productSlug='events' AND productDeleted IS NULL LIMIT 1
[5] SELECT DISTINCT idx.itemID FROM swt_shop_index idx JOIN swt_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
[2] SELECT DISTINCT idx.itemID FROM swt_shop_index idx JOIN swt_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 swt_shop_index idx JOIN swt_shop_products main ON idx.itemID=main.productID AND idx.itemKey='productID' JOIN swt_shop_index idx2 ON idx.itemID=idx2.itemID AND idx.itemKey='productID' AND idx2.indexKey='title' AND idx.itemID IN ('1', '2', '3', '4', '5') AND idx.itemID NOT IN ('1', '3') WHERE 1=1 AND ((idx.indexKey='parentID' AND idx.indexValue=3)) 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
[60] SELECT DISTINCT settingID, settingValue FROM swt_settings WHERE userID=0
Using template: /templates/shop/products/variant_list.html
Drew McLellan

Drew McLellan 2638 points
Perch Support

I get pretty much the same thing, but the difference is, my variants are listed!

Do you have "AND parentID IS NULL"

Drew McLellan

Drew McLellan 2638 points
Perch Support

Found it - inheritance issue. Will be fixed in the next update.

Magic!