Cart page metafield debugging

Highlighted
New Member
5 0 0

I have the below script that would ideally display the product metafields and quantity in the console.

 

function productIdsWithQuantities() {
        {%- assign added_first = false -%}
        return {
          {%- for item in cart.items -%}
            {%- if item.variant.metafields.productId.productId -%}
              {%- if added_first %},{% endif -%}
              "{{ item.variant.metafields.productId.productId }}": {{ product.quantity | json }}
              {%- assign added_first = true -%}
            {%- endif -%}
          {%- endfor -%}
        };
      }

      function init() {
        self.options = Object.assign({
          products: productIdsWithQuantities(),
          checkoutButtonSelector: '{{ checkout_button_selector }}',
          checkoutUrl: '{{ checkout_url }}'
        }, options);

        self.$checkoutButton = $(self.options.checkoutButtonSelector);

        debug('Initialized with options', self.options);

        inject();
      }

When I cam calling the init() function within the products value is displayed null when calling function productIdsWithQuantities() which is the above.

 

 

What would cause this to happen? Are you able to pull these metafields in such a way?

 

 

0 Likes
 
 
0 Likes