pereirinha / woocommerce-variation-details-on-page-product

WooCommerce Variation Details on Page Product

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Details not showing up for variable products with "Any value" selected for an attribute

CodeSmith32 opened this issue · comments

Love the plugin. Exactly what I needed. With the product system I'm working with though, the products are variable, and also have "Any XYZ" selected for all of the variations.

This apparently translates to a "" value for the attribute in each of the mp_wc_variations variation objects. The plugin filter function in wc-attributes-on-page.js on lines 9-11, however, don't support this:

filterData = function filterDataF( obj ) {
	return selectedVal[prop] === obj[prop];
},

So, I just changed it to the following (thus, if "Any" value is selected, it'll always be included in the filter pass), and it works fine:

filterData = function filterDataF( obj ) {
	return obj[prop] === "" || selectedVal[prop] === obj[prop];
},

Hi @CodeSmith32:

I'm so sorry for late reply. The main reason why is that I didn't saw you suggestion working for me.
However, your request joined a long list of people asking for this.

For that reason, I did invest some time to bring this feature in, but it would be great if you can test it before I deploy into WordPress repo. Can I ask you that?

If so, can you please clone the repo and checkout fix/multivariations-single-impact branch? I now, meaningless lame branch name… I guess I was too tired by the time I created it :)

You say it isn't working for you? Not sure... maybe you're thinking of a different issue.

All I know is that with the plugin WooCommerce 2.6.12, and the plugin WooCommerce Variation Details on Page Product 3.3.1, there was an issue:
When I have a variational product, I create attributes, then choose a set of attributes for that product. Then, when I create product variations on that product, I have to select the specific values for each attribute that define which variation the product is. One of the options for the value of an attribute is 'Any', meaning, any value of that attribute will choose this variation. The issue was, when this value is selected for a variation, that variation will not display its details when its values are selected on the product page.
I looked at your code, and figured out that it was simply because, for a product variation, the variation value for an attribute that is using 'Any' is equal to "" (an empty string). But your product filter function, filterData, requires that all values are exactly equal: (wc-attributes-on-page.js:10) return selectedVal[prop] === obj[prop]; So, for a product using 'Any', this would appear as return "somespecificvalue" === ""; which is always false, even though it should really be always true.
I instead just changed it to return obj[prop] === "" || selectedVal[prop] === obj[prop]; and it now works fine for me.

(p.s. You have a wc-attributes-on-page.min.js that's not getting used.)

Thanks for keeping tuned about this @CodeSmith32.

As a general sense, there are variations that might have nothing to do with these physical dimensions. Let's have Color attribute as an example. Having color green or blue, shouldn't require setting dimensions associated. Until version 3.3.1 that would be indeed a requirement.

This new version will handle situations like you described — hopefully. That is why it would be super if you could test this branch on your end.

About the minification script, again, thanks for the heads up. At some point I've introduced that for helping me debug some scenarios. This is in fact something fixed on this new branch. Debugging mode is now tied up with WP_DEBUG as it should.

Hey @CodeSmith32:

Version 3.4.0 was released. Let me know if it fixed your issues, so we can close this ticket.

Hey @pereirinha, sorry for the late (really late) reply. I did update the plugin and it works great. :)

Thanks!