Every one:
I want to add some products(fittings) below shopping_cart.php page ,when the customers have a products in cart,and then if he also add a fittings into the cart,then the fitting get 20%(or other) discount,
if he only buy the fittings ,the price is full price(no discount at all).
I add "if "(red part) into shopping_cart class ,it also normal,but i have judge all in card product subset of fittings,it no any discount,how to calculate?
function calculate() {
global $languages_id;// Eversun mod for SPPP Qty Price Break Enhancement
$this->total_virtual = 0; // ICW Gift Voucher System
$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'];
$pf = new PriceFormatter;
// 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 = $pf->loadProduct($products_id, $languages_id)) {
// ICW ORDER TOTAL CREDIT CLASS Start Amendment
$no_count = 1;
$gv_query = tep_db_query("select products_model from " . TABLE_PRODUCTS . " where products_id = '" . (int)$products_id . "'");
$gv_result = tep_db_fetch_array($gv_query);
if (ereg('^GIFT', $gv_result['products_model'])) {
$no_count = 0;
}
// ICW ORDER TOTAL CREDIT CLASS End Amendment
$prid = $product['products_id'];
$products_tax = tep_get_tax_rate($product['products_tax_class_id']);
// Eversun mod end for sppc and qty price breaks
//$products_price = $product['products_price'];
$products_price = $pf->computePrice($qty);
$products_weight = $product['products_weight'];
$extra_products=array(84,758); //fittings id setif(in_array($prid,$extra_products) && !array_unique($this->get_all_in_cart_products_array()+$extra_products)===$extra_products ){
//array_unique($this->get_all_in_cart_products_array()+$extra_products)===$extra_products juade all incard product is subset of $extra_products.
$products_price=$products_price*0.8;
}
$special_price = tep_get_products_special_price($prid);
}
$special_price = tep_get_products_special_price($prid);
if ($special_price) {
$products_price = $special_price;
}
$this->total_virtual += tep_add_tax($products_price, $products_tax) * $qty * $no_count;// ICW CREDIT CLASS;
$this->weight_virtual += ($qty * $products_weight) * $no_count;// ICW CREDIT CLASS;
$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'])) {
// BOM - Options Catagories
/*
$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);
}
*/
if ( !is_array($value) ) {
$attribute_price_query = tep_db_query("select options_values_price as 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['price'], $products_tax);
} else {
$this->total -= $qty * tep_add_tax($attribute_price['price'], $products_tax);
}
} elseif ( isset($value['t']) ) {
$attribute_price_query = tep_db_query("select options_values_price as price, price_prefix from " . TABLE_PRODUCTS_ATTRIBUTES . " where products_id = '" . (int)$products_id . "' and options_id = '" . (int)$option . "' and options_values_id = '0'");
$attribute_price = tep_db_fetch_array($attribute_price_query);
if ($attribute_price['price_prefix'] == '+') {
$this->total += $qty * tep_add_tax($attribute_price['price'], $products_tax);
} else {
$this->total -= $qty * tep_add_tax($attribute_price['price'], $products_tax);
}
} elseif ( isset($value['c']) ) {
foreach ( $value['c'] as $v ) {
$attribute_price_query = tep_db_query("select options_values_price as price, price_prefix from " . TABLE_PRODUCTS_ATTRIBUTES . " where products_id = '" . (int)$products_id . "' and options_id = '" . (int)$option . "' and options_values_id = '" . (int)$v . "'");
$attribute_price = tep_db_fetch_array($attribute_price_query);
if ($attribute_price['price_prefix'] == '+') {
$this->total += $qty * tep_add_tax($attribute_price['price'], $products_tax);
} else {
$this->total -= $qty * tep_add_tax($attribute_price['price'], $products_tax);
}
}
}
// EOM - Options Catagories
}
}
}
}














