Announcement

Collapse
No announcement yet.

Rewriting / updating a custom basket field

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Rewriting / updating a custom basket field

    I'm working on a custom basket field that saves attribute data on a sku, so I can fill in the options on product page if the customer goes back to the product page to make changes.

    I have this working, but only if I have one of that sku in the basket. I can't get the custom basket field to rewrite with if there's another line item.

    On the basket page, in the code for the products options, I have this:

    HTML Code:
    <mvt:elseif expr="( l.settings:option:attr_code EQ 'MakeModel' )">
        <mvt:item name="customfields" param="Read_Basket( 'makeModel', g.makeModel )" />
        <strong>&mvt:option:attr_prompt;:</strong> &mvt:option:data; - &mvt:global:makeModel;
        <mvt:assign name="g.optionData" value="l.settings:option:data" />
        <mvt:if expr="g.makeModel NE g.optionData">
             <mvt:item name="customfields" param="Write_Basket( 'makeModel', l.settings:option:data )" />
        </mvt:if>
    So if that option is on the line item, it will read the current custom basket field, and if it doesnt match the option data in the basket field, it should re-write the field with its data.

    I've displayed the basket fields on the line items to see what data its showing and its like this-

    Line 1 - Make Model Option data = abc; Custom basket field = 123
    Line 2 - Make Model Option data = 123; Custom basket field = abc

    I think what's happening is the first line item doesn't match the basket field, so it rewrites. And now the 2nd line item doesn't match it because it was just rewritten, so it rewrites it again. Any ideas on how I can set this up?

    #2
    An easier way to do this would be to save the variant id of the attribute combination selected into a custom field. For any product you can pass ?variant_id=XX to the end of the URL and Miva will pre-select that attribute combination that maps to that variant.

    You can get the variant id by tying into the OnVariantChange event: https://docs.miva.com/code-samples/m...ariant-changed
    Brennan Heyde
    VP Product
    Miva, Inc.
    [email protected]
    https://www.miva.com

    Comment


      #3
      Will that work with the EXTERNAL module product? That's what I'm using, so its not using the prod template.

      Comment


        #4
        It should work on any product that has inventory variants generated. Does this product use variants?
        Brennan Heyde
        VP Product
        Miva, Inc.
        [email protected]
        https://www.miva.com

        Comment


          #5
          No it doesnt

          Comment


            #6
            I managed to get the result I was looking for with this using javascript. Now though, I'm looking at getting the variant id to pass through the url for a different reason. I'm not able to get the variant id though.

            I tried using the code on the page Code Samples | Load Variant Data On Variant Change but I don't get any results. Where should that code be added to? I'm just trying it on the product page, in the product display layout section, and I tried other areas on the product page as well.


            Comment

            Working...
            X