0

in my store folder i am calling cart_php to pull magento data in wordpress following is code.

<?php

require_once('app/Mage.php');
    umask(0);
    Mage::app('default');
// This has to run to authenticate customer and checkout session calls.
Mage::getSingleton('core/session', array('name' => 'frontend'));

// Get any customer model you desire.
$oSession = Mage::getSingleton( 'customer/session' );
$oCustomer = $oSession->getCustomer();
$oCheckout = Mage::getSingleton( 'checkout/session' );
$oQuote = $oCheckout->getQuote();

//var_dump( $oCustomer );
//var_dump( $oSession );
//var_dump( $oQuote );
//var_dump( $oCheckout );
$html="";$i=0;
    $oCart = $oQuote->getAllItems();
    if( !empty( $oCart ) )
    {
        foreach ( $oCart as $oItem ) 
        {
            $sName  = $oItem->getProduct()->getName();
            //$fPrice = $oItem->getProduct()->getPrice();
             $fPrice= $oItem->getRowTotal();
             $html.="<div class=product-range-con>".
                    "<div class=product-range-image>".
                        "<img src=images/product-two.jpg width=40>".
                    "</div>".
                    "<div class=product-range-name>".$sName."<br></div>".
                    "<div class=product-range>".
                        "<div class=input-group>".
                            "<span class=input-group-btn>".
                                "<button type=button class='btn btn-default btn-number range-pdn' disabled=disabled data-type=minus data-field=quant[1]>".
                                    "<span class='glyphicon glyphicon-minus'></span>".
                                "</button>".
                            "</span>".
                            "<input type=text name=quant[1] class='form-control input-number range-con' value=1 min=1 max=10>".
                            "<span class=input-group-btn>".
                                "<button type=button class='btn btn-default btn-number range-pdn' data-type=plus data-field=quant[1]>".
                                    "<span class='glyphicon glyphicon-plus'></span>".
                                "</button>".
                            "</span>".
                        "</div>".
                        "<div class=range-multiply>".
                "X".
                        "</div>".
                    "</div>".
                    "<div class=product-range-price>".Mage::app()->getLocale()->currency(Mage::app()->getStore()->getCurrentCurrencyCode())->getSymbol() .$fPrice.
                    "</div>".
                    "<div class=cf></div>".
                "</div>";
                $i++;

        }

            $quote = Mage::getModel('checkout/session')->getQuote();
$quoteData= $quote->getData();
$grandTotal=$quoteData['grand_total']; 
$shipping_cost= Mage::getSingleton('checkout/session')->getQuote()->getShippingAddress()->getShippingAmount(); 
$html.= '~'.Mage::app()->getLocale()->currency(Mage::app()->getStore()->getCurrentCurrencyCode())->getSymbol() .Mage::helper('checkout/cart')->getQuote()->getSubtotal();
$html.= '~'.Mage::app()->getLocale()->currency(Mage::app()->getStore()->getCurrentCurrencyCode())->getSymbol() .$shipping_cost;
$html.= '~'.Mage::app()->getLocale()->currency(Mage::app()->getStore()->getCurrentCurrencyCode())->getSymbol() .$grandTotal;
$html.= '~'.$i;
}
    echo $html;

and its returning ajax error 500 internal server error. any help appreciated

  • Can you give me your magento root path and full path of this php file of wordpress so I can help you – Murtuza Zabuawala Aug 16 '16 at 4:21
  • yes komposter.os4wprojects.de/p/cart_pop.php this is the file , which i been calling throug ajax , base url is path which been calling this file in header.php – Man S. Aug 16 '16 at 4:28
  • For include function try to add fill DIR path of mage.php file and let me know – Murtuza Zabuawala Aug 16 '16 at 4:31
  • its not working mate , indeed i just trace the code the error is in require_once file if i echo before this its returning , after this its throwing 500 error – Man S. Aug 16 '16 at 4:36
  • Can you give video or screenshot of your error? – Murtuza Zabuawala Aug 16 '16 at 4:39
0

Right Now In your home Page has this JQuery Ajax Call Just Below

$('.addtocart').click(function(){
             var product= $(this).attr('mode');

                  alert(product);

                 $.ajax({
            type: "post",
            data: "mode=addtocart&product=" + product,
            url: "http://hello.com/handler",
            success: function (result)
            {


                result = result.trim();

                            alert(result);


            }

        });

        });
        });

The Above code has an extra )};

So replace it with Below Code

$('.addtocart').click(function(){
             var product= $(this).attr('mode');

                  alert(product);

                 $.ajax({
            type: "post",
            data: "mode=addtocart&product=" + product,
            url: "http://hello.com/handler",
            success: function (result)
            {


                result = result.trim();

                            alert(result);


            }

        }); });
  • The code is working like a charm, Thankyou so much for pointing out the error, You are the best. Keep Up :) – Man S. Aug 16 '16 at 5:00
  • could you please check its not working again – Man S. Aug 16 '16 at 5:55
  • Give Me both Url Again – Murtuza Zabuawala Aug 16 '16 at 6:02
  • have you been able to find error ? – Man S. Aug 16 '16 at 6:20
  • 1
    @MurtuzaZabuawala finally solved using => require_once('./../app/Mage.php'); – Gem Apr 17 at 7:32

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.