when both uc_aac and uc_ajax_cart are enabled - ajax_cart seems not to work.
when clicking the "add_to_cart" button - the product is added to the cart but not in ajax way, like if uc_ajax_cart isn't installed.

I solved the problem by commenting this code in uc_aac.js

// Update the add to cart form.
if (data.form) {
// var action = form.attr('action');
// $(form).after(data.form).next().attr('action', action).uc_aac_attach();
// form.remove();
}
but it caused this: when changing select attributes - prices do not rebuilt. Still thats better than non-ajax cart ))

Comments

At least i found the better way:
each time after we update any attribute we myst bind click event to ajax_add_to_cart on product form submit button.

we do something like this:
// Update the add to cart form.
if (data.form) {
var action = form.attr('action');
$(form).after(data.form).next().attr('action', action).uc_aac_attach();
form.remove();
uc_ajax_cart_bindClick();
}

where uc_ajax_cart_bindClick() - is a function from ajax_cart module, containing main code:
function uc_ajax_cart_bindClick(){
$('input.ajax-submit-form, button.ajax-submit-form').bind('click',function(e){
var $form = jQuery(this).parents('form').eq(0);
var callbackID = $form.attr('id');
if ( $form.find('input[@name=uc-ajax-cart-callback]').length == 0 )
{
$form.append('')
}
var d = $form.formToArray();
var tagName = this.tagName ;
var button = jQuery(this);
if ( bText != false )
{
if ( tagName == "BUTTON" )
{
button.attr('oldTitle',button.html());
button.html(bText);
}
else
{
button.attr('oldTitle',button.attr("value"));
button.attr('value',bText);
}
}
button.addClass(bclass);
if ( disabled == 1 )
{
button.css({display : 'none'});
button.after('' + bText + '');
}
$.post( Drupal.settings.basePath + 'cart/ajax/update',d,updateAjaxCart, 'json');
return false;
});
}

Hi shtirluk,

I don't believe this is not the correct way to handle this. The new uc_aac 6.x-2.x branch offers many ways for other modules to interact with it. The Ajax Cart module will need to leverage this ability to interact with the uc_aac module and perform the binding on it's own. I think this issue should be moved under the Ajax Cart module, but before I do that, I'll wait for a response in case I am missing something.

Cheers,

Antoine

Project:Ubercart Ajax Attribute Calculations» Ubercart AJAX Cart
Version:6.x-2.0-beta1» 6.x-2.x-dev

shtirluk,

Since I have not heard anything for over a month, I assume you have no disagreements with how this should be fixed, therefore I am moving this issue to the Ajax Cart module.

Cheers,

Antoine

#1 not a solution, because for example my code for ajax cart callback is:

jQuery(document).ready(function(){
/** get settings **/
var bText = Drupal.settings.uc_ajax_cart.text ;
var disabled = Drupal.settings.uc_ajax_cart.disable ;
var bclass = Drupal.settings.uc_ajax_cart.bclass ;
var curr_language = Drupal.settings.uc_ajax_cart.curr_language;
jQuery(this).find('input.ajax-submit-form,button.ajax-submit-form').bind('click',function(e){
var $form = jQuery(this).parents('form').eq(0);
var callbackID = $form.attr('id');
if ( $form.find('input[@name=uc-ajax-cart-callback]').length  == 0 )
{
$form.append('<input type="hidden" value="'+callbackID+'" name="uc-ajax-cart-callback" />')
}
var d = $form.formToArray();
var tagName = this.tagName ;
var button = jQuery(this);
if ( bText != false )
{
if ( tagName == "BUTTON" )
{
button.attr('oldTitle',button.html());
button.html(bText);
}
else
{
button.attr('oldTitle',button.attr("value"));
button.attr('value',bText);
}
}
button.addClass(bclass);
if ( disabled == 1 )
{
button.css({display : 'none'});
button.after('<div class="ajax-cart-msg">' + bText + '</div>');
}
jQuery.getJSON( Drupal.settings.basePath + curr_language + 'cart/ajax/update',d,updateAjaxCart);
return false;
});
   jQuery.getJSON( Drupal.settings.basePath + curr_language + 'cart/ajax/update',{},updateAjaxCart);
})

So, how emplement your way of solution for me?

Title:Module conflicts with ubercart ajax cartModule conflicts with Ubercart Ajax Attribute Calculations

Changing name to reflect change of project.

Status:Needs review» Active
StatusFileSize
new631 bytes
new6.23 KB
new613 bytes

Please check comment #7 as I reviewed my patch, changed it to make use of

Drupal.behaviors.myModuleBehavior = function (context) {
//do some fancy stuff
};

Explanation in next comment.

Ok, so I came up with a solution. This is a fix for the following problems:

Using:
Ubercart ajax cart 6.x-1.0
Ubercart Ajax Attribute Calculations 6.x-2.0
Ubercart Out of stock Notification 6.x-1.4

Ubercart Ajax Attribute Calculations - uc_aac (http://drupal.org/project/uc_aac) is conflicting with this modules (Ubercart ajax cart - uc_ajax_cart) and with Ubercart Out of stock Notification - uc_out_of_stock (http://drupal.org/project/uc_out_of_stock).

The problem is that uc_aac creates a new form when you change an attribute, and this new form is not captured by any modules that relays on jQuery(document).ready(function() to capture forms without providing a function which can be called back when new forms are added to the page.

How to fix it:
First I changed uc_ajax_cart.js and wrapped the init code into a function, which I call ajaxCartInitCart and I call it once the document is ready. Also, this new function gets a parameter which will be the selector for the form to modify. This way when I call it for the first time I call it like this ajaxCartInitCart('form.ajax-cart-submit-form'); giving a selector for every form on the page.

I then modified uc_aac.js so that every-time a new form is added to the page, the function gets called like this: ajaxCartInitCart('#'+form.attr('id')); This way I'm making sure that only the new form is checked by uc_ajax_cart. I also put a validation so that the function only gets called if it is defined already, which happens only if the other module is installed (and my patch applied)

Same thing happened with uc_out_of_stock. I first wrapped the init code in two functions and then called them when needed.

I'm posting patches so you can check what is going on and apply to your like.

I invite the developers of the 3 modules to commit this changes as there are plenty like me who really want them all working together.

Love to all!

StatusFileSize
new7.3 KB
new894 bytes
new382 bytes

Ok, so new PATCH, it is the same concept as in my previous post, BUT I now use

Drupal.behaviors.myModuleBehavior = function (context) {
//do some fancy stuff
};

Which means that we need no validation for pre-existing modules and it just works! HURRAY for Drupal coding standards!

I contacted the developers of each module but just in case HELP ME SPREAD THE WORD. What I just did is actually how the modules should have been in the first place!

PLEASE COMIT THIS!

Hi Federico,

I am the maintainer of uc_out_of_stock.

Thanks for the patches, however, I feel this is not the way to go.

No module should rely on other module to work. If on each of these three modules you use functions from the others, you are forcing the users of each module to install the others.

We are aware of the incompatibility problems introduced by uc_aac 2.0 when removing the form. There's one way to fix this, at least partly, in a proper way which is being discussed on #697976: JS behavior of removing the form is a bit aggressive for other third-party modules..

And particulary in http://api.drupal.org/api/drupal/developer--topics--javascript_startup_g....

The idea is to use Drupal.behaviors instead of document ready, which is the recommended method for drupal and uc_aac should call Drupal.attachBehaviors(). I already tried some fixing around this and although this works, there's a few other isses because uc_aac and uc_out_of_stock both modifies the same form.

I will submit a patch there for uc_aac and eventually fix my own module to use the behaviors object as that's the way to go, although uc_aac with uc_out_of_stock will require more fixing.

Hi Hanoii

Actually my second patch works the way it should. No module relies on the others. What I did was actually making them all use the

Drupal.behaviors.myModuleBehavior = function (context) {
//do some fancy stuff
};

Drupal hook.

You can update your module and it will work with no problem regardless of the others. My patch only changes the way your code is called. Now, what happens is that EVERY module should use this convention.
If you check my second patch for your module you'll see that I does not need any other module to be installed in order to work, it is right the opposite it makes it work with every module (that follows Drupal JS conventions).

This is true for the 3 patches I submit. Please check the second post and the patches.

@jm.federico: Ok, it seems that I missed you second post. Anyway, I don't see why the need for changing other than the behaviors part, (at least for now and for my module) and I fixed that yesterday on uc_out_of_stock.

uc_aac seems fine, except it should also use Drupal.behaviors besides Drupal.attachBehaviors(). see http://drupal.org/node/697976#comment-2605178 where I submitted a patch similar to yours but with that bit also fixed. There are still issues to be fixed between uc_aac and uc_out_of_stock but better to follow discussion on that on uc_aac issue queue.

And I don't use uc_ajax_cart to comment on it.

a.=

Hi Federico,

Maybe I'm missing something but: where can I find the file to be patched with uc_ajax_cart.js_.patch?

Thanks,

Fred

Status:Active» Needs review

Will be fixed in 2.0-BETA1. But you need still need

uc_aac.js_.patch from #7

I have contact the developer of uc_aac .

@fredklopper

Each patch is for a different module. The one you mention is located under modules/uc_ajax_cart/js/uc_ajax_cart.js

Hope this helps.

@erikseifert
Thanks

Federico

From 2.0 - beta1 you only need to patch uc_aac module.

@Federico

Thanks, I was looking at the files in Ajax Cart 1.0 :-(

Fred

Would it be difficult to get this to work with UC Attribute Stock Filter?

Status:Active» Needs review

#7 patch failed for me:

File to patch: js/uc_ajax_cart.js
patching file js/uc_ajax_cart.js
Hunk #1 FAILED at 13.
Hunk #2 FAILED at 24.
2 out of 2 hunks FAILED -- saving rejects to file js/uc_ajax_cart.js.rej

Status:Needs review» Fixed

This bug has been tested using Ubertcart Ajax Cart 2.0-beta5 with Ubercart Ajax Attribute Calculations 6.x-2.1 and seems to be not present.

#17 jday you don't need to patch module, it seems maintainers already patched the code. Please use Ubercart Ajax Attribute Calculations 6.x-2.1 and test.

I'm closing this bug, reopen it if problem presists.

Status:Fixed» Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.