Jump to content
  • Checkout
  • Login
  • Get in touch

osCommerce

The e-commerce.

Seperate Pricing Per Customer v3.5


scendent

Recommended Posts

Here's the classes/shopping_cart.php problem.

My classes/shopping_cart.php is successfully edited to work with "SPPC hide products and categories from groups" [and an auction contrib that not really finished yet so I can lose that if I have to temporarily]

 

I have made an attempt to edit my shopping_cart.php as per the install instructions in SPPC attributes mod of November 7 2006 and this is the output if I try to put something in the cart

1052 - Column: 'products_id' in where clause is ambiguous

 

select products_status, options_id, options_values_id, attributes_hide_from_groups, '0' as hide_attr_status from products left join products_attributes using(products_id) where products_id = '660'

 

[TEP STOP]

I get the same result when I use the shopping_cart.php in the package...

 

//Micke

 

[...and don't try to tell me your not a genius - I was this close to start posting ASCII homages...]

Link to comment
Share on other sites

Here's the classes/shopping_cart.php problem.

My classes/shopping_cart.php is successfully edited to work with "SPPC hide products and categories from groups" [and an auction contrib that not really finished yet so I can lose that if I have to temporarily]

 

I have made an attempt to edit my shopping_cart.php as per the install instructions in SPPC attributes mod of November 7 2006 and this is the output if I try to put something in the cart

Strange that I don't have the problem on the version 5 I use.... but I can see why it throws such an error.

Can you change the syntax to avoid it (class shopping cart, around line 164)? :

// BOF SPPC attribute hide check, original query expanded to include attributes
	$check_product_query = tep_db_query("select products_status, options_id, options_values_id, attributes_hide_from_groups, '0' as hide_attr_status from " . TABLE_PRODUCTS . " p left join " . TABLE_PRODUCTS_ATTRIBUTES . " using(products_id) where p.products_id = '" . (int)$products_id . "'");

So after " . TABLE_PRODUCTS . " there comes a "p" and products_id is preceded by "p."

Link to comment
Share on other sites

I'm in the wrong location right now for testing this on my "SPPC hide products and categories from groups - shopping_cart.php"...

So I downloaded the 11/7 package and tried your fix on that shopping_cart.php...

 

Result:

Yes - You can put something in the cart and there's no error message.

Yes - Items with attributes added to your cart gets the "right" price when you have logged in.

No - Altogether hidden items and attribute-hidden items stays in your cart after logging in.

 

I think I'll have a chance to try this out on my "SPPC hide products and categories from groups - shopping_cart.php" in about 12 hrs...

//Micke

Link to comment
Share on other sites

I'm in the wrong location right now for testing this on my "SPPC hide products and categories from groups - shopping_cart.php"...

So I downloaded the 11/7 package and tried your fix on that shopping_cart.php...

 

Result:

Yes - You can put something in the cart and there's no error message.

Yes - Items with attributes added to your cart gets the "right" price when you have logged in.

No - Altogether hidden items and attribute-hidden items stays in your cart after logging in.

Hidden items should be removed from the shopping cart when you log in (if it is hidden for the customer group you belong to). Regarding the attribute-hide. Perhaps there is a MySQL issue (working for me, not for you).

 

To be on the safe side I think this is cleaner (get the base products_id out from the products_id, although MySQL does this usually for you; code from classes/shopping_cart.php):

// BOF SPPC attribute hide/invalid check: loop through the shopping cart and check the attributes if they
// are hidden for the now logged-in customer
	while (list($products_id, ) = each($this->contents)) {
				// only check attributes if they are set for the product in the cart
			   if (isset($this->contents[$products_id]['attributes'])) {
			$check_attributes_query = tep_db_query("select options_id, options_values_id, attributes_hide_from_groups, '0' as hide_attr_status from " . TABLE_PRODUCTS_ATTRIBUTES . " where products_id = '" . tep_get_prid($products_id) . "'");

Notice the tep_get_prid

Link to comment
Share on other sites

hmmm. I put the "p." in there and the "tep_get_prid"...

Still does not work for me. Same result - the shopping cart will not clean up itself upon loggin in. Attribute prices are corrected...

Maybe if I did the same "p." and "tep_get_prid" tricks with every query to that table in shopping_cart?

//Micke

Link to comment
Share on other sites

Stuck.

 

Maybe if I do it all over again?

I still have my old "SPPC hide products and categories from groups"-shopping_cart.php

(it's the one on line right now)

Should I post the 492 lines?

Or maybe just get myself a cup of coffee...

 

//Micke

Link to comment
Share on other sites

Maybe if I do it all over again?

Let's see if this works. I left out the part after the function get_products() which hasn't altered for SPPC.

<?php

/*

$Id: shopping_cart.php,v 1.35 2003/06/25 21:14:33 hpdl Exp $

adapted for Separate Pricing Per Customer v4.2.0, Hide products and categories for groups 2006/11/17

 

osCommerce, Open Source E-Commerce Solutions

http://www.oscommerce.com

 

Copyright (c) 2003 osCommerce

 

Released under the GNU General Public License

*/

 

class shoppingCart {

var $contents, $total, $weight, $cartID, $content_type;

 

function shoppingCart() {

$this->reset();

}

 

function restore_contents() {

// BOF Separate Pricing Per Customer

global $customer_id, $sppc_customer_group_id;

 

if (!tep_session_is_registered('customer_id')) return false;

 

if(!tep_session_is_registered('sppc_customer_group_id')) {

$this->cg_id = '0';

} else {

$this->cg_id = $sppc_customer_group_id;

}

// EOF Separate Pricing Per Customer

 

// insert current cart contents in database

if (is_array($this->contents)) {

reset($this->contents);

// BOF SPPC attribute hide/invalid check: loop through the shopping cart and check the attributes if they

// are hidden for the now logged-in customer

while (list($products_id, ) = each($this->contents)) {

// only check attributes if they are set for the product in the cart

if (isset($this->contents[$products_id]['attributes'])) {

$check_attributes_query = tep_db_query("select options_id, options_values_id, attributes_hide_from_groups, '0' as hide_attr_status from " . TABLE_PRODUCTS_ATTRIBUTES . " where products_id = '" . tep_get_prid($products_id) . "'");

while ($_check_attributes = tep_db_fetch_array($check_attributes_query)) {

$attr_hide_array = array(); // empty array in case it is still around and filled

$attr_hide_array = explode(",", $_check_attributes['attributes_hide_from_groups']);

if (in_array($this->cg_id, $attr_hide_array)) {

$_check_attributes['hide_attr_status'] = '1';

}

$check_attributes[] = $_check_attributes;

} // end while ($_check_attributes = tep_db_fetch_array($check_attributes_query))

$no_of_check_attributes = count($check_attributes);

$change_products_id = '0';

 

foreach($this->contents[$products_id]['attributes'] as $attr_option => $attr_option_value) {

$valid_option = '0';

for ($x = 0; $x < $no_of_check_attributes; $x++) {

if ($attr_option == $check_attributes[$x]['options_id'] && $attr_option_value == $check_attributes[$x]['options_values_id']) {

$valid_option = '1';

if ($check_attributes[$x]['hide_attr_status'] == '1') {

// delete hidden attributes from array attributes, change products_id accordingly later

$change_products_id = '1';

unset($this->contents[$products_id]['attributes'][$attr_option]);

}

} // end if ($attr_option == $check_attributes[$x]['options_id']....

} // end for ($x = 0; $x < $no_of_check_attributes; $x++)

if ($valid_option == '0') {

// after having gone through the options for this product and not having found a matching one

// we can conclude that apparently this is not a valid option for this product so remove it

unset($this->contents[$products_id]['attributes'][$attr_option]);

// change products_id accordingly later

$change_products_id = '1';

}

} // end foreach($this->contents[$products_id]['attributes'] as $attr_option => $attr_option_value)

 

if ($change_products_id == '1') {

$original_products_id = $products_id;

$products_id = tep_get_prid($original_products_id);

$products_id = tep_get_uprid($products_id, $this->contents[$original_products_id]['attributes']);

// add the product without the hidden attributes to the cart

$this->contents[$products_id] = $this->contents[$original_products_id];

// delete the originally added product with the hidden attributes

unset($this->contents[$original_products_id]);

}

} // end if (isset($this->contents[$products_id]['attributes']))

} // end while (list($products_id, ) = each($this->contents))

reset($this->contents); // reset the array otherwise the cart will be emptied

// EOF SPPC attribute hide/invalid check

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)$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)$customer_id . "', '" . tep_db_input($products_id) . "', '" . $qty . "', '" . date('Ymd') . "')");

if (isset($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)$customer_id . "', '" . tep_db_input($products_id) . "', '" . (int)$option . "', '" . (int)$value . "')");

}

}

} else {

tep_db_query("update " . TABLE_CUSTOMERS_BASKET . " set customers_basket_quantity = '" . $qty . "' where customers_id = '" . (int)$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)$customer_id . "'");

// BOF SPPC hide products and categories from groups

$no_of_products_in_basket = 0;

while ($_products = tep_db_fetch_array($products_query)) {

$temp_post_get_array[] = $_products['products_id'];

$products[] = $_products;

$no_of_products_in_basket += 1;

}

if ($no_of_products_in_basket > 0) {

$hide_status_products = array();

$hide_status_products = tep_get_hide_status($hide_status_products, $this->cg_id, $temp_post_get_array);

for ($i=0; $i < $no_of_products_in_basket; $i++) {

foreach($hide_status_products as $key => $subarray) {

if ($subarray['products_id'] == tep_get_prid($products[$i]['products_id']) && $subarray['hidden'] == '0') {

// not hidden for this customer, can be added to the object shoppingCart

$this->contents[$products[$i]['products_id']] = array('qty' => $products[$i]['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)$customer_id . "' and products_id = '" . tep_db_input($products[$i]['products_id']) . "'");

while ($attributes = tep_db_fetch_array($attributes_query)) {

$this->contents[$products[$i]['products_id']]['attributes'][$attributes['products_options_id']] = $attributes['products_options_value_id'];

}

} elseif ($subarray['products_id'] == tep_get_prid($products[$i]['products_id']) && $subarray['hidden'] == '1') {

// product is hidden for the customer, don't add to object shoppingCart, delete from db next

$products_to_delete_from_cb[] = $products[$i]['products_id'];

} // end if/elseif

}// end foreach ($hide_status_products as $key => $subarray)

} // end for ($i=0; $i < $no_of_products_in_basket; $i++)

 

// delete from the database those products that are hidden from this customer

if (tep_not_null($products_to_delete_from_cb)) {

$no_of_iterations = count($products_to_delete_from_cb);

// since the products_id in the table customer_basket and customer_basket_attributes can contain

// attributes like 1{4}2{3}6 we need to delete them one by one for the two tables

for ($y = 0; $y < $no_of_iterations; $y++) {

tep_db_query("delete from " . TABLE_CUSTOMERS_BASKET . " where customers_id = '" . (int)$customer_id . "' and (products_id = '" . (int)$products_to_delete_from_cb[$y] . "' or products_id REGEXP '^" . (int)$products_to_delete_from_cb[$y] . "{');");

tep_db_query("delete from " . TABLE_CUSTOMERS_BASKET_ATTRIBUTES . " where customers_id = '" . (int)$customer_id . "' and (products_id = '" . (int)$products_to_delete_from_cb[$y] . "' or products_id REGEXP '^" . (int)$products_to_delete_from_cb[$y] . "{');");

} // end for ($y = 0; $y < $no_of_iterations; $y++)

} // end if (tep_not_null($products_to_delete_from_cb))

} // end if ($no_of_products_in_basket > 0)

// EOF SPPC hide products and categories from groups

 

$this->cleanup();

}

 

function reset($reset_database = false) {

global $customer_id;

 

$this->contents = array();

$this->total = 0;

$this->weight = 0;

$this->content_type = false;

 

if (tep_session_is_registered('customer_id') && ($reset_database == true)) {

tep_db_query("delete from " . TABLE_CUSTOMERS_BASKET . " where customers_id = '" . (int)$customer_id . "'");

tep_db_query("delete from " . TABLE_CUSTOMERS_BASKET_ATTRIBUTES . " where customers_id = '" . (int)$customer_id . "'");

}

 

unset($this->cartID);

if (tep_session_is_registered('cartID')) tep_session_unregister('cartID');

}

 

function add_cart($products_id, $qty = '1', $attributes = '', $notify = true) {

// BOF Separate Pricing Per Customer

global $new_products_id_in_cart, $customer_id, $sppc_customer_group_id;

 

if(!tep_session_is_registered('sppc_customer_group_id')) {

$this->cg_id = '0';

} else {

$this->cg_id = $sppc_customer_group_id;

}

// EOF Separate Pricing Per Customer

 

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

$products_id = tep_get_prid($products_id_string);

 

$attributes_pass_check = true;

 

if (is_array($attributes)) {

reset($attributes);

while (list($option, $value) = each($attributes)) {

if (!is_numeric($option) || !is_numeric($value)) {

$attributes_pass_check = false;

break;

}

}

}

 

if (is_numeric($products_id) && is_numeric($qty) && ($attributes_pass_check == true)) {

// BOF SPPC attribute hide check, original query expanded to include attributes

$check_product_query = tep_db_query("select products_status, options_id, options_values_id, attributes_hide_from_groups, '0' as hide_attr_status from " . TABLE_PRODUCTS . " p left join " . TABLE_PRODUCTS_ATTRIBUTES . " using(products_id) where p.products_id = '" . (int)$products_id . "'");

while ($_check_product = tep_db_fetch_array($check_product_query)) {

$attr_hide_array = array(); // empty array in case it is still around and filled

$attr_hide_array = explode(",", $_check_product['attributes_hide_from_groups']);

if (in_array($this->cg_id, $attr_hide_array)) {

$_check_product['hide_attr_status'] = '1';

}

$check_product[] = $_check_product;

} // end while ($_check_product = tep_db_fetch_array($check_product_query))

$no_of_check_product = count($check_product);

 

if (is_array($attributes)) {

foreach($attributes as $attr_option => $attr_option_value) {

$valid_option = '0';

for ($x = 0; $x < $no_of_check_product; $x++) {

if ($attr_option == $check_product[$x]['options_id'] && $attr_option_value == $check_product[$x]['options_values_id']) {

$valid_option = '1';

if ($check_product[$x]['hide_attr_status'] == '1') {

// delete hidden attributes from array attributes

unset($attributes[$attr_option]);

}

} // end if ($attr_option == $check_product[$x]['options_id']....

} // end for ($x = 0; $x < $no_of_check_product; $x++)

if ($valid_option == '0') {

// after having gone through the options for this product and not having found a matching one

// we can conclude that apparently this is not a valid option for this product so remove it

unset($attributes[$attr_option]);

}

} // end foreach($attributes as $attr_option => $attr_option_value)

} // end if (is_array($attributes))

// now attributes have been checked and hidden and invalid ones deleted make the $products_id_string again

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

 

if ((isset($check_product) && tep_not_null($check_product)) && ($check_product[0]['products_status'] == '1')) {

// EOF SPPC attribute hide check

if ($notify == true) {

$new_products_id_in_cart = $products_id;

tep_session_register('new_products_id_in_cart');

}

 

if ($this->in_cart($products_id_string)) {

$this->update_quantity($products_id_string, $qty, $attributes);

} else {

$this->contents[$products_id_string] = array('qty' => $qty);

// insert into database

if (tep_session_is_registered('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_string) . "', '" . (int)$qty . "', '" . date('Ymd') . "')");

 

if (is_array($attributes)) {

reset($attributes);

while (list($option, $value) = each($attributes)) {

$this->contents[$products_id_string]['attributes'][$option] = $value;

// insert into database

if (tep_session_is_registered('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_string) . "', '" . (int)$option . "', '" . (int)$value . "')");

}

}

}

 

$this->cleanup();

 

// assign a temporary unique ID to the order contents to prevent hack attempts during the checkout procedure

$this->cartID = $this->generate_cart_id();

}

}

}

 

function update_quantity($products_id, $quantity = '', $attributes = '') {

global $customer_id;

 

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

$products_id = tep_get_prid($products_id_string);

 

if (is_numeric($products_id) && isset($this->contents[$products_id_string]) && is_numeric($quantity)) {

$this->contents[$products_id_string] = array('qty' => $quantity);

// update database

if (tep_session_is_registered('customer_id')) tep_db_query("update " . TABLE_CUSTOMERS_BASKET . " set customers_basket_quantity = '" . (int)$quantity . "' where customers_id = '" . (int)$customer_id . "' and products_id = '" . tep_db_input($products_id_string) . "'");

 

if (is_array($attributes)) {

reset($attributes);

while (list($option, $value) = each($attributes)) {

$this->contents[$products_id_string]['attributes'][$option] = $value;

// update database

if (tep_session_is_registered('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_string) . "' 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 (tep_session_is_registered('customer_id')) {

tep_db_query("delete from " . TABLE_CUSTOMERS_BASKET . " where customers_id = '" . (int)$customer_id . "' and products_id = '" . tep_db_input($key) . "'");

tep_db_query("delete from " . TABLE_CUSTOMERS_BASKET_ATTRIBUTES . " where customers_id = '" . (int)$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 (isset($this->contents[$products_id])) {

return $this->contents[$products_id]['qty'];

} else {

return 0;

}

}

 

function in_cart($products_id) {

if (isset($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 (tep_session_is_registered('customer_id')) {

tep_db_query("delete from " . TABLE_CUSTOMERS_BASKET . " where customers_id = '" . (int)$customer_id . "' and products_id = '" . tep_db_input($products_id) . "'");

tep_db_query("delete from " . TABLE_CUSTOMERS_BASKET_ATTRIBUTES . " where customers_id = '" . (int)$customer_id . "' and products_id = '" . tep_db_input($products_id) . "'");

}

 

// assign a temporary unique ID to the order contents to prevent hack attempts during the checkout procedure

$this->cartID = $this->generate_cart_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'];

// BOF Separate Pricing Per Customer

// global variable (session) $sppc_customer_group_id -> class variable cg_id

global $sppc_customer_group_id;

 

if(!tep_session_is_registered('sppc_customer_group_id')) {

$this->cg_id = '0';

} else {

$this->cg_id = $sppc_customer_group_id;

}

// EOF Separate Pricing Per Customer

 

// 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)$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'];

 

// BOF Separate Pricing Per Customer

$specials_price = tep_get_products_special_price((int)$prid);

if (tep_not_null($specials_price)) {

$products_price = $specials_price;

} elseif ($this->cg_id != 0){

$customer_group_price_query = tep_db_query("select customers_group_price from " . TABLE_PRODUCTS_GROUPS . " where products_id = '" . (int)$prid . "' and customers_group_id = '" . $this->cg_id . "'");

if ($customer_group_price = tep_db_fetch_array($customer_group_price_query)) {

$products_price = $customer_group_price['customers_group_price'];

}

}

// EOF Separate Pricing Per Customer

 

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

$this->weight += ($qty * $products_weight);

}

 

// attributes price

// BOF SPPC attributes mod

if (isset($this->contents[$products_id]['attributes'])) {

reset($this->contents[$products_id]['attributes']);

$where = " AND ((";

while (list($option, $value) = each($this->contents[$products_id]['attributes'])) {

$where .= "options_id = '" . (int)$option . "' AND options_values_id = '" . (int)$value . "') OR (";

}

$where=substr($where, 0, -5) . ')';

 

$attribute_price_query = tep_db_query("SELECT products_attributes_id, options_values_price, price_prefix FROM " . TABLE_PRODUCTS_ATTRIBUTES . " WHERE products_id = '" . (int)$products_id . "'" . $where ."");

 

if (tep_db_num_rows($attribute_price_query)) {

$list_of_prdcts_attributes_id = '';

// empty array $attribute_price

$attribute_price = array();

while ($attributes_price_array = tep_db_fetch_array($attribute_price_query)) {

$attribute_price[] = $attributes_price_array;

$list_of_prdcts_attributes_id .= $attributes_price_array['products_attributes_id'].",";

}

if (tep_not_null($list_of_prdcts_attributes_id) && $this->cg_id != '0') {

$select_list_of_prdcts_attributes_ids = "(" . substr($list_of_prdcts_attributes_id, 0 , -1) . ")";

$pag_query = tep_db_query("select products_attributes_id, options_values_price, price_prefix from " . TABLE_PRODUCTS_ATTRIBUTES_GROUPS . " where products_attributes_id IN " . $select_list_of_prdcts_attributes_ids . " AND customers_group_id = '" . $this->cg_id . "'");

while ($pag_array = tep_db_fetch_array($pag_query)) {

$cg_attr_prices[] = $pag_array;

}

 

// substitute options_values_price and prefix for those for the customer group (if available)

if ($customer_group_id != '0' && tep_not_null($cg_attr_prices)) {

for ($n = 0; $n < count($attribute_price); $n++) {

for ($i = 0; $i < count($cg_attr_prices); $i++) {

if ($cg_attr_prices[$i]['products_attributes_id'] == $attribute_price[$n]['products_attributes_id']) {

$attribute_price[$n]['price_prefix'] = $cg_attr_prices[$i]['price_prefix'];

$attribute_price[$n]['options_values_price'] = $cg_attr_prices[$i]['options_values_price'];

}

} // end for ($i = 0; $i < count($cg_att_prices); $i++)

}

} // end if ($customer_group_id != '0' && (tep_not_null($cg_attr_prices))

} // end if (tep_not_null($list_of_prdcts_attributes_id) && $customer_group_id != '0')

// now loop through array $attribute_price to add up/substract attribute prices

 

for ($n = 0; $n < count($attribute_price); $n++) {

if ($attribute_price[$n]['price_prefix'] == '+') {

$this->total += $qty * tep_add_tax($attribute_price[$n]['options_values_price'], $products_tax);

} else {

$this->total -= $qty * tep_add_tax($attribute_price[$n]['options_values_price'], $products_tax);

}

} // end for ($n = 0; $n < count($attribute_price); $n++)

} // end if (tep_db_num_rows($attribute_price_query))

} // end if (isset($this->contents[$products_id]['attributes']))

}

}

// EOF SPPC attributes mod

 

// function attributes_price changed partially according to FalseDawn's post

// http://www.oscommerce.com/forums/index.php?showtopic=139587

// changed completely for Separate Pricing Per Customer, attributes mod

function attributes_price($products_id) {

// global variable (session) $sppc_customer_group_id -> class variable cg_id

global $sppc_customer_group_id;

 

if(!tep_session_is_registered('sppc_customer_group_id')) {

$this->cg_id = '0';

} else {

$this->cg_id = $sppc_customer_group_id;

}

if (isset($this->contents[$products_id]['attributes'])) {

reset($this->contents[$products_id]['attributes']);

$where = " AND ((";

while (list($option, $value) = each($this->contents[$products_id]['attributes'])) {

$where .= "options_id = '" . (int)$option . "' AND options_values_id = '" . (int)$value . "') OR (";

}

$where=substr($where, 0, -5) . ')';

 

$attribute_price_query = tep_db_query("SELECT products_attributes_id, options_values_price, price_prefix FROM " . TABLE_PRODUCTS_ATTRIBUTES . " WHERE products_id = '" . (int)$products_id . "'" . $where ."");

 

if (tep_db_num_rows($attribute_price_query)) {

$list_of_prdcts_attributes_id = '';

while ($attributes_price_array = tep_db_fetch_array($attribute_price_query)) {

$attribute_price[] = $attributes_price_array;

$list_of_prdcts_attributes_id .= $attributes_price_array['products_attributes_id'].",";

}

 

if (tep_not_null($list_of_prdcts_attributes_id) && $this->cg_id != '0') {

$select_list_of_prdcts_attributes_ids = "(" . substr($list_of_prdcts_attributes_id, 0 , -1) . ")";

$pag_query = tep_db_query("select products_attributes_id, options_values_price, price_prefix from " . TABLE_PRODUCTS_ATTRIBUTES_GROUPS . " where products_attributes_id IN " . $select_list_of_prdcts_attributes_ids . " AND customers_group_id = '" . $this->cg_id . "'");

while ($pag_array = tep_db_fetch_array($pag_query)) {

$cg_attr_prices[] = $pag_array;

}

 

// substitute options_values_price and prefix for those for the customer group (if available)

if ($customer_group_id != '0' && tep_not_null($cg_attr_prices)) {

for ($n = 0; $n < count($attribute_price); $n++) {

for ($i = 0; $i < count($cg_attr_prices); $i++) {

if ($cg_attr_prices[$i]['products_attributes_id'] == $attribute_price[$n]['products_attributes_id']) {

$attribute_price[$n]['price_prefix'] = $cg_attr_prices[$i]['price_prefix'];

$attribute_price[$n]['options_values_price'] = $cg_attr_prices[$i]['options_values_price'];

}

} // end for ($i = 0; $i < count($cg_att_prices); $i++)

}

} // end if ($customer_group_id != '0' && (tep_not_null($cg_attr_prices))

} // end if (tep_not_null($list_of_prdcts_attributes_id) && $customer_group_id != '0')

// now loop through array $attribute_price to add up/substract attribute prices

 

for ($n = 0; $n < count($attribute_price); $n++) {

if ($attribute_price[$n]['price_prefix'] == '+') {

$attributes_price += $attribute_price[$n]['options_values_price'];

} else {

$attributes_price -= $attribute_price[$n]['options_values_price'];

}

} // end for ($n = 0; $n < count($attribute_price); $n++)

return $attributes_price;

} else { // end if (tep_db_num_rows($attribute_price_query))

return 0;

}

} else { // end if (isset($this->contents[$products_id]['attributes']))

return 0;

}

} // end of function attributes_price, modified for SPPC with attributes

 

function get_products() {

global $languages_id;

// BOF Separate Pricing Per Customer

// global variable (session) $sppc_customer_group_id -> class variable cg_id

global $sppc_customer_group_id;

 

if(!tep_session_is_registered('sppc_customer_group_id')) {

$this->cg_id = '0';

} else {

$this->cg_id = $sppc_customer_group_id;

}

// EOF Separate Pricing Per Customer

if (!is_array($this->contents)) return false;

 

$products_array = array();

reset($this->contents);

while (list($products_id, ) = each($this->contents)) {

$products_query =

Link to comment
Share on other sites

Let's see if this works.
And since the function get_products() got cut off in the post (too long I guess) just that last part (which hasn't changed however).

	function get_products() {
  global $languages_id;
// BOF Separate Pricing Per Customer
// global variable (session) $sppc_customer_group_id -> class variable cg_id
 global $sppc_customer_group_id;

 if(!tep_session_is_registered('sppc_customer_group_id')) {
 $this->cg_id = '0';
 } else {
  $this->cg_id = $sppc_customer_group_id;
 }
// EOF Separate Pricing Per Customer
  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_image, p.products_price, p.products_weight, p.products_tax_class_id from " . TABLE_PRODUCTS . " p, " . TABLE_PRODUCTS_DESCRIPTION . " pd where p.products_id = '" . (int)$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'];

// BOF Separate Pricing Per Customer
  $specials_price = tep_get_products_special_price($prid);
 if (tep_not_null($specials_price)) {
 $products_price = $specials_price;
  } elseif ($this->cg_id != 0){
	$customer_group_price_query = tep_db_query("select customers_group_price from " . TABLE_PRODUCTS_GROUPS . " where products_id = '" . (int)$prid . "' and customers_group_id =  '" . $this->cg_id . "'");
	if ($customer_group_price = tep_db_fetch_array($customer_group_price_query)) {
	$products_price = $customer_group_price['customers_group_price'];
	}
 }
// EOF Separate Pricing Per Customer

	  $products_array[] = array('id' => $products_id,
								'name' => $products['products_name'],
								'model' => $products['products_model'],
								'image' => $products['products_image'],
								'price' => $products_price,
								'quantity' => $this->contents[$products_id]['qty'],
								'weight' => $products['products_weight'],
								'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;
}

Link to comment
Share on other sites

Almost there!

I'll try to illustrate...

I put three different packs of colored magnets in my cart, a white that is hidden at attribute level, a green that costs a little more for this customer group and a red just for reference.

I also put in another product that is hidden for this particular customer group on a product level.

I log in and here's the cart:

cart.jpg

That other product is now cleaned out of the cart when I log in and so that feature is back again!

The price is adjusted according to the customer group attribute level pricing on the Green magnets.

However, the white magnet is still there (apart from it's attribute sting "- Color White").

 

Tickin' the remove checkbox and updating the cart removes it of course...

(If the customer will not I can remove it with the order editor later...)

So I'm incorporating this now!

 

//Micke

Link to comment
Share on other sites

Almost there!

I'll try to illustrate...

I put three different packs of colored magnets in my cart, a white that is hidden at attribute level, a green that costs a little more for this customer group and a red just for reference.

I also put in another product that is hidden for this particular customer group on a product level.

 

That other product is now cleaned out of the cart when I log in and so that feature is back again!

The price is adjusted according to the customer group attribute level pricing on the Green magnets.

However, the white magnet is still there (apart from it's attribute sting "- Color White").

OK, it is working as coded then. The trouble with the white magnet is part of the bigger attribute problem of osC. For you the product is the white magnet, but osC treats it as a magnet with something added. Therefore, the stock problems with products with attributes (Quantity Pro is the contribution that deals with that I think).

 

This is an example of the same kind of problem. To get around that you would need some system in which you store what to do in such a case: drop the product completely or replace the hidden attribute with some sort of default attribute.

 

So all in all this feature is mostly useful for hiding attributes from retail customers or products that are also products without the hidden attribute (something like gift wrapping for example).

Link to comment
Share on other sites

Hi,

 

I have merged SPPC, Hide products from customer groups for SPPC and Hide products and categories. Now I would like to know a (bullet)proof way on how to test the application, that is: a certain Input produces a certain Output.

 

 

To: Micke

Glad that you got everything sorted out, Micke! Curious as I am, I looked at your site, www.audicom.com. I liked the way you have configured your contact_us.php page. Would you mind tell me which contributions, if any, you have used, I am in particular reffering to the Google-maps over Malmoe, Gothenburg and Stockholm. Also of interest are the radiobuttons and dropdowns that you have in there.

 

TIA

Link to comment
Share on other sites

Would you mind tell me which contributions, if any, you have used, I am in particular reffering to the Google-maps over Malmoe, Gothenburg and Stockholm. Also of interest are the radiobuttons and dropdowns that you have in there.
I have sent you a personal message about this as it's off topic, I think....
Link to comment
Share on other sites

SPPC and Safe Urls

 

Problem when using Search Engine Safe Urls (Admin > Store Configuration)

 

I have been working with SPPC and all was well with a couple of test installs..

 

Then I started having problems logging in as the admin user, ie the one that gets to select from the the Price Groups at login and as defined in the 'SPPC_TOGGLE_LOGIN_PASSWORD' in the catalog\includes\languages\english\login.php file.

 

It turns out that having the SEO Safe Urls turned on, will stop the defined user logging in

 

Symptoms:

Auth user gets the Select Customer Group login dialog form but is always returned to that form on submit.

(Also noted that on IE the submit button image is missing in that form)

 

Fix: Turn OFF Search Engine Safe Urls!

Link to comment
Share on other sites

It turns out that having the SEO Safe Urls turned on, will stop the defined user logging in

 

Symptoms:

Auth user gets the Select Customer Group login dialog form but is always returned to that form on submit.

(Also noted that on IE the submit button image is missing in that form)

 

Fix: Turn OFF Search Engine Safe Urls!

True, but there is a work-around. As far as I know you shouldn't use the standard osC SEO Safe Url's. I believe there is some issue with it. There is a contribution for it though, by Chemo.
Link to comment
Share on other sites

HI,

 

 

Just installed this contribs and i have the same problem as this old message

 

Warning: array_merge() [function.array-merge]: Argument #1 is not an array in D:\web\xampp\htdocs\store\admin\customers.php on line 1064

 

Warning: array_merge() [function.array-merge]: Argument #2 is not an array in D:\web\xampp\htdocs\store\admin\customers.php on line 1064

 

Warning: array_merge() [function.array-merge]: Argument #2 is not an array in D:\web\xampp\htdocs\store\admin\customers.php on line 1066

 

Warning: reset() [function.reset]: Passed variable is not an array or object in D:\web\xampp\htdocs\store\admin\includes\classes\object_info.php on line 17

 

Warning: Variable passed to each() is not an array or object in D:\web\xampp\htdocs\store\admin\includes\classes\object_info.php on line 18

 

with php5.1.6 and mysql 5.0.24a.

 

Has someone the same, any ideas?

 

 

 

thanks

 

 

PLdtm

PL DTM

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

Sur un malentendu, ... ?a pourrait marcher

Link to comment
Share on other sites

Just installed this contribs and i have the same problem as this old message

with php5.1.6 and mysql 5.0.24a.

Looks like the query for the country name didn't yield any result:

		$country_query = tep_db_query("select countries_name from " . TABLE_COUNTRIES . " where countries_id = '" . (int)$customers['entry_country_id'] . "'");
	$country = tep_db_fetch_array($country_query);

	$reviews_query = tep_db_query("select count(*) as number_of_reviews from " . TABLE_REVIEWS . " where customers_id = '" . (int)$customers['customers_id'] . "'");
	$reviews = tep_db_fetch_array($reviews_query);

	$customer_info = array_merge($country, $info, $reviews); // line 1064

	$cInfo_array = array_merge($customers, $customer_info);

Could it be that you changed osC to only handle one country and removed code? Or perhaps this is just one customer that throws that error?

Link to comment
Share on other sites

hi JAN,

 

when i create a customer in admin with (step by step order 1.8) no problem but when i'm on the catalog side and i create an account it bugs. Ithink i didn't change any code, just added anti robot validation contrib, ccgv trad and sppc.

and ultimate seo url but i think this last one doesn't change any code in this file.

 

and i added one langage and french zone but didn't deleted any country. I'll try with an "out of the box file" to see if it works or not. because i have no other idea.

 

thanks

PL DTM

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

Sur un malentendu, ... ?a pourrait marcher

Link to comment
Share on other sites

Janz, could you help please?

 

It only that, in specials.php I also need to appear a short bit if the description of the product.

 

 

With this code, name and price appears correctly, but not the description :(

 

 

Thankx!

 

		<td bgcolor=#F2EEE5 width=250 valign=top align=center>
	 <table cellspacing=0 cellpadding=0 width=230>
	  <tr><td height=12></td></tr>
	  <tr>
	  <td width=78 valign=top><a href="' . tep_href_link(FILENAME_PRODUCT_INFO, 'products_id=' . $specials[$x]['products_id']) . '">' . tep_image(DIR_WS_IMAGES . $specials[$x]['products_image'], $specials[$x]['products_name'], SMALL_IMAGE_WIDTH, SMALL_IMAGE_HEIGHT) . '</a></td>
	  <td width=10></td>
	   <td width=140 valign=top>
	   <table cellspacing=0 cellpadding=0 width=140>
				   <tr><td height=55 valign=middle><a class=ml5  href="' . tep_href_link(FILENAME_PRODUCT_INFO, 'products_id=' . $specials[$x]['products_id']) . '">' . $specials[$x]['products_name'] . '</a></td></tr>
		<tr><td class=ch8><a class=ch8  href="' . tep_href_link(FILENAME_PRODUCT_INFO, ($cPath ? 'cPath=' . $cPath . '&' : '') . 'products_id=' . $specials['products_id']) . '">Model ID# ' . $specials['products_id'] . '</a></td></tr>
		<tr><td height=5></td></tr>
		<tr><td class=ch9 height=30 valign=middle><li><u>'.preg_replace('/\s\S*$/i', '', substr($new_products['products_description'], 0, 45)).' ...</u></li></td></tr>
		<tr><td class=ch10 height=40 valign=middle>    <s class=ch10 style="color:#7F7F7F;font-size:11px">'.$currencies->display_price($specials[$x]['products_price'], tep_get_tax_rate($specials[$x]['products_tax_class_id'])) . '</s><br><span class=ch10>' . $currencies->display_price($specials[$x]['specials_new_products_price'], tep_get_tax_rate($specials[$x]['products_tax_class_id'])) . '</span></td></tr>
		<tr><td height=5></td></tr>
		<tr><td><a href="' . tep_href_link(FILENAME_PRODUCT_INFO, 'products_id=' . $specials['products_id']) . '">' . tep_image_button('small_view.gif') . '</a> <a href="' . tep_href_link(basename($PHP_SELF), tep_get_all_get_params(array('action')) . 'action=buy_now&products_id=' . $specials['products_id']) . '">' . tep_image_button('button_in_cart.gif') . '</a></td></tr>
		<tr><td height=2></td></tr>
	   </table>  
	  </td>
	  </tr>
	 </table>
	</td>

Link to comment
Share on other sites

It only that, in specials.php I also need to appear a short bit if the description of the product.

With this code, name and price appears correctly, but not the description.

It looks like you copied this piece of code from somewhere else, where the array with database results was called new_products. Try specials instead (and add the [$x], also with the Model ID#:

		<td bgcolor=#F2EEE5 width=250 valign=top align=center>
	 <table cellspacing=0 cellpadding=0 width=230>
	  <tr><td height=12></td></tr>
	  <tr>
	  <td width=78 valign=top><a href="' . tep_href_link(FILENAME_PRODUCT_INFO, 'products_id=' . $specials[$x]['products_id']) . '">' . tep_image(DIR_WS_IMAGES . $specials[$x]['products_image'], $specials[$x]['products_name'], SMALL_IMAGE_WIDTH, SMALL_IMAGE_HEIGHT) . '</a></td>
	  <td width=10></td>
	   <td width=140 valign=top>
	   <table cellspacing=0 cellpadding=0 width=140>
				   <tr><td height=55 valign=middle><a class=ml5  href="' . tep_href_link(FILENAME_PRODUCT_INFO, 'products_id=' . $specials[$x]['products_id']) . '">' . $specials[$x]['products_name'] . '</a></td></tr>
		<tr><td class=ch8><a class=ch8  href="' . tep_href_link(FILENAME_PRODUCT_INFO, ($cPath ? 'cPath=' . $cPath . '&' : '') . 'products_id=' . $specials[$x]['products_id']) . '">Model ID# ' . $specials[$x]['products_id'] . '</a></td></tr>
		<tr><td height=5></td></tr>
		<tr><td class=ch9 height=30 valign=middle><li><u>'.preg_replace('/\s\S*$/i', '', substr($specials[$x]['products_description'], 0, 45)).' ...</u></li></td></tr>

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...