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'];
?>
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']; ?>"> </span></td><td valign="top" align="right" style="width:1px"><?php echo $product['quantity']; ?> x </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.