I try to setup a commerce site where the customer can order prints. The prints can have choices of papersize and paperquality. These are setup as attributes fields at a new product type called print.
Beside that the customer has to upload the picture he wants to get printed. Therefore I created a custom line-item with a file field to collect the file. Then, after creating the product display, the product shows up ok with the two selection fields and the file upload field.
Now the crude stuff happens, when a picture file is selcted. If I only select the file and then click on "add to cart", the selected attributes and the file show up in the cart (I had to change the cart view for the file to show up). If I however select the file and click on the "upload" button and then on the "add to cart" button, allways the first SKU-Item of the display node shows up in the cart, no matter what the attribute selection has been. The uploaded file is correct though.
Has somebody seen this behavior before and can give me a hint, whats goin wrong as I'm having no clue?
As a work around I can hide the "upload" button, but I'm courious where this issue is comming from.
Edit: I'm using the Module filefield_path to put the uploaded File into a structure depending on papersize and paperquality. This is required for a simpler handling of the files in the production process. Maybe there's the culprit.
Best regards
Werner
Comments
Hi WLA, I am having similar
Hi WLA,
I am having similar issues, did you find a workaround?
Only as described hiding the
Only as described hiding the upload button. The file is automatically uploaded with the add to cart click and then everything works as expected.
This problem has not been
This problem has not been sorted 4 years later, it is related to ajax using a form state which is cached. There are 2 instances on the forums with a solution but it hasn"'t worked in my case, 16 hours later I still have no fix, extremely frustrated.
here are the
here are the threads
https://www.drupal.org/forum/support/module-development-and-code-questio...
https://www.drupal.org/node/1843940
JQuery solution
I am facing the same issue, so I hacked together some jQuery which solves the problem.
Basically, what I'm doing is calling the Attribute selection again after the Upload button is clicked. This way the image gets uploaded and the attribute selection gets saved.
This results in the following js:
// Track clicks on the Upload buttonvar fire; // This is used to avoid a continuous loop on the ajaxComplete event
Drupal.behaviors.uploadButtons = {
attach: function (context) {
jQuery('button.form-submit', context).bind('mousedown', Drupal.upload.Fired ); // If the Upload button is clicked ...
}
};
Drupal.upload = Drupal.upload || {
Fired : function(){
fire = true; // ... set the event to true
}
};
Then, on an ajaxComplete event, this code gets fired:
jQuery(document).ajaxComplete(function() {
// Fire the Product Attribute selection again
if (fire) {
var parent = jQuery('.form-type-commerce-fancy-attributes-ajax .description .description-selected').parent().parent();
jQuery('input[type=radio]', parent).click();
jQuery('input[type=radio]', parent).change();
fire = false; // Set fire to False to avoid a continuous loop here
}
});
If anyone cares to optimise my hacked code, be my guest.
In the meantime, I hope this helps you out.