Kryptronic Software Support Forum

You are viewing this forum as a guest. Login to an existing account, or create a new account, to reply to topics and to create new topics.

#1 01-26-2017 16:25:33

htw_simon
Member
From: UK
Registered: 11-20-2007
Posts: 83
Website

Adding the delivery estimate to the cart and mini cart totals

I'd like to be able to add the delivery estimate, if there is one, to the cart and mini cart totals. and include the name and cost from the custom delivery script in the cart too.

I tried setting the values as global variables but that doesn't work. I managed to get it to display correctly by cloning the shipestimator.php file and adding a location variable to the doestimator function of ECOM_ShipEstimator which directs the function to the new file just for the cart display, however this breaks the ajax update function.

Any ideas of the best way to achieve this?

Thanks!

Offline

 

#2 01-27-2017 09:06:24

webmaster
Administrator
From: York, PA
Registered: 04-20-2001
Posts: 19798
Website

Re: Adding the delivery estimate to the cart and mini cart totals

Are you using any realtime calculations at all for your shipping charges?  If you are, this is a very, very bad idea as it will cause much lag loading each page if and when changes are made to the cart.

You can do this and it's much easier than you're making it.

(1) Back out all your changes.  This is important.  Get those pieces back to stock.

(2) Access System / Displays / Skin Widgets and clone the cart widget.  It doesn't matter what you choose for the id, but don't use spaces or special characters, but I'll assume you use id 'MINICUSTOM'.  Just put an X in the Skin Widget Display Code field for now.

(3) Update the stock cart widget and set it's Display Status to false to turn it off.

(4) Access your site via FTP and browse to {private}/apps/ecom/ECOM/includes.  Take a look at the skinwidget_minicart.php file.  Copy it's contents into the Skin Widget Display Code field for your MINICUSTOM widget.

At this point you should have a minicart widget displaying on your site, and it will look like the stock one, but will be using the PHP code you have in your MINICUSTOM widget.  Verify this.

(5) The next thing to do is start modifying the code in your widget.  I'd imagine you're doing this all the way at the bottom, right after the minicart items foreach statement, and before the closeout of all the open divs at line 351:

Code:

} // End of foreach statement.

// YOUR CUSTOM CODE GOES HERE

print '</div></div></div>' . $eol;

// +--
// | Minicart JavaScript
// +--

As far as what your custom code is, this might get you along the right track, but I haven't tested it.  If I were doing it, I'd just combine the parts I needed from the ECOM_ShipEstimator class and the shipestimator.php display include right in there:

Code:

// +--
// | Get an estimate if we have delivery info available.
// +--

$stateprov  = $this->globals('core_session.stateprov');
$country    = $this->globals('core_session.country');
$postalcode = $this->globals('core_session.postalcode');
$rescom     = $this->globals('core_session.rescom');

if ((!(empty($stateprov))) && (!(empty($country))) && (!(empty($postalcode))) && (!(empty($country)))) {

     // +--
     // | Get estimate (from {private}/apps/ecom/ECOM_ShipEstimator/ECOM_ShipEstmator.php)
     // +--

     $CORE_Session =& $this->quick_object('CORE_Session','core');
     $ECOM_Ship    =& $this->quick_object('ECOM_Ship','ecom');

     $addbook = $this->globals('core_session.addbook');

     $xbook = array('fname'      => 'SHIPESTIMATOR',
                    'lname'      => 'SHIPESTIMATOR',
                    'company'    => 'SHIPESTIMATOR',
                    'addone'     => 'SHIPESTIMATOR',
                    'addtwo'     => 'SHIPESTIMATOR',
                    'city'       => 'SHIPESTIMATOR',
                    'stateprov'  => $stateprov,
                    'country'    => $country,
                    'postalcode' => $postalcode,
                    'rescom'     => $rescom);

     $hash           = md5(serialize($xbook));
     $addbook[$hash] = $xbook;

     $CORE_Session->sessvalues('addbook',$addbook);
     
     $sesess = array('items' => array());

     foreach ($mini['cart'] as $cartid => $item) {

          $xhash = serialize($item);
          $xhash = md5($xhash);

          $sesess['items'][$item['randid']] = array('deladd' => $hash, 'delgroup' => 'UNASSIGNED');

     } // End of if statement.

     $sesess = $ECOM_Ship->coship($sesess);

     unset($addbook[$hash]);

     $CORE_Session->sessvalues('addbook',$addbook);

     // +--
     // | Print Estimate (from {private}/apps/ecom/ECOM/includes/shipestimator.php)
     // +--

     // Do what you want here, based on shipestimator.php.  I imagine your display
     // may just total the default delivery charges in $sesess and display them.

} // End of if statement.

Nick Hendler

Offline

 

Board footer