When I'm on a product display page and I change for example the color, the page gets partly reloaded using ajax (standard commerce behavior). It seems preprocess functions like hook_node_view_alter are not called when reloading the page (by changing an attribute). Say you change the price markup in this function, this new markup doesn't get loaded when changing the product's color.

Is there a way to make this work?

Comments

vasike’s picture

Status: Active » Postponed (maintainer needs more info)

can you provide some screenshots with right descriptions, please?

I'm not sure about your issue here, but i can say that the Product attributes deals with Product data and not the Product Display-Node.
So maybe you have to work on Product entities instead of nodes.

rszrama’s picture

Status: Postponed (maintainer needs more info) » Closed (fixed)

Actually, if I understand right, since we're using field_view_field() to render fields on the AJAX refresh, you should be able to do what you want through the appropriate prepare_view field hooks.

fernly’s picture

Status: Closed (fixed) » Closed (works as designed)

Thanks both vasike and Ryan. The reloading of the fields is indeed getting its data straight from the entity and by this 'bypassing' any node related functions if you can put it that way. Like Ryan says, some entity field functions can provide the functionality to solve this 'issue'.

drupalreggie’s picture

I'm experiencing a problem related to this issue.

On some of my product pages I have a dynamically generated link: [site:login-url]?destination=[current-page:url:path]

This allows the user to login and be returned to the product page afterwards.

Only problem is after a product attribute is changed the dynamically generated link URL becomes: user?destination=system/ajax

I know there is an option in commerce to force users to login before checking out but this is not the functionality I am looking for. These are custom product pages which contain links to external payment providers (GoCardless - to handle the dreaded recurring payment problem) so at the moment I do specifically feel that I need this functionality.

Any ideas on a work around this?

Cheers,

Marko B’s picture

Issue summary: View changes

With some hook_field_attach_view_alter you can preprocess field output one by one. What I needed is to preprocess this whole group of data, add to cart form basically that consists attributes and add to cart button. To do that the only way to make it work with AJAX is with form alter. So change the forms data in

function my_custom_form_commerce_cart_add_to_cart_form_alter(&$form, &$form_state) {

and you can probably get what you need. Think this is the only way.