How can I get the product variant url

How to configure and adapt Aimeos based shops as developer
Forum rules
Always add your Aimeos and PHP version as well as your environment (Linux/Mac/Win)
Spam and unrelated posts will be removed immediately!
thestranger
Posts: 16
Joined: 06 Jun 2024, 04:34

How can I get the product variant url

Post by thestranger » 17 Jul 2024, 10:02

Hello, I noticed this piece of js code in catalog-detail.js and I'd like to know how can I get the correct url so we can make promos on some variants so when people click on the link the product variant is preselected.

Code: Select all

/**
	 * Check for variants in URL
	 * Set the variant attributes and trigger select-dropdown´s to show the variant article
	 */
	onSelectVariant() {
		const product = $('article.product');

		if(product && product.data('varattributes')) {
			$.each(product.data('varattributes'), function (key, val) {
				$('#select-' + product.data('id') + '-' + key).val(val).trigger('change');
			});
		}
	},

thestranger
Posts: 16
Joined: 06 Jun 2024, 04:34

Re: How can I get the product variant url

Post by thestranger » 17 Jul 2024, 12:07

got up to this link http://localhost:8081/default/shop/asdf/0/26501?d_articleid=26504 which produces the varattributes in javascript but there's no effect on the ui.

User avatar
aimeos
Administrator
Posts: 8620
Joined: 01 Jan 1970, 00:00

Re: How can I get the product variant url

Post by aimeos » 17 Jul 2024, 12:20

This is what's relevant for the UI:

Code: Select all

#select-' + product.data('id') + '-' + key
Professional support and custom implementation are available at Aimeos.com
If you like Aimeos, Image give us a star

thestranger
Posts: 16
Joined: 06 Jun 2024, 04:34

Re: How can I get the product variant url

Post by thestranger » 18 Jul 2024, 06:37

yea I did the console log and it works till there but i think the problem is that .trigger('change') does not work or something since it doesn't select the variant options in the ui (could it be because I'm using radio buttons and not dropdown select?)

User avatar
aimeos
Administrator
Posts: 8620
Joined: 01 Jan 1970, 00:00

Re: How can I get the product variant url

Post by aimeos » 19 Jul 2024, 08:31

Most likely, the "change" trigger must be added when the document is loaded. Can you check and create a pull request with the necessary change afterwards?
Professional support and custom implementation are available at Aimeos.com
If you like Aimeos, Image give us a star

Post Reply