Loaded Commerce Community

Banner


Board index » Web Design and Development » Designers Workshop

All times are UTC - 5 hours




Post new topic Reply to topic  [ 6 posts ] 
Author Message
 Post subject: Add "Model" in shopping cart
PostPosted: Fri Nov 04, 2011 3:19 am 
Offline
CRE Freak

Joined: Thu Oct 27, 2011 3:14 pm
Posts: 37
Hello,

Is it possible to display "model" in shopping cart? I have "product name", "unit price" and "total price" but I want to show "model" in shopping cart and invoice. ....Is there code I can add to those files?


class shoppingCart {
var $contents, $total, $weight;

function shoppingCart() {
if ( ! isset($_SESSION['shoppingCart_data']) ) {
$this->reset();
$_SESSION['shoppingCart_data'] = array('contents' => array(),
'total' => 0,
'weight' => 0,
'cartID' => 0,
'content_type' => ''
);
}
$this->contents =& $_SESSION['shoppingCart_data']['contents'];
$this->total =& $_SESSION['shoppingCart_data']['total'];
$this->weight =& $_SESSION['shoppingCart_data']['weight'];
$this->cartID =& $_SESSION['shoppingCart_data']['cartID'];
$this->content_type =& $_SESSION['shoppingCart_data']['content_type'];
}

function restore_contents() {
//global $customer_id;

if (!isset($_SESSION['customer_id'])) return 0;

// insert current cart contents in database
if ($this->contents) {
reset($this->contents);
while (list($products_id, ) = each($this->contents)) {
$qty = $this->contents[$products_id]['qty'];
$product_query = tep_db_query("select products_id from " . TABLE_CUSTOMERS_BASKET . " where customers_id = '" . (int)$_SESSION['customer_id'] . "' and products_id = '" . tep_db_input($products_id) . "'");
if (!tep_db_num_rows($product_query)) {
tep_db_query("insert into " . TABLE_CUSTOMERS_BASKET . " (customers_id, products_id, customers_basket_quantity, customers_basket_date_added) values ('" . (int)$_SESSION['customer_id'] . "', '" . tep_db_input($products_id) . "', '" . tep_db_input($qty) . "', '" . date('Ymd') . "')");
if ($this->contents[$products_id]['attributes']) {
reset($this->contents[$products_id]['attributes']);
while (list($option, $value) = each($this->contents[$products_id]['attributes'])) {
tep_db_query("insert into " . TABLE_CUSTOMERS_BASKET_ATTRIBUTES . " (customers_id, products_id, products_options_id, products_options_value_id) values ('" . (int)$_SESSION['customer_id'] . "', '" . tep_db_input($products_id) . "', '" . (int)$option . "', '" . (int)$value . "')");
}
}
} else {
tep_db_query("update " . TABLE_CUSTOMERS_BASKET . " set customers_basket_quantity = '" . tep_db_input($qty) . "' where customers_id = '" . (int)$_SESSION['customer_id'] . "' and products_id = '" . tep_db_input($products_id) . "'");
}
}
}

// reset per-session cart contents, but not the database contents
$this->reset(FALSE);

$products_query = tep_db_query("select products_id, customers_basket_quantity from " . TABLE_CUSTOMERS_BASKET . " where customers_id = '" . (int)$_SESSION['customer_id'] . "'");
while ($products = tep_db_fetch_array($products_query)) {
$this->contents[$products['products_id']] = array('qty' => $products['customers_basket_quantity']);
// attributes
$attributes_query = tep_db_query("select products_options_id, products_options_value_id from " . TABLE_CUSTOMERS_BASKET_ATTRIBUTES . " where customers_id = '" . (int)$_SESSION['customer_id'] . "' and products_id = '" . tep_db_input($products['products_id']) . "'");
while ($attributes = tep_db_fetch_array($attributes_query)) {
$this->contents[$products['products_id']]['attributes'][$attributes['products_options_id']] = $attributes['products_options_value_id'];
}
}

$this->cleanup();
}

function reset($reset_database = FALSE) {
//global $customer_id;

$this->contents = array();
$this->total = 0;

if (isset($_SESSION['customer_id']) && $reset_database) {
tep_db_query("delete from " . TABLE_CUSTOMERS_BASKET . " where customers_id = '" . (int)$_SESSION['customer_id'] . "'");
tep_db_query("delete from " . TABLE_CUSTOMERS_BASKET_ATTRIBUTES . " where customers_id = '" . (int)$_SESSION['customer_id'] . "'");
}
}

function add_cart($products_id, $qty = '', $attributes = '') {
//global $new_products_id_in_cart, $customer_id;

$products_id = tep_get_uprid($products_id, $attributes);

if ($this->in_cart($products_id)) {
$this->update_quantity($products_id, $qty, $attributes);
} else {
if ($qty == '') $qty = '1'; // if no quantity is supplied, then add '1' to the customers basket

$this->contents[] = array($products_id);
$this->contents[$products_id] = array('qty' => $qty);
// insert into database
if (isset($_SESSION['customer_id'])) tep_db_query("insert into " . TABLE_CUSTOMERS_BASKET . " (customers_id, products_id, customers_basket_quantity, customers_basket_date_added) values ('" . (int)$customer_id . "', '" . tep_db_input($products_id) . "', '" . tep_db_input($qty) . "', '" . date('Ymd') . "')");

if (is_array($attributes)) {
reset($attributes);
while (list($option, $value) = each($attributes)) {
$this->contents[$products_id]['attributes'][$option] = $value;
// insert into database
if (isset($_SESSION['customer_id'])) tep_db_query("insert into " . TABLE_CUSTOMERS_BASKET_ATTRIBUTES . " (customers_id, products_id, products_options_id, products_options_value_id) values ('" . (int)$customer_id . "', '" . tep_db_input($products_id) . "', '" . (int)$option . "', '" . (int)$value . "')");
}
}
$_SESSION['new_products_id_in_cart'] = $products_id;
}
$this->cleanup();
}

function update_quantity($products_id, $quantity = '', $attributes = '') {
//global $customer_id;

if ($quantity == '') return true; // nothing needs to be updated if theres no quantity, so we return true..

$this->contents[$products_id] = array('qty' => $quantity);
// update database
if (isset($_SESSION['customer_id'])) tep_db_query("update " . TABLE_CUSTOMERS_BASKET . " set customers_basket_quantity = '" . tep_db_input($quantity) . "' where customers_id = '" . (int)$customer_id . "' and products_id = '" . tep_db_input($products_id) . "'");

if (is_array($attributes)) {
reset($attributes);
while (list($option, $value) = each($attributes)) {
$this->contents[$products_id]['attributes'][$option] = $value;
// update database
if (isset($_SESSION['customer_id'])) tep_db_query("update " . TABLE_CUSTOMERS_BASKET_ATTRIBUTES . " set products_options_value_id = '" . (int)$value . "' where customers_id = '" . (int)$customer_id . "' and products_id = '" . tep_db_input($products_id) . "' and products_options_id = '" . (int)$option . "'");
}
}
}

function cleanup() {
//global $customer_id;

reset($this->contents);
while (list($key,) = each($this->contents)) {
if ($this->contents[$key]['qty'] < 1) {
unset($this->contents[$key]);
// remove from database
if (isset($_SESSION['customer_id'])) {
tep_db_query("delete from " . TABLE_CUSTOMERS_BASKET . " where customers_id = '" . (int)$_SESSION['customer_id'] . "' and products_id = '" . tep_db_input($key) . "'");
tep_db_query("delete from " . TABLE_CUSTOMERS_BASKET_ATTRIBUTES . " where customers_id = '" . (int)$_SESSION['customer_id'] . "' and products_id = '" . tep_db_input($key) . "'");
}
}
}
}

function count_contents() { // get total number of items in cart
$total_items = 0;
if (is_array($this->contents)) {
reset($this->contents);
while (list($products_id, ) = each($this->contents)) {
$total_items += $this->get_quantity($products_id);
}
}
return $total_items;
}

function get_quantity($products_id) {
if ($this->contents[$products_id]) {
return $this->contents[$products_id]['qty'];
} else {
return 0;
}
}

function in_cart($products_id) {
if ($this->contents[$products_id]) {
return true;
} else {
return false;
}
}

function remove($products_id) {
//global $customer_id;

unset($this->contents[$products_id]);
// remove from database
if (isset($_SESSION['customer_id'])) {
tep_db_query("delete from " . TABLE_CUSTOMERS_BASKET . " where customers_id = '" . (int)$_SESSION['customer_id'] . "' and products_id = '" . tep_db_input($products_id) . "'");
tep_db_query("delete from " . TABLE_CUSTOMERS_BASKET_ATTRIBUTES . " where customers_id = '" . (int)$_SESSION['customer_id'] . "' and products_id = '" . tep_db_input($products_id) . "'");
}
}

function remove_all() {
$this->reset();
}

function get_product_id_list() {
$product_id_list = '';
if (is_array($this->contents))
{
reset($this->contents);
while (list($products_id, ) = each($this->contents)) {
$product_id_list .= ', ' . $products_id;
}
}
return substr($product_id_list, 2);
}

function calculate() {
$this->total = 0;
$this->weight = 0;
if (!is_array($this->contents)) return 0;

reset($this->contents);
while (list($products_id, ) = each($this->contents)) {
$qty = $this->contents[$products_id]['qty'];

// products price
$product_query = tep_db_query("select products_id, products_price, products_tax_class_id, products_weight from " . TABLE_PRODUCTS . " where products_id='" . (int)tep_get_prid($products_id) . "'");
if ($product = tep_db_fetch_array($product_query)) {
$prid = $product['products_id'];
$products_tax = tep_get_tax_rate($product['products_tax_class_id']);
$products_price = $product['products_price'];
$products_weight = $product['products_weight'];

$specials_query = tep_db_query("select specials_new_products_price from " . TABLE_SPECIALS . " where products_id = '" . (int)$prid . "' and status = '1'");
if (tep_db_num_rows ($specials_query)) {
$specials = tep_db_fetch_array($specials_query);
$products_price = $specials['specials_new_products_price'];
}

$this->total += tep_add_tax($products_price, $products_tax) * $qty;
$this->weight += ($qty * $products_weight);
}

// attributes price
if (isset($this->contents[$products_id]['attributes'])) {
reset($this->contents[$products_id]['attributes']);
while (list($option, $value) = each($this->contents[$products_id]['attributes'])) {
$attribute_price_query = tep_db_query("select options_values_price, price_prefix from " . TABLE_PRODUCTS_ATTRIBUTES . " where products_id = '" . (int)$prid . "' and options_id = '" . (int)$option . "' and options_values_id = '" . (int)$value . "'");
$attribute_price = tep_db_fetch_array($attribute_price_query);
if ($attribute_price['price_prefix'] == '+') {
$this->total += $qty * tep_add_tax($attribute_price['options_values_price'], $products_tax);
} else {
$this->total -= $qty * tep_add_tax($attribute_price['options_values_price'], $products_tax);
}
}
}
}
}

function attributes_price($products_id) {
$attributes_price = 0;

if (isset($this->contents[$products_id]['attributes'])) {
reset($this->contents[$products_id]['attributes']);
while (list($option, $value) = each($this->contents[$products_id]['attributes'])) {
$attribute_price_query = tep_db_query("select options_values_price, price_prefix from " . TABLE_PRODUCTS_ATTRIBUTES . " where products_id = '" . (int)$products_id . "' and options_id = '" . (int)$option . "' and options_values_id = '" . (int)$value . "'");
$attribute_price = tep_db_fetch_array($attribute_price_query);
if ($attribute_price['price_prefix'] == '+') {
$attributes_price += $attribute_price['options_values_price'];
} else {
$attributes_price -= $attribute_price['options_values_price'];
}
}
}

return $attributes_price;
}

function get_products() {
global $languages_id;
$languages_id = '1';
if (!is_array($this->contents)) return false;
$products_array = array();
reset($this->contents);
while (list($products_id, ) = each($this->contents)) {
$products_query = tep_db_query("select p.products_id, pd.products_name, p.products_model, p.products_price, p.products_weight, p.products_tax_class_id, p.products_length, p.products_width, p.products_height, p.products_ready_to_ship from " . TABLE_PRODUCTS . " p, " . TABLE_PRODUCTS_DESCRIPTION . " pd where p.products_id='" . (int)tep_get_prid($products_id) . "' and pd.products_id = p.products_id and pd.language_id = '" . (int)$languages_id . "'");
if ($products = tep_db_fetch_array($products_query)) {
$prid = $products['products_id'];
$products_price = $products['products_price'];

$specials_query = tep_db_query("select specials_new_products_price from " . TABLE_SPECIALS . " where products_id = '" . (int)$prid . "' and status = '1'");
if (tep_db_num_rows($specials_query)) {
$specials = tep_db_fetch_array($specials_query);
$products_price = $specials['specials_new_products_price'];
}

$products_array[] = array('id' => $products_id,
'name' => $products['products_name'],
'model' => $products['products_model'],
'price' => $products_price,
'quantity' => $this->contents[$products_id]['qty'],
'weight' => $products['products_weight'],
// Dimensional UPS begin
'length' => $products['products_length'],
'width' => $products['products_width'],
'height' => $products['products_height'],
'ready_to_ship' => $products['products_ready_to_ship'],
// Dimensional UPS end
'final_price' => ($products_price + $this->attributes_price($products_id)),
'tax_class_id' => $products['products_tax_class_id'],
'attributes' => (isset($this->contents[$products_id]['attributes']) ? $this->contents[$products_id]['attributes'] : ''));
}
}
return $products_array;
}

function show_total() {
$this->calculate();

return $this->total;
}

function show_weight() {
$this->calculate();

return $this->weight;
}
function get_content_type() {
$this->content_type = false;

if ( (DOWNLOAD_ENABLED == 'true') && ($this->count_contents() > 0) ) {
reset($this->contents);
while (list($products_id, ) = each($this->contents)) {
if (isset($this->contents[$products_id]['attributes'])) {
reset($this->contents[$products_id]['attributes']);
while (list(, $value) = each($this->contents[$products_id]['attributes'])) {
$virtual_check_query = tep_db_query("select count(*) as total from " . TABLE_PRODUCTS_ATTRIBUTES . " pa, " . TABLE_PRODUCTS_ATTRIBUTES_DOWNLOAD . " pad where pa.products_id = '" . (int)$products_id . "' and pa.options_values_id = '" . (int)$value . "' and pa.products_attributes_id = pad.products_attributes_id");
$virtual_check = tep_db_fetch_array($virtual_check_query);

if ($virtual_check['total'] > 0) {
switch ($this->content_type) {
case 'physical':
$this->content_type = 'mixed';

return $this->content_type;
break;
default:
$this->content_type = 'virtual';
break;
}
} else {
switch ($this->content_type) {
case 'virtual':
$this->content_type = 'mixed';

return $this->content_type;
break;
default:
$this->content_type = 'physical';
break;
}
}
}
// ICW ADDED CREDIT CLASS - Begin
} elseif ($this->show_weight() == 0) {
reset($this->contents);
while (list($products_id, ) = each($this->contents)) {
$virtual_check_query = tep_db_query("select products_weight from " . TABLE_PRODUCTS . " where products_id = '" . $products_id . "'");
$virtual_check = tep_db_fetch_array($virtual_check_query);
if ($virtual_check['products_weight'] == 0) {
switch ($this->content_type) {
case 'physical':
$this->content_type = 'mixed';

return $this->content_type;
break;
default:
$this->content_type = 'virtual_weight';
break;
}
} else {
switch ($this->content_type) {
case 'virtual':
$this->content_type = 'mixed';

return $this->content_type;
break;
default:
$this->content_type = 'physical';
break;
}
}
}
// ICW ADDED CREDIT CLASS - End
} else {
switch ($this->content_type) {
case 'virtual':
$this->content_type = 'mixed';

return $this->content_type;
break;
default:
$this->content_type = 'physical';
break;
}
}
}
} else {
$this->content_type = 'physical';
}

return $this->content_type;
}


function unserialize($broken) {
for(reset($broken);$kv=each($broken);) {
$key=$kv['key'];
if (gettype($this->$key)!="user function")
$this->$key=$kv['value'];
}
}

}
?>


Top
 Profile  
 
 Post subject: Re: Add "Model" in shopping cart
PostPosted: Sat Nov 05, 2011 12:48 am 
Offline
CRE Legend
User avatar

Joined: Thu Jun 12, 2008 6:39 am
Posts: 2405
Location: New Zealand
The file you need to look at is /templates/content/shopping_cart.tpl.php and you should be able to copy pretty much what happens for product name - eg add in a new column for the Model:

Code:
$info_box_contents[0][] = array('params' => 'class="productListing-heading"',
                                    'text' => 'Model');

And the call the info:
Code:
$info_box_contents[$cur_row][] = array('params' => 'class="productListing-data"',
                                             'text' => $products[$i]['model']);

Product model in the invoice? Should already be there (this from admin/invoice.php from a 6.4.1a B2B cart):
Code:
<td class="dataTableHeadingContent"><?php echo TABLE_HEADING_PRODUCTS_MODEL; ?></td>

Simon

_________________
www.codemehappy.com
For Cre Loaded tips, how-to articles and more


Top
 Profile  
 
 Post subject: Re: Add "Model" in shopping cart
PostPosted: Sat Nov 05, 2011 1:05 am 
Offline
CRE Freak

Joined: Thu Oct 27, 2011 3:14 pm
Posts: 37
I am going to try this after I finish upgrading to a newer version of CRE Loaded. Thank you!! Will let u know how it goes. -:)


Top
 Profile  
 
 Post subject: Re: Add "Model" in shopping cart
PostPosted: Sat Nov 05, 2011 1:20 am 
Offline
CRE Legend
User avatar

Joined: Thu Jun 12, 2008 6:39 am
Posts: 2405
Location: New Zealand
bubuinla wrote:
I am going to try this after I finish upgrading to a newer version of CRE Loaded. Thank you!! Will let u know how it goes. -:)

Pretty sure it'll work :)

Simon

_________________
www.codemehappy.com
For Cre Loaded tips, how-to articles and more


Top
 Profile  
 
 Post subject: Re: Add "Model" in shopping cart
PostPosted: Sat Nov 19, 2011 3:54 pm 
Offline
CRE Freak

Joined: Thu Oct 27, 2011 3:14 pm
Posts: 37
Hi Simon,

I got the title Model inserted but I don't know where to put this line in.

$info_box_contents[$cur_row][] = array('params' => 'class="productListing-data"',
'text' => $products[$i]['model']);

p.s. Does the model name has to be all unique? In other words, would it cause a problem if I have duplicated model names?


Top
 Profile  
 
 Post subject: Re: Add "Model" in shopping cart
PostPosted: Sat Nov 19, 2011 9:45 pm 
Offline
CRE Legend
User avatar

Joined: Thu Jun 12, 2008 6:39 am
Posts: 2405
Location: New Zealand
So (around line 220):
Code:
$info_box_contents[$cur_row][] = array('params' => 'class="productListing-data"',
                                             'text' => $products_model);

would go in the same order as the heading :
Code:
$info_box_contents[0][] = array('params' => 'class="productListing-heading"',
                                    'text' => 'Model');

So if the name was first, model second, each of the above lines would go second in their respective areas of code.

Simon

_________________
www.codemehappy.com
For Cre Loaded tips, how-to articles and more


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 6 posts ] 

Board index » Web Design and Development » Designers Workshop

All times are UTC - 5 hours


Who is online

Users browsing this forum: No registered users and 3 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
It is currently Thu May 24, 2012 6:50 am
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group

Login

Forums Latest Activity

Top Listing

1. Cart2Cart - Shopping...
    Category: Shopping Cart Database Conversion Scripts
    
2. Points & Rewards PLUS!...
    Category: Add-Ons
    
3. Configuration Server...
    Category: Fixes
    
4. Credit Card with CCV
    Category: Payment Modules
    
5. CC7333_ATS
    Category: Templates
    
Show more...

© CRE Loaded is a product of Chain Reaction Ecommerce, Inc. Usage & Privacy Policy