mivaecommerce / readytheme-shadows

Shadows is the development framework and methodology used for creating our ReadyThemes as well as custom websites.
https://shadows.mivareadythemes.com/
MIT License
4 stars 3 forks source link

PROD: Attribute Machine: Allow dynamic update of price for non-variant attributes #95

Closed influxweb closed 3 years ago

influxweb commented 3 years ago

Current Behavior

Currently, dynamic pricing only works when a product has inventory attributes. This has been improved in Miva 10.01.00 so dynamic pricing is reflected for non-inventory attributes, even if the product only has non-inventory attributes.

Correcting the Issue

To make the update, without applying the latest release, you will need to update the code in User Interface -> Templates -> Pages -> PROD -> Attribute Machine -> Head Template:

AttributeMachine.prototype.Swatch_Click = function(input, attribute, option) {
    let swatch_name_element = document.querySelector('[data-hook="attribute-swatch-name"]');
    let i;
    let swatchElements = input.machine.swatches.childNodes[0].childNodes;

    for (i = 0; i < input.select.options.length; i++) {
        if (input.select.options[i].value === option.code) {
            input.select.selectedIndex = i;
        }
    }

    this.Attribute_Changed(input);
    swatch_name_element.innerHTML = option.prompt;

    /**
     * Adds focus back to the selected swatch.
     */
    swatchElements.forEach(function (swatchElement) {
        let swatchColor = swatchElement.getAttribute('data-code');
        let swatchImage = swatchElement.querySelector('button');

        if (swatchColor === input.select.options[input.select.selectedIndex].value) {
            swatchImage.focus();
        }
    });
};