Can I include jQuery and AJAX in the same file? Would this conflict?

Can I include jQuery and AJAX in the same file? Would this conflict?

I am attempting to include jQuery with a Magento GO template, but when I upload and include jQuery in the template, the drop down menus/etc. stop working. The links all still work fine, but the dropdown menus, and other similar functionality stop working…

I believe this may be because Magento includes AJAX in the hosted solution on their end..?

Magento Ajax add to cart not working for subsites

I’ve written a small script that is called via ajax for adding products to the cart.

$request = Mage::app()->getRequest();
$session = Mage::getSingleton('core/session', array('name'=>'frontend'));
$cart = Mage::helper('checkout/cart')->getCart();
foreach($pids as $pid){
    if(!pid || $pid == ''){continue;}
    $product = Mage::getModel('catalog/product')->load($pid);
    $cart->addProduct($product, $qty);

I have a multi site setup and this script works fine when it is run under the main site but when I run it under one of the subsites it doesn’t add it to the cart.

I’ve tried having the addtocart.php in the root of the subsite (and including the main sites mage.php) and have also tried adding it to the root of the main site, But nothing works.

Do I need to specify the website id somewhere?


Magento – Registration on Checkout page and then pay via PayPal

I have issue, after checkout on “checkout/onepage/success” get a user info using “order id”, something like:

$orderInfo = Mage::getModel('sales/order')->load($lastOrderId);
$customerId = $orderInfo->getCustomerId();

Order from user that registrated on Checkout page and then pay via PayPal become a “guest order”, and ofcourse in “Model(‘sales/order’)” customer id is null, and in DB this transaction and order looks like a “Guest order” that was made by PayPal account, not from Magento’s. Another payment systems working fine with registration on Checkout page, and after checkout I can get customer id.
The question is, how to get a “user id” from just registrated users in Magento site throught Checkout page and bought something via PayPal?

How do I track AJAX sections in Magento Onepage with Google Analytics Async

I have a magento store and I am trying to track the progress of users at the checkout process.

I have the Onepage checkout enabled – which does some ajax stuff to essentially load 6 different steps in an accordion format. I would like to track each step with Google Analytics so i know whats putting the users off.. I found this link ( to do so with Google Analytics – but it uses the old GA code. I am using the Async code which uses the gaq push.

So here is the code they recommend to use.

 gotoSection: function(section)
        try {
            pageTracker._trackPageview('/checkout/' + section + '/');
        } catch(err) {}

        section = $('opc-'+section);

To update this to the Asynchronous version, would i use:

 gotoSection: function(section)
        try {
            _gaq.push(['_trackPageview', '/checkout/', + section + '/']);
        } catch(err) {}

        section = $('opc-'+section);

Do i need the catch(err) ? What would be the full code – this doesn’t seem to work for me?

Magento: how to show standard error/success message using JS in admin panel?

I can add error/success message to the Magento admin panel from server-side, for example,


But how to show the same message on the client-side using JS? I mean standard way (of course I can create the same message box, but it’s not a solution). For example when I need to show a status of some AJAX request. Any ideas?

Magento – Can I JSON encode the entire product collection?

This is what I have so far. Does it look relavent? Or is there an easier way?

protected function _encodedProductCollection()
    $productcollection = $this->_getProductCollection();
    $productmodel = Mage::getModel('catalog/product');
    $categorymodel = Mage::getModel('catalog/category');

    $collection_to_encode = array();

    foreach( $productcollection as $product )
        $product_to_encode = array();

        $thisproduct = $productmodel->load($product->getId());
        $productsname = $thisproduct->getName();
        $productsid = $thisproduct->getId();
        $productcategories = $thisproduct->getCategoryIds();
        $productscategoryname = $categorymodel->load($productcategories[0])->getName();  //we'll start with the first category name.
        //$productsimageurl = $thisproduct->getImageUrl();  //gets the image url if we need it later
        //$altcategorymethod = ($thisproduct->getCategory() ? $thisproduct->getCategory()->getName() : 'No Category');  //we may use this one instead.

        $product_to_encode[] = array(
            'id' => $productsid,
            'name' => $productsname,
            'category' => $productscategoryname );

        array_merge($product_to_encode, $collection_to_encode); 

    $encoded_products = json_encode($collection_to_encode);

    return $encoded_products;  //leave this if we leave it as a function - we may port it all over to the template itself.

Load search form results inline with jQuery, instead of on a new page

I’m trying to build a custom search form for an e-commerce setup built on Magento.

This search form consists of several (dropdown) select boxes. The form is functioning properly, but after you choose your search values and submit the form, you’re taken to a new page with the results.

Search page URL:
Results page URL:

What I would like to do is instead load the search results in a div below the form with some jQuery.

I’ve searched and have found several examples of this, but I can’t seem to get anywhere. I’ve also come across a few similar threads here on Stack Overflow, but nothing here has worked for me as of yet.

Thank you for any help or guidance on this.

Problem with Javascript Form to work consistently with Ajax to login to a Private Magento Store

My Webdeveloper abandoned me and my form doesn’t seem to work always.

When clicked it doesn’t appear to do anything (just shows the “javascript:;” href on the browser status bar), but sometimes it works…

I’ve searched everywhere for a solution but I haven’t had any luck. Maybe I don’t know where to start!! Really would appreciate help: I’m a novice and have been struggling. THANK YOU!!

   <link rel="stylesheet" type="text/css" href="css.css" />
      <script type="text/javascript" src="prototype.js" ></script>
      <script type="text/javascript">
          function login(){
             if($('username').value == '') alert('Username cannot be left blank');
             if($('password').value == '') alert('Password cannot be left blank');
      new Ajax.Request('',
      parameters: 'username='+$('username').value+'&password='+$('password').value,
         onSuccess: function(transport){
             if (transport && transport.responseText){
         response = eval('(' + transport.responseText + ')');
     catch (e) {
    response = {};

   if (response.success){
       if ((typeof response.message) == 'string') {
       return false;
   onFailure: function(){ alert('Something went wrong...') }

This is the HTML form

<form name="frm" method="post" action="#" id="frm">
        <li><input type="text" class="rounded" name="username" id="username" value="Username" /></li>
        <li><input type="password" class="rounded" name="password" id="password" value="Password" /></li>
        <li><a href="javascript:;" onClick="login();return false;"><img src="splash/button.png" alt="" /></a></li>

Callup of prototype.js refers to prototype.js MIT Javascript framework, version 1.6.1

Magento: How to change default template dynamically in controllers

example: a controller named ajaxhandlerController
it can receive several ajax request types,
each type should have separate block in the layout xml

in layout for index of ajaxhandler i would write

      <block some block></block>

How do I change from index to save for example if there is $request[‘type’]==”save”; so I can use


Magento AJAX problem in IE9 64bit – Using Simple Configurable Products Plugin

I have a Magento which uses the simple configurable products plugin. For those of you that don’t know, once you’ve chosen your configurable product options, it then uses an AJAX query to get the custom options of the simple product which makes up your configurable product selection.

The problem exists on this page.

When someone choose the simple product they want based on the pack size, it is supposed to get the custom option when lets them decide on colour choice.

This works fine in every single browser except IE9 in 64bit mode (which happens to be the browser my client uses!!!!)

I have already tried to force the document type using:

<meta http-equiv="X-UA-Compatible" content="IE=8" />

but to no avail in this 64bit version…

The plugin developer have done their best to ignore me, so I’m kinda stuck. Here’s the AJAX call that the script makes – I wondered if it’s perhaps something to do with the ActiveX Object not being loaded?

Product.Config.prototype.showCustomOptionsBlock = function(productId, parentId) {
    var coUrl = this.config.ajaxBaseUrl + "co/?id=" + productId + '&pid=' + parentId;
    var prodForm = $('product_addtocart_form');

   if ($('SCPcustomOptionsDiv')==null) {

    Effect.Fade('SCPcustomOptionsDiv', { duration: 0.5, from: 1, to: 0.5 });
    if(productId) {
        //Uncomment the line below if you want an ajax loader to appear while any custom
        //options are being loaded.
        $$('span.scp-please-wait').each(function(el) {});

        //prodForm.getElements().each(function(el) {el.disable()});
        new Ajax.Updater('SCPcustomOptionsDiv', coUrl, {
          method: 'get',
          cache: false,
          evalScripts: true,
          onComplete: function() {
              $$('span.scp-please-wait').each(function(el) {el.hide()});
              Effect.Fade('SCPcustomOptionsDiv', { duration: 0.5, from: 0.5, to: 1 });
              //prodForm.getElements().each(function(el) {el.enable()});
    } else {
        $('SCPcustomOptionsDiv').innerHTML = '';
        window.opConfig = new Product.Options([]);

Any thoughts/ideas would be much appreciated!