X-Cart: shopping cart software

X-Cart forums (https://forum.x-cart.com/index.php)
-   Dev Questions (https://forum.x-cart.com/forumdisplay.php?f=20)
-   -   Mini-cart (or other functionality) on a non-xcart page (https://forum.x-cart.com/showthread.php?t=14443)

Jon 06-08-2005 11:41 AM

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.

grnyj93 06-08-2005 12:26 PM

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?

Jon 06-08-2005 01:03 PM

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

Is the rest of your store functioning?

grnyj93 06-08-2005 01:06 PM

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.

Jon 06-08-2005 01:12 PM

Sounds like your config and whole site is likely messed up, what's the url?

grnyj93 06-08-2005 01:15 PM

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.

grnyj93 06-08-2005 01:30 PM

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.

grnyj93 06-08-2005 01:42 PM

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.

grnyj93 06-08-2005 01:54 PM

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?

Jon 06-08-2005 02:58 PM

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.


All times are GMT -8. The time now is 10:06 PM.

Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.