Follow us on Twitter X-Cart on Facebook Wiki
Shopping cart software Solutions for online shops and malls
 

Mini-cart (or other functionality) on a non-xcart page

 
Reply
   X-Cart forums > X-Cart 4 > Dev Questions
 
Thread Tools Search this Thread
  #1  
Old 06-08-2005, 11:41 AM
  Jon's Avatar 
Jon Jon is offline
 

X-Guru
  
Join Date: Oct 2002
Location: Vancouver, Canada
Posts: 4,200
 

Default Mini-cart (or other functionality) on a non-xcart page

I'm using mini-cart to php to show the theory behind how this works. You can do this for many of the x-cart features, including customer information, $login variable, etc.

It's important to understand however, that the auth.php adds overhead, because it essentially initializes x-cart.

Definitely do not include auth.php more than once on a page. I've put the auth.php include inside this external_minicart.php, but if you are going to have several includes like this, you'll want to include auth.php only once per page and not in your includes.

This example is for 4.0.13

Create a new file, called exernal_minicart.php with the following code and substitue your full path for the auth.php include:

Code:
<? require_once "/your/full/path/to/xcart/auth.php"; x_session_register ("cart"); $MINICART["total_cost"] = price_format(0); $MINICART["total_items"] = 0; $MINICART["sub_total"] = price_format(0); if (!empty($cart)) { if (!empty($cart["total_cost"])) $MINICART["total_cost"] = $cart["total_cost"]; if (!empty($cart["subtotal"])) $MINICART["subtotal"] = $cart["subtotal"]; if (!empty($cart["tax_cost"])) $MINICART["tax_cost"] = $cart["tax_cost"]; if (!empty($cart["shipping_cost"])) $MINICART["shipping_cost"] = $cart["shipping_cost"]; $MINICART["total_items"] = ((!empty($cart["products"]) and is_array($cart["products"]))?count($cart["products"]):0) + ((!empty($cart["giftcerts"]) and is_array($cart["giftcerts"]))?count($cart["giftcerts"]):0); ?> <table border="0" cellpadding="2" cellspacing="2"> <tr> <td>Items:</td> <td><?= $MINICART["total_items"]; ?></td> </tr> <tr> <td>Subtotal:</td> <td><?= number_format($MINICART["subtotal"], 2, '.', ','); ?></td> </tr> <tr> <td>Shipping:</td> <td><?= number_format($MINICART["shipping_cost"], 2, '.', ','); ?></td> </tr> <tr> <td>Tax:</td> <td><?= number_format($MINICART["tax_cost"], 2, '.', ','); ?></td> </tr> <tr> <td colspan="2"> <hr noshade size="1" color="#DBDBDB"> </td> </tr> <tr> <td>Total:</td> <td><?= number_format($MINICART["total_cost"], 2, '.', ','); ?></td> </tr> </table> <? } else { echo "Your shopping cart is currently empty."; } ?>

Include this file on any other php non-xcart page.
Reply With Quote
  #2  
Old 06-08-2005, 12:26 PM
 
grnyj93 grnyj93 is offline
 

Advanced Member
  
Join Date: Nov 2004
Location: US
Posts: 38
 

Default

Jon,

I have tried this and changed the auth.php path correctly. I am getting a
Code:
ERROR: Can not initiate application! Please check configuration.
error whether I have the external_minicart.php file in or out of the xcart directory.

Any guesses as to what I am doing wrong?
__________________
x-cart 4.0.13
Reply With Quote
  #3  
Old 06-08-2005, 01:03 PM
  Jon's Avatar 
Jon Jon is offline
 

X-Guru
  
Join Date: Oct 2002
Location: Vancouver, Canada
Posts: 4,200
 

Default

Unfortunately not too sure, I tested the exact code on a 4.0.13 without problem.

Is the rest of your store functioning?
Reply With Quote
  #4  
Old 06-08-2005, 01:06 PM
 
grnyj93 grnyj93 is offline
 

Advanced Member
  
Join Date: Nov 2004
Location: US
Posts: 38
 

Default

The rest seems to be working just find. Like I said it seems not to matter whether I have the file in the xcart directory or not.

If I comment out the following line
Code:
if (!defined('DIR_CUSTOMER')) die("ERROR: Can not initiate application! Please check configuration.");
then I get this error
Code:
rning: main(/config.php): failed to open stream: No such file or directory in /home/virtual/site23/fst/var/www/html/store/auth.php on line 37 Warning: main(): Failed opening '/config.php' for inclusion (include_path='.:/php/includes:/usr/share/php') in /home/virtual/site23/fst/var/www/html/store/auth.php on line 37 Fatal error: Call to undefined function: x_session_register() in /home/virtual/site23/fst/var/www/html/store/auth.php on line 38
Not sure if that helps at all.
__________________
x-cart 4.0.13
Reply With Quote
  #5  
Old 06-08-2005, 01:12 PM
  Jon's Avatar 
Jon Jon is offline
 

X-Guru
  
Join Date: Oct 2002
Location: Vancouver, Canada
Posts: 4,200
 

Default

Sounds like your config and whole site is likely messed up, what's the url?
Reply With Quote
  #6  
Old 06-08-2005, 01:15 PM
 
grnyj93 grnyj93 is offline
 

Advanced Member
  
Join Date: Nov 2004
Location: US
Posts: 38
 

Default

The URL is http://www.outdoorbasics.com/store

ok tried something and found this:
If I place the file (minicart.box.php - or external_minicart.php) in the xcart directory it will work if I access it directly. Problem occurs if I try to include it in a file outside the xcart directory.
__________________
x-cart 4.0.13
Reply With Quote
  #7  
Old 06-08-2005, 01:30 PM
 
grnyj93 grnyj93 is offline
 

Advanced Member
  
Join Date: Nov 2004
Location: US
Posts: 38
 

Default

If I change the following in auth.php
Code:
@include_once $_SERVER['DOCUMENT_ROOT'] . "/store/top.inc.php"; @include_once "../top.inc.php"; @include_once "../../top.inc.php";
(I changed the top on to be absolute) then I can get it to work except for the following errors
Code:
Warning: Cannot modify header information - headers already sent by (output started at /home/virtual/site23/fst/var/www/html/includes/header.inc.php:13) in /home/virtual/site23/fst/var/www/html/store/include/get_language.php on line 134 Warning: Cannot modify header information - headers already sent by (output started at /home/virtual/site23/fst/var/www/html/includes/header.inc.php:13) in /home/virtual/site23/fst/var/www/html/store/include/get_language.php on line 135
But the shopping cart part will work.
__________________
x-cart 4.0.13
Reply With Quote
  #8  
Old 06-08-2005, 01:42 PM
 
grnyj93 grnyj93 is offline
 

Advanced Member
  
Join Date: Nov 2004
Location: US
Posts: 38
 

Default

Well, I believe that I figured it out. I had a bit of php code in the top of the file (file #1) I was trying to include the minicart into from one of the things I tried before that was causing it. I can even have the minicart file outside the xcart directory.

Thanks for the help, and sorry it was my stupid mistake.

Another question I have is where did you get the info for the php code in the minicart file that pulls the info into the file? For instance if I wanted to do the same for the login 'box'.

I am not asking for you do necessarily do it for me, but rather teach me where you got it or how to know what to pull so I can do any one that I want.

Again, thanks for the help it is greatly appreciated.
__________________
x-cart 4.0.13
Reply With Quote
  #9  
Old 06-08-2005, 01:54 PM
 
grnyj93 grnyj93 is offline
 

Advanced Member
  
Join Date: Nov 2004
Location: US
Posts: 38
 

Default

Another question:

What is the syntax here?
Code:
<?= number_format($MINICART["total_cost"], 2, '.', ','); ?>
I assumed it was php but when I changed it to
Code:
<?php = number_format($MINICART["total_cost"], 2, '.', ','); ?>
It threw and error about the '=' so I changed it to
Code:
<?php number_format($MINICART["total_cost"], 2, '.', ','); ?>
and it didn't return anything.

Why?
__________________
x-cart 4.0.13
Reply With Quote
  #10  
Old 06-08-2005, 02:58 PM
  Jon's Avatar 
Jon Jon is offline
 

X-Guru
  
Join Date: Oct 2002
Location: Vancouver, Canada
Posts: 4,200
 

Default

K, great, that was confusing for me

---------------

The code syntax:

Code:
<?=

is equivalent to

Code:
<? echo

so you'd have to use:

Code:
<?php echo number_format($MINICART["total_cost"], 2, '.', ','); ?>

---------------

I pulled the mini-cart information from include/minicart.php and then added some additional code to pull additional info, removed all the smarty references and instead echo'd the information directly.
Reply With Quote
Reply
   X-Cart forums > X-Cart 4 > Dev Questions



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump


All times are GMT -8. The time now is 10:45 AM.

   

 
X-Cart forums © 2001-2020