signalpoint / commerce

The Drupal Commerce module for DrupalGap.
8 stars 10 forks source link

Adding logical field to commerce_product breaks attributes system #22

Open ntym4ek opened 6 years ago

ntym4ek commented 6 years ago

I have commerce_product with attribute field of type 'term reference'. Changing attribute in app (built by http://tylerfrankenstein.com/code/build-mobile-app-sell-products-with-drupal) works well.

After logical type field adding to commerce_product I got problem. _commerce_product_display_get_current_product_id() function does not return chosen commerce_product id cause new field gets to _commerce_product_attribute_field_names array.

I was had to fix this with commerce_cart_add_to_cart_form() altering and building _commerce_product_attribute_field_names from scrath:

function myapp_form_alter(form, form_state) {
    try {
        switch(form.id) {
            case 'commerce_cart_add_to_cart_form':

                _commerce_product_attribute_field_names = [];
                var field_info_instances = drupalgap_field_info_instances('commerce_product', 'product');
                $.each(field_info_instances, function(field_name, field) {
                    if (
                        typeof field.commerce_cart_settings !== 'undefined' &&
                        typeof field.commerce_cart_settings.attribute_field !== 'undefined'
                         && field.commerce_cart_settings.attribute_field != 0
                    ) {
                        _commerce_product_attribute_field_names.push(field_name);
                    }
                });
              ...