Skip to content

ProductMatrix - Default value of Variable Spec causes wrong Variant to be added to the cart #56

@digitalalphas

Description

@digitalalphas

When a variable selection spec is configured to have a default value, that value is always used to construct the variant for the cart, meaning the wrong variant is added to the cart.

matrix-1-varspec-default
matrix-2-variants
matrix-3-productpage
matrix-4-cart-wrong-variant

Unchecking the "default" option on the admin site is the quickest solution, but I think the code should also handle this scenario. I updated the _addToOrder function in the ProductMatrix factory of a client's version of productMatrix.js so they wouldn't have to update all of their products.

I updated the following lines from:
if(!liSpecs[spec].Value){ liSpecs[spec].Value = item.tempSpecs[spec] ? item.tempSpecs[spec].Value : null; }
To:
if(!liSpecs[spec].Value || (item.tempSpecs[spec] && liSpecs[spec].Value != item.tempSpecs[spec].Value)){ liSpecs[spec].Value = item.tempSpecs[spec] ? item.tempSpecs[spec].Value : null; }

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions