Post by heizo » Wed Apr 06, 2011 2:58 am

Do you have the appropriate code in your wordpress header that was posted in this thread that tells you how to port OC session into wordpress?

My Blog / Site

$1 Hosting and Free Domain Name for OpenCart, Wordpress, Joomla, Droopal


New member

Posts

Joined
Wed Feb 09, 2011 1:12 am

Post by SupraTwinTurbo » Wed Apr 06, 2011 5:36 am

heizo wrote:if you log in and have SSL enabled (https), the session is wrapped in your SSL, so if you navigate back to your wordpress and wordpress is not wrapped in SSL (so its HTTP and not HTTPS) then you loose the session...I had to wrap both wordpress and the entire shopping cart in SSL to get my sessions to stick through the entire experience.

Let me know if this helps.
Hi Heizo,

Can you let us know how you wrapped both Wordpress and the entire cart in SSL to get your sessions to stick through the entire experience?

Thank you,

SupraTT

User avatar
New member

Posts

Joined
Thu Mar 24, 2011 12:43 pm
Location - NYC, NY USA

Post by theclownoftightness » Wed Apr 06, 2011 6:17 am

Nice job Heizo, saved me some work. I'm turning it into a plugin right now. The plugin will not be a full integration, but a bridge between opencart and wordpress. Might be able to do a mod rewrite and make it unoticeable. Right now I've built widgets for wordpress the display featured products, bestsellers, cart. Little bit more work and then it will be set~!~~!!

New member

Posts

Joined
Wed Mar 11, 2009 4:55 pm


New member

Posts

Joined
Wed Feb 09, 2011 1:12 am

Post by ftntravis » Wed Jun 15, 2011 3:27 pm

any update on this?

Newbie

Posts

Joined
Wed Jun 08, 2011 5:04 am

Post by heizo » Sun Jul 24, 2011 4:46 am

Didn't realize people were still posting :)

I just wrapped all of wordpress into an SSL, so both sides were encrypted. (took some header moding and a few plugins but eventually you can get everything swapped over to SSL)

Other then that little aspect, the code still works and is finished - havn't heard anything back about the wordpress plugin.

My Blog / Site

$1 Hosting and Free Domain Name for OpenCart, Wordpress, Joomla, Droopal


New member

Posts

Joined
Wed Feb 09, 2011 1:12 am

Post by fourgood » Mon Aug 29, 2011 2:41 pm

I also tried to integrate WP in OC. The problem i ran into was, that "if logged!" is not working. Instead i used

Code: Select all

<? if (isset($_SESSION[customer_id])) { ?>
to check if the user is logged in, which works quiet nicely.

Now i want a language switch on my site, but the translation variables like

Code: Select all

<?php echo $text_login; ?>
are not working inside of WP. Have anyone managed to fix this?

Active Member

Posts

Joined
Wed Oct 20, 2010 9:49 pm

Post by laptopcommuter » Fri Sep 16, 2011 1:51 am

I've added the code as suggested (making file path changes relative to my installation), but it is not working for me. Instead of running the script, the code is appearing as text on my page (see attached screenshot1.jpg). When I add the <?php to the beginning of the code, then the code seems to run until it gets to the set('config', $config); part...where it starts just displaying the code as text on my screen again (see attached screenshot2.jpg). Any insight would be GREATLY appreciated! I'm running the latest version of WP and OpenCart. Thank you so much, in advance :).
Here's the entirety of my code, modified with my filepath:

Code: Select all

</php
//////////////////// Open Cart Login Info

// Configuration
    require_once('spradleyshop/config.php');
    // Application Classes
    require_once(DIR_SYSTEM . 'spradleyshop/system/library/customer.php');
    require_once(DIR_SYSTEM . 'spradleyshop/system/library/currency.php');
    require_once(DIR_SYSTEM . 'spradleyshop/system/library/tax.php');
    require_once(DIR_SYSTEM . 'spradleyshop/system/library/weight.php');
    require_once(DIR_SYSTEM . 'spradleyshop/system/library/cart.php');
    // Engine
    require_once(DIR_SYSTEM . 'spradleyshop/system/engine/controller.php');
    require_once(DIR_SYSTEM . 'spradleyshop/system/engine/registry.php');

    // Common
    require_once(DIR_SYSTEM . 'spradleyshop/system/library/config.php');
    require_once(DIR_SYSTEM . 'spradleyshop/system/library/db.php');
    require_once(DIR_SYSTEM . 'spradleyshop/system/library/session.php');

    // Registry
    $registry = new Registry();

    // Config
    $config = new Config();
    $registry->set('config', $config);

    // Database
    $db = new DB(DB_DRIVER, DB_HOSTNAME, DB_USERNAME, DB_PASSWORD, DB_DATABASE);
    $registry->set('db', $db);

    // Session
    $session = new Session();
    $registry->set('session', $session);

    // Customer
    $registry->set('customer', new Customer($registry));

    // Currency
    $registry->set('currency', new Currency($registry));

    // Tax
    $registry->set('tax', new Tax($registry));

    // Weight
    $registry->set('weight', new Weight($registry));

    // Cart
    $registry->set('cart', new Cart($registry));

    require_once(DIR_APPLICATION . 'spradleyshop/catalog/controller/checkout/cart.php');


          $product_id = $registry->get('cart')->session->data['cart'];
          
          //var_dump($registry->get('cart')->session->data['cart']);
             
             
          
          $tf = false;
          foreach($product_id as $p=>$val) {
             
             $array = explode(':', $p);
                $product_id = $array[0];
             
             $key = $array[0].':'.$array[1];
             
             if (isset($array[1])) {
                  $options = explode('.', $array[1]);
                } else {
                  $options = array();
                }
             
             $cartSQL = mysql_fetch_assoc(mysql_query("
             SELECT DISTINCT *, pd.name AS name, p.image, m.name AS manufacturer, ss.name AS stock FROM " . DB_PREFIX . "product p
             LEFT JOIN " . DB_PREFIX . "product_description pd ON (p.product_id = pd.product_id)
             LEFT JOIN " . DB_PREFIX . "product_to_store p2s ON (p.product_id = p2s.product_id)
             LEFT JOIN " . DB_PREFIX . "manufacturer m ON (p.manufacturer_id = m.manufacturer_id)
             LEFT JOIN " . DB_PREFIX . "stock_status ss ON (p.stock_status_id = ss.stock_status_id)
             WHERE p.product_id = '".$product_id."' AND pd.language_id = '1' AND p2s.store_id = '0' AND ss.language_id = '1' AND p.date_available <= NOW() AND p.status = '1'"));
             ////////////////////
          
          foreach ($options as $product_option_value_id) {
                      $option_value_query = mysql_query("SELECT * FROM " . DB_PREFIX . "product_option_value pov LEFT JOIN " . DB_PREFIX . "product_option_value_description povd ON (pov.product_option_value_id = povd.product_option_value_id) WHERE pov.product_option_value_id = '" . (int)$product_option_value_id . "' AND pov.product_id = '" . (int)$product_id . "' AND povd.language_id = '1' ORDER BY pov.sort_order");
                   
                   if (mysql_num_rows($option_value_query)) {
                   $option_value_query = mysql_fetch_assoc($option_value_query);   
                      
                      $option_query = mysql_fetch_assoc(mysql_query("SELECT pod.name FROM " . DB_PREFIX . "product_option po LEFT JOIN " . DB_PREFIX . "product_option_description pod ON (po.product_option_id = pod.product_option_id) WHERE po.product_option_id = '" . (int)$option_value_query['product_option_id'] . "' AND po.product_id = '" . (int)$product_id . "' AND pod.language_id = '1' ORDER BY po.sort_order"));
                      
                        
                      
                        $option_data[] = array(
                             'product_option_value_id' => $product_option_value_id,
                             'name'                    => $option_query['name'],
                             'value'                   => $option_value_query['name'],
                             'prefix'                  => $option_value_query['prefix'],
                             'price'                   => $option_value_query['price']
                        );
                   }
                   }
          
          ////////////////////
          $products[] = array(
                  'key'        => $key,
                'product_id' => $product_id,
                  'name'       => $cartSQL['name'],
                'option'     => $option_data,
                  'quantity'   => $val,
                'stock'      => $cartSQL['stock'],
                'price'      => $cartSQL['price'],
                'tax_class_id'   => $cartSQL['tax_class_id'],
                'url'       => 'http://spradleyshop.wiwtyproject.com/index.php?route=product/product&product_id=' . $product_id
                );
             
          unset($option_data);
             
          }
          //var_dump($option_data); 
      //var_dump($products);

    $logged = $registry->get('session')->data['customer_id'];

    ?>

heizo wrote:Tried to trim down some of the includes that wasn't needed, still probably not the most efficient but it works. I get login status and cart information. From there you can mod it how you see fit.

NOTE: I am only using one language, wasn't able to figure out how to get language IDs in the time allotted to me, so I manually put them in. From the default install this should work for English.

The products are in a query called $cartSQL and the login info is a bool called $logged. This goes into your header as before.

Code: Select all

// Configuration
require_once('../Store/config.php');
// Application Classes
require_once(DIR_SYSTEM . 'library/customer.php');
require_once(DIR_SYSTEM . 'library/currency.php');
require_once(DIR_SYSTEM . 'library/tax.php');
require_once(DIR_SYSTEM . 'library/weight.php');
require_once(DIR_SYSTEM . 'library/cart.php');
// Engine
require_once(DIR_SYSTEM . 'engine/controller.php');
require_once(DIR_SYSTEM . 'engine/registry.php');

// Common
require_once(DIR_SYSTEM . 'library/config.php');
require_once(DIR_SYSTEM . 'library/db.php');
require_once(DIR_SYSTEM . 'library/session.php');

// Registry
$registry = new Registry();


// Config
$config = new Config();
$registry->set('config', $config);

// Database 
$db = new DB(DB_DRIVER, DB_HOSTNAME, DB_USERNAME, DB_PASSWORD, DB_DATABASE);
$registry->set('db', $db);


// Session
$session = new Session();
$registry->set('session', $session);

// Customer
$registry->set('customer', new Customer($registry));

// Currency
$registry->set('currency', new Currency($registry));

// Tax
$registry->set('tax', new Tax($registry));

// Weight
$registry->set('weight', new Weight($registry));


// Cart
$registry->set('cart', new Cart($registry));




require_once(DIR_APPLICATION . 'controller/module/cart.php');


		$product_id = $registry->get('cart')->session->data['cart'];
		$tf = false;
		foreach($product_id as $p=>$val) {
			if($tf) {
				$sql .=  'OR p.product_id = "'.$p.'"';	
			}else{
				$tf = true;
				$sql =  'p.product_id = "'.$p.'"';
			}
		}
		$cartSQL = mysql_query("
		SELECT DISTINCT *, pd.name AS name, p.image, m.name AS manufacturer, ss.name AS stock FROM " . DB_PREFIX . "product p 
		LEFT JOIN " . DB_PREFIX . "product_description pd ON (p.product_id = pd.product_id) 
		LEFT JOIN " . DB_PREFIX . "product_to_store p2s ON (p.product_id = p2s.product_id) 
		LEFT JOIN " . DB_PREFIX . "manufacturer m ON (p.manufacturer_id = m.manufacturer_id) 
		LEFT JOIN " . DB_PREFIX . "stock_status ss ON (p.stock_status_id = ss.stock_status_id) 
		WHERE (" . $sql . ") AND pd.language_id = '1' AND p2s.store_id = '0' AND ss.language_id = '1' AND p.date_available <= NOW() AND p.status = '1'");
		

while($row = mysql_fetch_array($cartSQL)) {
	echo $row['name'];	
}

$logged = $registry->get('session')->data['customer_id'];

Attachments

screenshot2.jpg

This is the suggested code added to WP header.php file WITH the opening <?php - screenshot2.jpg (277.75 KiB) Viewed 28325 times

screenshot1.jpg

This is the suggested code added to WP header.php file without the opening <?php - screenshot1.jpg (349.32 KiB) Viewed 28325 times



Posts

Joined
Sun Sep 11, 2011 7:48 pm

Post by heizo » Fri Sep 16, 2011 4:02 am

First thing I see is that your </php is actually supposed to be <?php (line 1)

Change that and see if that works.

My Blog / Site

$1 Hosting and Free Domain Name for OpenCart, Wordpress, Joomla, Droopal


New member

Posts

Joined
Wed Feb 09, 2011 1:12 am

Post by laptopcommuter » Fri Sep 16, 2011 4:38 am

Oh yeah, I saw that too...changed it but I still have the same problem. Sorry, I should have come back here and told you!


Posts

Joined
Sun Sep 11, 2011 7:48 pm

Post by heizo » Fri Sep 16, 2011 8:43 am

Can you send your file to me? pcpmith@gmail.com

I will look it over.

My Blog / Site

$1 Hosting and Free Domain Name for OpenCart, Wordpress, Joomla, Droopal


New member

Posts

Joined
Wed Feb 09, 2011 1:12 am

Post by laptopcommuter » Fri Sep 16, 2011 9:54 am

heizo wrote:Can you send your file to me? pcpmith@gmail.com

I will look it over.
Sending you a message right now :). Thanks!


Posts

Joined
Sun Sep 11, 2011 7:48 pm

Post by danger89 » Sat May 26, 2012 9:30 pm

You can easily check of the customer is logged, by checking the session. See below.

Code: Select all

<?php
// begin the session
session_start();

if(isset($_SESSION['customer_id']))
{
    $logged_in= true;
}
else
{
     $logged_in = false;
}
?>
Know you know if the customer is logged in at OpenLaptop the code above can be used in your own scripts as long it is on the same domain.

User avatar
Newbie

Posts

Joined
Sat Oct 15, 2011 8:12 pm
Location - Nederland

Post by openinteractive » Wed May 30, 2012 5:19 am

Hello Hiezo,
I am trying to integrate your code, with my ultimate goal to display the cart header links (welcome, shopping cart items, wishlist links etc.) from inside my wordpress / genesis theme. I have added your code that loads all of the opencart config into my functions.php (genesis doesn't use header.php), and also the link code from the openart header.tpl. but when i load my page, i get a bunch of errors.

Im using Wordpress 3.3.2 and Genesis 1.8.1

My functions.php code looks like this:

Code: Select all

// Configuration
require_once('/home/website/public_html/shop/config.php');
// Application Classes
require_once(DIR_SYSTEM . 'library/customer.php');
require_once(DIR_SYSTEM . 'library/currency.php');
require_once(DIR_SYSTEM . 'library/tax.php');
require_once(DIR_SYSTEM . 'library/weight.php');
require_once(DIR_SYSTEM . 'library/cart.php');
// Engine
require_once(DIR_SYSTEM . 'engine/controller.php');
require_once(DIR_SYSTEM . 'engine/registry.php');

// Common
require_once(DIR_SYSTEM . 'library/config.php');
require_once(DIR_SYSTEM . 'library/db.php');
require_once(DIR_SYSTEM . 'library/session.php');

// Registry
$registry = new Registry();

// Config
$config = new Config();
$registry->set('config', $config);

// Database 
$db = new DB(DB_DRIVER, DB_HOSTNAME, DB_USERNAME, DB_PASSWORD, DB_DATABASE);
$registry->set('db', $db);

// Session
$session = new Session();
$registry->set('session', $session);
// Customer
$registry->set('customer', new Customer($registry));
// Currency
$registry->set('currency', new Currency($registry));

// Tax
$registry->set('tax', new Tax($registry));

// Weight
$registry->set('weight', new Weight($registry));
// Cart
$registry->set('cart', new Cart($registry));

require_once(DIR_APPLICATION . 'controller/module/cart.php');
      $product_id = $registry->get('cart')->session->data['cart'];
      
      //var_dump($registry->get('cart')->session->data['cart']);        
      
      $tf = false;
      foreach($product_id as $p=>$val) {
         
         $array = explode(':', $p);
            $product_id = $array[0];
         
         $key = $array[0].':'.$array[1];
         
         if (isset($array[1])) {
              $options = explode('.', $array[1]);
            } else {
              $options = array();
            }
         
         $cartSQL = mysql_fetch_assoc(mysql_query("
         SELECT DISTINCT *, pd.name AS name, p.image, m.name AS manufacturer, ss.name AS stock FROM " . DB_PREFIX . "product p 
         LEFT JOIN " . DB_PREFIX . "product_description pd ON (p.product_id = pd.product_id) 
         LEFT JOIN " . DB_PREFIX . "product_to_store p2s ON (p.product_id = p2s.product_id) 
         LEFT JOIN " . DB_PREFIX . "manufacturer m ON (p.manufacturer_id = m.manufacturer_id) 
         LEFT JOIN " . DB_PREFIX . "stock_status ss ON (p.stock_status_id = ss.stock_status_id)
         WHERE p.product_id = '".$product_id."' AND pd.language_id = '1' AND p2s.store_id = '0' AND ss.language_id = '1' AND p.date_available <= NOW() AND p.status = '1'"));      
     
         ////////////////////
      
      foreach ($options as $product_option_value_id) {
                  $option_value_query = mysql_query("SELECT * FROM " . DB_PREFIX . "product_option_value pov LEFT JOIN " . DB_PREFIX . "product_option_value_description povd ON (pov.product_option_value_id = povd.product_option_value_id) WHERE pov.product_option_value_id = '" . (int)$product_option_value_id . "' AND pov.product_id = '" . (int)$product_id . "' AND povd.language_id = '1' ORDER BY pov.sort_order");
               
               if (mysql_num_rows($option_value_query)) {
               $option_value_query = mysql_fetch_assoc($option_value_query);   
                  
                  $option_query = mysql_fetch_assoc(mysql_query("SELECT pod.name FROM " . DB_PREFIX . "product_option po LEFT JOIN " . DB_PREFIX . "product_option_description pod ON (po.product_option_id = pod.product_option_id) WHERE po.product_option_id = '" . (int)$option_value_query['product_option_id'] . "' AND po.product_id = '" . (int)$product_id . "' AND pod.language_id = '1' ORDER BY po.sort_order"));                                
                  
                    $option_data[] = array(
                         'product_option_value_id' => $product_option_value_id,
                         'name'                    => $option_query['name'],
                         'value'                   => $option_value_query['name'],
                         'prefix'                  => $option_value_query['prefix'],
                         'price'                   => $option_value_query['price']
                    );
               }
               } 
      
      ////////////////////

      $products[] = array(
              'key'        => $key,
            'product_id' => $product_id,
              'name'       => $cartSQL['name'],
            'option'     => $option_data,
              'quantity'   => $val,
            'stock'      => $cartSQL['stock'],
            'price'      => $cartSQL['price'],
            'tax_class_id'   => $cartSQL['tax_class_id'],
            'url'       => 'http://officeoutofthebox.net/Store/index.php?route=product/product&product_id=' . $product_id
            );
         
      unset($option_data);
         
      }
      //var_dump($option_data);
  //var_dump($products);
$logged = $registry->get('session')->data['customer_id'];
}

add_action( 'genesis_header_right', 'openCartHeader' );
and my header nav code looks like this:

Code: Select all

  <div id="search">
    <div class="button-search"></div>
    <?php if ($filter_name) { ?>
    <input type="text" name="filter_name" value="<?php echo $filter_name; ?>" />
    <?php } else { ?>
    <input type="text" name="filter_name" value="<?php echo $text_search; ?>" onclick="this.value = '';" onkeydown="this.style.color = '#000000';" />
    <?php } ?>
  </div>
  <div id="welcome">
    <?php if (!$logged) { ?>
    <?php echo $text_welcome; ?>
    <?php } else { ?>
    <?php echo $text_logged; ?>
    <?php } ?>
  </div>
  <div class="links"><a href="<?php echo $home; ?>"><?php echo $text_home; ?></a><a href="<?php echo $wishlist; ?>" id="wishlist-total"><?php echo $text_wishlist; ?></a><a href="<?php echo $account; ?>"><?php echo $text_account; ?></a><a href="<?php echo $shopping_cart; ?>"><?php echo $text_shopping_cart; ?></a><a href="<?php echo $checkout; ?>"><?php echo $text_checkout; ?></a></div>          
Im getting the following errors:

Code: Select all

Notice: Constant DB_PASSWORD already defined in /home/website/public_html/shop/config.php on line 27

Warning: mysql_connect() [function.mysql-connect]: Access denied for user 'website_soul'@'localhost' (using password: YES) in /home/website/public_html/shop/system/database/mysql.php on line 6

Notice: Error: Could not make a database link using website_soul@localhost in /home/website/public_html/shop/system/database/mysql.php on line 7

Warning: mysql_select_db(): supplied argument is not a valid MySQL-Link resource in /home/website/public_html/shop/system/database/mysql.php on line 10

Notice: Error: Could not connect to database website_soul in /home/website/public_html/shop/system/database/mysql.php on line 11

Warning: mysql_query(): supplied argument is not a valid MySQL-Link resource in /home/website/public_html/shop/system/database/mysql.php on line 14

Warning: mysql_query(): supplied argument is not a valid MySQL-Link resource in /home/website/public_html/shop/system/database/mysql.php on line 15

Warning: mysql_query(): supplied argument is not a valid MySQL-Link resource in /home/website/public_html/shop/system/database/mysql.php on line 16

Warning: mysql_query(): supplied argument is not a valid MySQL-Link resource in /home/website/public_html/shop/system/database/mysql.php on line 17

Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at /home/website/public_html/wp-content/themes/genesis/lib/structure/header.php:31) in /home/website/public_html/shop/system/library/session.php on line 11

Warning: mysql_query(): supplied argument is not a valid MySQL-Link resource in /home/website/public_html/shop/system/database/mysql.php on line 21

Warning: mysql_error(): supplied argument is not a valid MySQL-Link resource in /home/website/public_html/shop/system/database/mysql.php on line 49

Warning: mysql_errno(): supplied argument is not a valid MySQL-Link resource in /home/website/public_html/shop/system/database/mysql.php on line 49

Notice: Error: 
Error No: 
SELECT * FROM currency in /home/website/public_html/shop/system/database/mysql.php on line 49

Warning: mysql_close(): supplied argument is not a valid MySQL-Link resource in /home/website/public_html/shop/system/database/mysql.php on line 67
Im not sure why im getting all of these errors. any help would be greatly appreciated!


heizo wrote:Tried to trim down some of the includes that wasn't needed, still probably not the most efficient but it works. I get login status and cart information. From there you can mod it how you see fit.

NOTE: I am only using one language, wasn't able to figure out how to get language IDs in the time allotted to me, so I manually put them in. From the default install this should work for English.

The products are in a query called $cartSQL and the login info is a bool called $logged. This goes into your header as before.

Code: Select all

// Configuration
require_once('../Store/config.php');
// Application Classes
require_once(DIR_SYSTEM . 'library/customer.php');
require_once(DIR_SYSTEM . 'library/currency.php');
require_once(DIR_SYSTEM . 'library/tax.php');
require_once(DIR_SYSTEM . 'library/weight.php');
require_once(DIR_SYSTEM . 'library/cart.php');
// Engine
require_once(DIR_SYSTEM . 'engine/controller.php');
require_once(DIR_SYSTEM . 'engine/registry.php');

// Common
require_once(DIR_SYSTEM . 'library/config.php');
require_once(DIR_SYSTEM . 'library/db.php');
require_once(DIR_SYSTEM . 'library/session.php');

// Registry
$registry = new Registry();


// Config
$config = new Config();
$registry->set('config', $config);

// Database 
$db = new DB(DB_DRIVER, DB_HOSTNAME, DB_USERNAME, DB_PASSWORD, DB_DATABASE);
$registry->set('db', $db);


// Session
$session = new Session();
$registry->set('session', $session);

// Customer
$registry->set('customer', new Customer($registry));

// Currency
$registry->set('currency', new Currency($registry));

// Tax
$registry->set('tax', new Tax($registry));

// Weight
$registry->set('weight', new Weight($registry));


// Cart
$registry->set('cart', new Cart($registry));




require_once(DIR_APPLICATION . 'controller/module/cart.php');


		$product_id = $registry->get('cart')->session->data['cart'];
		$tf = false;
		foreach($product_id as $p=>$val) {
			if($tf) {
				$sql .=  'OR p.product_id = "'.$p.'"';	
			}else{
				$tf = true;
				$sql =  'p.product_id = "'.$p.'"';
			}
		}
		$cartSQL = mysql_query("
		SELECT DISTINCT *, pd.name AS name, p.image, m.name AS manufacturer, ss.name AS stock FROM " . DB_PREFIX . "product p 
		LEFT JOIN " . DB_PREFIX . "product_description pd ON (p.product_id = pd.product_id) 
		LEFT JOIN " . DB_PREFIX . "product_to_store p2s ON (p.product_id = p2s.product_id) 
		LEFT JOIN " . DB_PREFIX . "manufacturer m ON (p.manufacturer_id = m.manufacturer_id) 
		LEFT JOIN " . DB_PREFIX . "stock_status ss ON (p.stock_status_id = ss.stock_status_id) 
		WHERE (" . $sql . ") AND pd.language_id = '1' AND p2s.store_id = '0' AND ss.language_id = '1' AND p.date_available <= NOW() AND p.status = '1'");
		

while($row = mysql_fetch_array($cartSQL)) {
	echo $row['name'];	
}

$logged = $registry->get('session')->data['customer_id'];


Posts

Joined
Wed May 30, 2012 4:09 am

Post by AliceH » Sun Nov 18, 2012 7:26 am

I am trying to use this code, I hope it will do what I want it to do. I have wordpress with buddypress intalled I have a pluggin that means that wordpress is using the same customer db so the buddypress/worpress registration is disabled. I want my customer to be able to go from oc to wp without having to log in again. Will this code do what I am asking and if so I have tried it but it does not seem to be working and I do not have a comment section on my graphene theme header.php. So I am not sure where to put it.
Alice.

https://www.embroidery-allsorts.com/


User avatar
Active Member

Posts

Joined
Sun Jan 09, 2011 11:00 am
Location - Australia

Post by Concept211 » Mon Dec 17, 2012 10:27 pm

Can someone please provide some sample code on how to display the number of products and currency total currently in your shopping cart outside of the OpenCart directory/site? I've seen it done on http://www.poketo.com and I've tried contacting the developer but she is not responding back. Any help is greatly appreciated...thanks!

User avatar
New member

Posts

Joined
Fri Oct 14, 2011 1:40 am

Post by mminten » Mon Dec 31, 2012 10:25 am

I tried to do this but I had to hardcode each require_once. So instead of using

require_once('../Store/config.php');

I had to use

require_once('http://www.myurl.com/Store/config.php');

If not the screen would go blank. Even after that I had to hardcode all of the other require_once to get the page to even load... not sure if it is getting the right files at all.

Now I just get the following error:

Error: Could not load database file DB_DRIVER!

My databases are separate. I have tried to change all the database info in this code to be the same as those in the config.php but then I get the error:

Error: Could not load database file mysql!

I haven't change get_ to include yet because I didn't think that it would make a difference in connecting to the session.

Any tips or Ideas on what I am doing wrong? I am using WP 3.5 and OC 1.5.4
heizo wrote:This will get you user session and cart contents including tax and modified prices based on options.


In the header of wordpress add this just below the comment text.

Code: Select all

//////////////////// Open Cart Login Info 

// Configuration
require_once('../Store/config.php');
// Application Classes
require_once(DIR_SYSTEM . 'library/customer.php');
require_once(DIR_SYSTEM . 'library/currency.php');
require_once(DIR_SYSTEM . 'library/tax.php');
require_once(DIR_SYSTEM . 'library/weight.php');
require_once(DIR_SYSTEM . 'library/cart.php');
// Engine
require_once(DIR_SYSTEM . 'engine/controller.php');
require_once(DIR_SYSTEM . 'engine/registry.php');

// Common
require_once(DIR_SYSTEM . 'library/config.php');
require_once(DIR_SYSTEM . 'library/db.php');
require_once(DIR_SYSTEM . 'library/session.php');

// Registry
$registry = new Registry();


// Config
$config = new Config();
$registry->set('config', $config);

// Database 
$db = new DB(DB_DRIVER, DB_HOSTNAME, DB_USERNAME, DB_PASSWORD, DB_DATABASE);
$registry->set('db', $db);


// Session
$session = new Session();
$registry->set('session', $session);

// Customer
$registry->set('customer', new Customer($registry));

// Currency
$registry->set('currency', new Currency($registry));

// Tax
$registry->set('tax', new Tax($registry));

// Weight
$registry->set('weight', new Weight($registry));


// Cart
$registry->set('cart', new Cart($registry));




require_once(DIR_APPLICATION . 'controller/module/cart.php');


		$product_id = $registry->get('cart')->session->data['cart'];
		
		//var_dump($registry->get('cart')->session->data['cart']);
			
			
		
		$tf = false;
		foreach($product_id as $p=>$val) {
			
			$array = explode(':', $p);
      		$product_id = $array[0];
			
			$key = $array[0].':'.$array[1];
			
			if (isset($array[1])) {
        		$options = explode('.', $array[1]);
      		} else {
        		$options = array();
      		}
			
			$cartSQL = mysql_fetch_assoc(mysql_query("
			SELECT DISTINCT *, pd.name AS name, p.image, m.name AS manufacturer, ss.name AS stock FROM " . DB_PREFIX . "product p 
			LEFT JOIN " . DB_PREFIX . "product_description pd ON (p.product_id = pd.product_id) 
			LEFT JOIN " . DB_PREFIX . "product_to_store p2s ON (p.product_id = p2s.product_id) 
			LEFT JOIN " . DB_PREFIX . "manufacturer m ON (p.manufacturer_id = m.manufacturer_id) 
			LEFT JOIN " . DB_PREFIX . "stock_status ss ON (p.stock_status_id = ss.stock_status_id) 
			WHERE p.product_id = '".$product_id."' AND pd.language_id = '1' AND p2s.store_id = '0' AND ss.language_id = '1' AND p.date_available <= NOW() AND p.status = '1'")); 
			
			
			
			////////////////////
		
		foreach ($options as $product_option_value_id) {
        		 	$option_value_query = mysql_query("SELECT * FROM " . DB_PREFIX . "product_option_value pov LEFT JOIN " . DB_PREFIX . "product_option_value_description povd ON (pov.product_option_value_id = povd.product_option_value_id) WHERE pov.product_option_value_id = '" . (int)$product_option_value_id . "' AND pov.product_id = '" . (int)$product_id . "' AND povd.language_id = '1' ORDER BY pov.sort_order");
					
					if (mysql_num_rows($option_value_query)) {
					$option_value_query = mysql_fetch_assoc($option_value_query);	
						
						$option_query = mysql_fetch_assoc(mysql_query("SELECT pod.name FROM " . DB_PREFIX . "product_option po LEFT JOIN " . DB_PREFIX . "product_option_description pod ON (po.product_option_id = pod.product_option_id) WHERE po.product_option_id = '" . (int)$option_value_query['product_option_id'] . "' AND po.product_id = '" . (int)$product_id . "' AND pod.language_id = '1' ORDER BY po.sort_order"));
						
        				
						
        				$option_data[] = array(
          					'product_option_value_id' => $product_option_value_id,
          					'name'                    => $option_query['name'],
          					'value'                   => $option_value_query['name'],
          					'prefix'                  => $option_value_query['prefix'],
          					'price'                   => $option_value_query['price']
        				);
					}
      			} 
		
		////////////////////
		
		
		$products[] = array(
        		'key' 		 => $key,
				'product_id' => $product_id,
        		'name'       => $cartSQL['name'],
				'option'     => $option_data,
        		'quantity'   => $val,
				'stock'      => $cartSQL['stock'],
				'price'      => $cartSQL['price'],
				'tax_class_id'	=> $cartSQL['tax_class_id'],
				'url'       => 'http://officeoutofthebox.net/Store/index.php?route=product/product&product_id=' . $product_id
      		);
			
		unset($option_data);
			
		}
		//var_dump($option_data);
		
		
		
		
		
		
 
  
  //var_dump($products);
 
$logged = $registry->get('session')->data['customer_id'];

?>

Code: Select all

Replace all of your get_header() 
with include

Code: Select all

(TEMPLATEPATH . "/header.php"); ?>
and anywhere else you want this information to show up at (sidebar, footer) make sure those includes are included with the include function and not wordpress's get function.

Now I made a cart module in the sidebar and my code looks like this.

Code: Select all

<?php
/**
 * The Sidebar containing the primary and secondary widget areas.
 *
 * @package WordPress
 * @subpackage Twenty_Ten
 * @since Twenty Ten 1.0
 */
?>

		<div id="primary" class="widget-area" role="complementary">
<?php
	
	if ( ! dynamic_sidebar( 'primary-widget-area' ) ) : ?>
			
		<?php endif; // end primary widget area ?>
        
        
        
		</div><!-- #primary .widget-area -->



<!--  .......................................................... -->
 <?php
 
$display_price = 1;
 //var_dump($products);

 ?>
 
        
		<div id="module_cart">
  <div><img src="http://www.officeoutofthebox.net/Store/catalog/view/theme/default/image/shopping_cart_header.jpg" alt="" /></div>
    
    <table cellpadding="4" cellspacing="0" style="width: 232px; border-left:#ebebeb 1px solid;  border-right:#ebebeb 1px solid;  border-bottom:#ebebeb 1px solid; ">
    <?php if ($products) { ?>
    
      <?php foreach ($products as $product) { ?>
      <tr>
        <td align="left" valign="top" style="width:1px"><span class="cart_remove" id="remove_<?php echo $product['key']; ?>">&nbsp;</span></td><td valign="top" align="right" style="width:1px"><?php echo $product['quantity']; ?>&nbsp;x&nbsp;</td>
        <td align="left" valign="top"><a class="cartLink" href="<?php echo $product['url']; ?>"><?php echo $product['name']; ?></a>
          <div>
            <?php 
			foreach ($product['option'] as $key => $value) { ?>
            - <small style="color: #999;"><?php echo $value['name']; ?> : <?php echo $value['value']; ?></small><br />
            <?php 
			if($value['prefix'] == '+') {
				$product['total'] = $product['price'] + $value['price'];
			}else if ($value['prefix'] == '-') {
				$product['total'] = $product['price'] - $value['price'];
			}
			
			} ?>
          </div></td>
      </tr>
      <?php 
	$total += $product['price'] * $product['quantity'];
	
	///////////////
	
	if ($product['tax_class_id']) {
				if (!isset($taxes)) {
					$taxes = ($product['price'] * $product['quantity']) / 100 * $registry->get('tax')->getRate($product['tax_class_id']);
				} else {
					$taxes += ($product['price'] * $product['quantity']) / 100 *$registry->get('tax')->getRate($product['tax_class_id']);
				}
	}
	
	///////////////
	
	?>
      <?php } ?>
      <tr><td align="right" colspan="3">
      
      <?php if ($display_price) { ?>
	<table cellpadding="0" cellspacing="0" align="right" style="display:inline-block;">
      <tr>
        <td align="right"><span class="cartTotals"><strong>Sub-Total:</strong></span></td>
        <td align="right"><span class="cartTotals2"><?php echo number_format($total, 2, '.', ' '); ?></span></td>
      </tr>
      <?php if ($taxes > 0) { ?>
      <tr>
      <td align="right"><span class="cartTotals"><strong>Ohio Tax:</strong></span></td>
      <td align="right"><span class="cartTotals2"><?php echo number_format($taxes, 2, '.', ' '); ?></span></td>
      </tr>
      <?php } ?>
      <tr>
      <td align="right"><span class="cartTotals"><strong>Total:</strong></span></td>
      <td align="right"><span class="cartTotals2"><?php echo number_format(($total + $taxes), 2, '.', ' '); ?></span></td>
      </tr>
     <tr><td colspan="2"><div style="padding-top:5px;text-align:center;clear:both;"><a class="cartLink" href="http://www.officeoutofthebox.net/Store/index.php?route=checkout/cart">View Cart</a> <span class="cartLink">|</span> <a class="cartLink" href="http://www.officeoutofthebox.net/Store/index.php?route=checkout/shipping">Checkout</a></div></td></tr> 
    </table>
    
	<?php } ?>
    
    <?php } else { ?>
    
    <table cellpadding="4" cellspacing="0" style="width: 232px; border-left:#ebebeb 1px solid;  border-right:#ebebeb 1px solid;  border-bottom:#ebebeb 1px solid; ">
    <tr><td><div style="text-align: center;">0 items</div></td></tr></table>

    <?php } ?>
      
      </td></tr>
      
      
      
      
    </table>
    <br />
    

<?php if ($ajax) { ?>
<script type="text/javascript" src="catalog/view/javascript/jquery/ajax_add.js"></script>
<?php } ?>
</div>
<script type="text/javascript"><!--

function getUrlParam(name) {
  var name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
  var regexS = "[\\?&]"+name+"=([^&#]*)";
  var regex = new RegExp(regexS);
  var results = regex.exec(window.location.href);
  if (results == null)
    return "";
  else
    return results[1];
}

$(document).ready(function () {
	$('.cart_remove').live('click', function () {
		if (!confirm('Confirm?')) {
			return false;
		}
		$(this).removeClass('cart_remove').addClass('cart_remove_loading');
		$.ajax({
			type: 'post',
			url: 'http://www.officeoutofthebox.net/Store/index.php?route=module/cart/callback',
			dataType: 'html',
			data: 'remove=' + this.id,
			success: function (html) {
				$('#module_cart .middle').html(html);
				if (getUrlParam('route').indexOf('checkout') != -1) {
					window.location.reload();
				}
			}
		});
	});
});
//--></script>


<!--  .......................................................... -->
Make sure to include the jQuery attachment in your header
<script type="text/javascript" src="address to your store/catalog/view/javascript/jquery/jquery-1.3.2.min.js"></script>
if you want them to be able to delete items from the cart - also make sure you copy over the appropriate styles for everything.

Enjoy.

Active Member

Posts

Joined
Tue Nov 20, 2012 9:33 am

Who is online

Users browsing this forum: No registered users and 8 guests