New Zenner
- Join Date:
- Jun 2014
- Location:
- Suffolk, England
- Posts:
- 23
- Plugin Contributions:
- 0
Buy selection of items for offer price
Hi,
I am developing a function allowing customers to buy a selection of items for an offer price but I am having trouble when trying to apply it to multiple products with the same offer as the second item seems to be ignored.
Any help or advice would be appreciated.
Please find the code so far:
<?php
class offerprice extends base {
var $offersAllowed ;
var $offerlimit;
function offerprice() {
global $zco_notifier;
$_SESSION['cart']->attach($this, array('NOTIFIER_CART_SHOW_TOTAL_END'));
$zco_notifier->attach($this, array('NOTIFIER_COUPON_SUCCESSFULLY_ADDED'));
}
function update(&$class, $eventID) {
global $order;
$cost_saving = 0;
$multiple = 0;
$products = $_SESSION['cart']->get_products();
global $db;
$sql = "select products_id, products_price, products_offer_price, products_offer_quantity
from " . TABLE_PRODUCTS . "
where products_offer_price > 0
and products_offer_quantity > 0
and (products_offer_date_from IS NULL OR DATE(products_offer_date_from) <= DATE(NOW()) )
and (products_offer_date_to IS NULL OR DATE(products_offer_date_to) >= DATE(NOW()) )";
$products_list = $db->Execute($sql);
while (!$products_list->EOF) {
$mysql_id = $products_list->fields['products_id'];
$mysql_price = $products_list->fields['products_price'];
$mysql_offer_price = $products_list->fields['products_offer_price'];
$mysql_offer_quantity = $products_list->fields['products_offer_quantity'];
$this->offerpriceArray[]= array('products_id' => $products_list->fields['products_id'],
'products_price' => $products_list->fields['products_price'],
'products_offer_price' => $products_list->fields['products_offer_price'],
'products_offer_quantity' => $products_list->fields['products_offer_quantity']);
$products_list->MoveNext();
}
$cost_minimize = 0;
$cost_minimize_agg = 0;
$offerItem = $this->offerpriceArray;
for($i=0; $i < sizeof($offerItem); $i++ ) {
if ($_SESSION['cart']->in_cart($offerItem[$i]['products_id']) && $id != $offerItem[$i]['products_id']) {
if ((isset($_SESSION['cart']->contents[$offerItem[$i]['products_id']]['qty']) && $_SESSION['cart']->contents[$offerItem[$i]['products_id']]['qty'] >= 1)) {
$id = $offerItem[$i]['products_id'];
$offerItem[$i]['qty'] = $_SESSION['cart']->contents[$offerItem[$i]['products_id']]['qty'];
$price = $offerItem[$i]['products_price'];
$offer_price = $offerItem[$i]['products_offer_price'];
$quantity = $offerItem[$i]['products_offer_quantity'];
$numoffers = $quantity;
$cart_quantity = $_SESSION['cart']->contents[$id]['qty'];
if ($numoffers > 0) {
/* BOF: Check Offer */
if ($_SESSION['cart']->contents[$offerItem[$i]['products_id']]['qty'] >= $quantity) {
$_SESSION['offer_id'][$i] = $id;
$offer_multiples = floor($cart_quantity / $quantity);
$offer_modulus = floor(($cart_quantity % $quantity));
$offered_quantity = $offer_multiples * $offer_modulus;
$remaining_quantity = $price * $offer_modulus;
$total_price = $price * $cart_quantity;
$offer_total_price = $offer_price * $offer_multiples;
$offer_price_final = $offer_total_price + $remaining_quantity;
//$final_price_vat = zen_add_tax($products[$j]['final_price'], zen_get_tax_rate($products[$j]['tax_class_id']));
//$cost_minimize_agg += $total_price;
echo "<p>Offer Multiples: ".$offer_multiples."<br />";
echo "ID: ".$id."<br />";
echo "Price: ".$price."<br />";
echo "Cart Quantity: " .$cart_quantity."<br />";
echo "Offer Quantity: " .$quantity."<br />";
echo "Offer Price: ".$offer_price."<br />";
echo "Total Price: ".$total_price."<br />";
echo "Modulus: ".$offer_modulus."<br />";
echo "Offer Total Price: ".$offer_total_price."<br />";
echo "Offer Price Final: ".$offer_price_final."</p>";
echo "<p> Cart Session<br />";
$total_price_vat = zen_add_tax($total_price, zen_get_tax_rate(1));
$offer_price_final_vat = zen_add_tax($offer_price_final, zen_get_tax_rate(1));
echo "Cart Total minus Total Price: ";
echo $_SESSION['cart']->total -= $total_price_vat;
echo "<br />Cart Total plus Offer Total Price: ";
echo $_SESSION['cart']->total += $offer_price_final_vat;
echo "</p>";
/*
$total_price_vat = zen_add_tax($total_price, zen_get_tax_rate(1));
$offer_price_final_vat = zen_add_tax($offer_price_final, zen_get_tax_rate(1));
$_SESSION['cart']->total -= $total_price_vat;
$_SESSION['cart']->total += $offer_price_final_vat;
*/
}
/* EOF: Check Offer */
}
}
}
////////////////
}
}
}
?>