Exemplo n.º 1
0
    $_SESSION['total_price'] = calculate_price($_SESSION['cart']);
    //tính tổng thành tiền của xe hàng
}
if (isset($_POST['save'])) {
    //Duyệt giỏ hàng
    foreach ($_SESSION['cart'] as $isbn => $qty) {
        // qty tổng số lượng
        if ($_POST[$isbn] == 0) {
            // Nếu isbn là 0 thì loại bỏ cuốn sách ra khỏi giỏ hàng
            unset($_SESSION['cart'][$isbn]);
        } else {
            $_SESSION['cart'][$isbn] = $_POST[$isbn];
        }
        // Cập nhật số lượng mới
    }
    $_SESSION['total_price'] = calculate_price($_SESSION['cart']);
    $_SESSION['items'] = calculate_items($_SESSION['cart']);
}
?>

<?php 
/*echo "<pre>";
	// print_r($_SESSION);
	echo "</pre>";*/
// Tiếp bài học 19.11.2015
if ($_SESSION['cart']) {
    display_cart($_SESSION['cart']);
} else {
    echo "<p>Giỏ hàng rỗng</p>";
    echo "<hr>";
}
 function eshop_cart_process($data = '')
 {
     global $wpdb, $blog_id, $wp_query, $eshopoptions, $_POST;
     if ($data != '') {
         $_POST = $data;
     }
     if (!isset($_POST['eshopnon'])) {
         return;
     }
     wp_verify_nonce('eshop_add_product_cart');
     unset($_POST['eshopnon']);
     //setup variables:
     $option = $qty = $pclas = $productid = $pid = $pname = $iprice = '';
     $echo = '';
     //cache
     eshop_cache();
     //delete the session, empties the cart
     if (isset($_POST['unset']) || calculate_items() == 0 && isset($_SESSION['eshopcart' . $blog_id]) && sizeof($_SESSION['eshopcart' . $blog_id]) > 0) {
         unset($_SESSION['eshopcart' . $blog_id]);
         unset($_SESSION['final_price' . $blog_id]);
         unset($_SESSION['items' . $blog_id]);
         $_POST['save'] = 'false';
     }
     if (isset($eshopoptions['min_qty']) && $eshopoptions['min_qty'] != '') {
         $min = $eshopoptions['min_qty'];
     }
     if (isset($eshopoptions['max_qty']) && $eshopoptions['max_qty'] != '') {
         $max = $eshopoptions['max_qty'];
     }
     if (!isset($_POST['save'])) {
         //on windows this check isn't working correctly, so I've added ==0
         if (get_magic_quotes_gpc()) {
             $_COOKIE = stripslashes_array($_COOKIE);
             $_FILES = stripslashes_array($_FILES);
             $_GET = stripslashes_array($_GET);
             $_POST = stripslashes_array($_POST);
             $_REQUEST = stripslashes_array($_REQUEST);
         }
         $_POST = sanitise_array($_POST);
         //if adding a product to the cart
         if (isset($_POST['qty']) && !isset($_POST['save']) && (!is_numeric(trim($_POST['qty'])) || strlen($_POST['qty']) > 3)) {
             $qty = $_POST['qty'] = 1;
             $v = '999';
             if (isset($max)) {
                 $v = $max;
             }
             $error = '<p><strong class="eshoperror error">' . sprintf(__('Error: The quantity must contain numbers only, with a maximum of %s.', 'eshop'), $v) . '</strong></p>';
         }
         if (isset($min) && isset($_POST['qty']) && $_POST['qty'] < $min) {
             $qty = $_POST['qty'] = $min;
             $v = '999';
             if (isset($max)) {
                 $v = $max;
             }
             $k = $min;
             $enote = '<p><strong class="eshoperror error">' . sprintf(__('Warning: The quantity must equal or be greater than %s, with a maximum of %s.', 'eshop'), $k, $v) . '</strong></p>';
         }
         if (isset($max) && isset($_POST['qty']) && $_POST['qty'] > $max) {
             $qty = $_POST['qty'] = $max;
             $v = $max;
             $k = 1;
             if (isset($min)) {
                 $k = $min;
             }
             $enote = '<p><strong class="eshoperror error">' . sprintf(__('Warning: The quantity must equal or be greater than %s, with a maximum of %s.', 'eshop'), $k, $v) . '</strong></p>';
         }
         if (isset($_POST['postid'])) {
             $stkav = get_post_meta($_POST['postid'], '_eshop_stock', true);
             $eshop_product = maybe_unserialize(get_post_meta($_POST['postid'], '_eshop_product', true));
         }
         if (isset($_POST['option']) && !isset($_POST['save'])) {
             $edown = $getprice = $option = $_POST['option'];
             if (!isset($_POST['qty'])) {
                 $enote = '<p><strong class="eshoperror error">' . __('Warning: you must supply a quantity.', 'eshop') . '</strong></p>';
             }
             $qty = $_POST['qty'];
             $plcas = '';
             if (isset($_POST['pclas'])) {
                 $pclas = $_POST['pclas'];
             }
             $productid = $pid = $_POST['pid'];
             $pname = $_POST['pname'];
             /* if download option then it must be free shipping */
             $postid = $wpdb->escape($_POST['postid']);
             $eshop_product = maybe_unserialize(get_post_meta($postid, '_eshop_product', true));
             $dlchk = '';
             if (isset($eshop_product['products'][$option]['download'])) {
                 $dlchk = $eshop_product['products'][$option]['download'];
             }
             if ($dlchk != '') {
                 $pclas = 'F';
             }
             $iprice = $eshop_product['products'][$option]['price'];
             if (isset($eshopoptions['sale_prices']) && $eshopoptions['sale_prices'] == 1 && isset($eshopoptions['sale']) && 'yes' == $eshopoptions['sale'] && isset($eshop_product['products'][$option]['saleprice']) && $eshop_product['products'][$option]['saleprice'] != '' && isset($eshop_product['sale']) && $eshop_product['sale'] == 'yes') {
                 $iprice = $eshop_product['products'][$option]['saleprice'];
             }
             if ($iprice == '') {
                 $error = '<p><strong class="eshoperror error">' . __('Error: That product is currently not available.', 'eshop') . '</strong></p>';
                 $option = $_POST['option'] = '';
                 $qty = $_POST['qty'] = '';
                 $pclas = $_POST['pclas'] = '';
                 $productid = $pid = $_POST['pid'] = '';
                 $pname = $_POST['pname'] = '';
                 $iprice = '';
             }
         }
         //unique identifier
         $optset = '';
         if (isset($_POST['optset'])) {
             $xx = 0;
             foreach ($_POST['optset'] as $opts) {
                 $optset .= 'os' . $xx . implode('os' . $xx, $opts);
                 $xx++;
             }
         }
         if (!isset($pid)) {
             $pid = '';
         }
         if (!isset($option)) {
             $option = '';
         }
         if (!isset($postid)) {
             $postid = '';
         }
         $identifier = $pid . $option . $postid . $optset;
         //$needle=array(" ","-","$","\r","\r\n","\n","\\","&","#",";");
         $identifier = md5($identifier);
         //str_replace($needle,"",$identifier);
         $stocktable = $wpdb->prefix . "eshop_stock";
         if (isset($_SESSION['eshopcart' . $blog_id][$identifier])) {
             $testqty = $_SESSION['eshopcart' . $blog_id][$identifier]['qty'] + $qty;
             $eshopid = $_SESSION['eshopcart' . $blog_id][$identifier]['postid'];
             $eshop_product = maybe_unserialize(get_post_meta($postid, '_eshop_product', true));
             $optnum = $_SESSION['eshopcart' . $blog_id][$identifier]['option'];
             $item = $eshop_product['products'][$_SESSION['eshopcart' . $blog_id][$identifier]['option']]['option'];
             if (isset($min) && $testqty < $min) {
                 $qty = 0;
                 $v = '999';
                 if (isset($max)) {
                     $v = $max;
                 }
                 $k = $min;
                 $enote = '<p><strong class="eshoperror error">' . sprintf(__('Warning: The quantity must equal or be greater than %s, with a maximum of %s.', 'eshop'), $k, $v) . '</strong></p>';
             }
             if (isset($max) && $testqty > $max) {
                 $qty = 0;
                 $v = $max;
                 $k = 1;
                 if (isset($min)) {
                     $k = $min;
                 }
                 $enote = '<p><strong class="eshoperror error">' . sprintf(__('Warning: The quantity must equal or be greater than %s, with a maximum of %s.', 'eshop'), $k, $v) . '</strong></p>';
             }
             if ('yes' == $eshopoptions['stock_control']) {
                 $stkqty = $eshop_product['products'][$optnum]['stkqty'];
                 //recheck stkqty
                 $stktableqty = $wpdb->get_var("SELECT available FROM {$stocktable} where post_id={$eshopid} && option_id={$optnum}");
                 if (isset($stktableqty) && is_numeric($stktableqty)) {
                     $stkqty = $stktableqty;
                 }
                 if (!ctype_digit(trim($testqty)) || strlen($testqty) > 3) {
                     $error = '<p><strong class="eshoperror error">' . __('Error: The quantity must contain numbers only, with a 999 maximum.', 'eshop') . '</strong></p>';
                 } elseif ('yes' == $eshopoptions['stock_control'] && ($stkav != '1' || $stkqty < $testqty)) {
                     $error = '<p><strong class="eshoperror error">' . __('Error: That quantity is not available for that product.', 'eshop') . '</strong></p>';
                 } else {
                     $_SESSION['eshopcart' . $blog_id][$identifier]['qty'] += $qty;
                 }
             } else {
                 $_SESSION['eshopcart' . $blog_id][$identifier]['qty'] += $qty;
             }
             $_SESSION['lastproduct' . $blog_id] = $postid;
             do_action('eshop_product_updated_cart', $_SESSION['eshopcart' . $blog_id][$identifier]);
         } elseif ($identifier != '') {
             $weight = 0;
             if (isset($_POST['save']) && $_POST['save'] == 'true') {
                 $postid = $_SESSION['eshopcart' . $blog_id][$identifier]['postid'];
                 $optid = $_SESSION['eshopcart' . $blog_id][$identifier]['option'];
                 $optnum = $optid;
                 $testqty = $qty;
             } else {
                 $postid = $wpdb->escape($_POST['postid']);
                 $optid = $wpdb->escape($_POST['option']);
                 $optnum = $optid;
                 $_SESSION['eshopcart' . $blog_id][$identifier]['postid'] = $postid;
                 $testqty = $qty;
             }
             $eshop_product = maybe_unserialize(get_post_meta($postid, '_eshop_product', true));
             $item = $eshop_product['products'][$optnum]['option'];
             if ('yes' == $eshopoptions['stock_control']) {
                 $stkqty = $eshop_product['products'][$optnum]['stkqty'];
                 //recheck stkqty
                 $stktableqty = $wpdb->get_var("SELECT available FROM {$stocktable} where post_id={$postid} && option_id={$optid}");
                 if (isset($stktableqty) && is_numeric($stktableqty)) {
                     $stkqty = $stktableqty;
                 }
                 if (!ctype_digit(trim($testqty)) || strlen($testqty) > 3) {
                     $error = '<p><strong class="eshoperror error">' . __('Error: The quantity must contain numbers only, with a 999 maximum.', 'eshop') . '</strong></p>';
                 } elseif ('yes' == $eshopoptions['stock_control'] && ($stkav != '1' || $stkqty < $testqty)) {
                     $error = '<p><strong class="eshoperror error">' . __('Error: That quantity is not available for that product.', 'eshop') . '</strong></p>';
                     //$_SESSION['eshopcart'.$blog_id][$identifier]['qty']=$stkqty;
                 } else {
                     $_SESSION['eshopcart' . $blog_id][$identifier]['qty'] = $qty;
                 }
             } else {
                 $_SESSION['eshopcart' . $blog_id][$identifier]['qty'] = $qty;
             }
             $_SESSION['lastproduct' . $blog_id] = $postid;
             $_SESSION['eshopcart' . $blog_id][$identifier]['item'] = $item;
             $_SESSION['eshopcart' . $blog_id][$identifier]['option'] = stripslashes($option);
             $_SESSION['eshopcart' . $blog_id][$identifier]['pclas'] = stripslashes($pclas);
             $_SESSION['eshopcart' . $blog_id][$identifier]['pid'] = $pid;
             $_SESSION['eshopcart' . $blog_id][$identifier]['pname'] = stripslashes($pname);
             $_SESSION['eshopcart' . $blog_id][$identifier]['price'] = $iprice;
             if (isset($_POST['optset'])) {
                 foreach ($_POST['optset'] as $k => $v) {
                     $newoptset[] = $v;
                 }
                 $_SESSION['eshopcart' . $blog_id][$identifier]['optset'] = serialize($newoptset);
                 $oset = $qb = array();
                 $optings = $newoptset;
                 //$opttable=$wpdb->prefix.'eshop_option_sets';
                 foreach ($optings as $foo => $opst) {
                     $qb[] = "id={$opst['id']}";
                 }
                 $qbs = implode(" OR ", $qb);
                 $otable = $wpdb->prefix . 'eshop_option_sets';
                 $orowres = $wpdb->get_results("select weight from {$otable} where {$qbs} ORDER BY id ASC");
                 $x = 0;
                 foreach ($orowres as $orow) {
                     $weight += $orow->weight;
                     $x++;
                 }
             }
             //weights?
             if (isset($eshop_product['products'][$option]['weight'])) {
                 $weight += $eshop_product['products'][$option]['weight'];
             }
             $_SESSION['eshopcart' . $blog_id][$identifier]['weight'] = $weight;
             if (isset($error)) {
                 unset($_SESSION['eshopcart' . $blog_id][$identifier]);
             }
             do_action('eshop_product_added_to_cart', $_SESSION['eshopcart' . $blog_id][$identifier]);
         }
     }
     if (!isset($error)) {
         //save? not sure why I used that, but its working so why make trouble for myself.
         if (isset($_POST['save'])) {
             $save = $_POST['save'];
         }
         //this bit is possibly not required
         if (isset($productid)) {
             //new item selected ******* may need checking
             $_SESSION['final_price' . $blog_id] = calculate_price();
             $_SESSION['items' . $blog_id] = calculate_items();
         }
         if (isset($_POST['eshopdeleteitem'])) {
             foreach ($_POST['eshopdeleteitem'] as $chkey => $chkval) {
                 $tochkkey = $chkey;
                 $tochkqty = $_SESSION['eshopcart' . $blog_id][$chkey]['qty'];
             }
         }
         if (isset($eshopoptions['min_qty']) && $eshopoptions['min_qty'] != '') {
             $min = $eshopoptions['min_qty'];
         }
         if (isset($eshopoptions['max_qty']) && $eshopoptions['max_qty'] != '') {
             $max = $eshopoptions['max_qty'];
         }
         if (isset($min) && isset($_POST['qty']) && $_POST['qty'] < $min) {
             $qty = $_POST['qty'] = $min;
             $v = '999';
             if (isset($max)) {
                 $v = $max;
             }
             $k = $min;
             $enote = '<p><strong class="eshoperror error">' . sprintf(__('Warning: The quantity must equal or be greater than %s, with a maximum of %s.', 'eshop'), $k, $v) . '</strong></p>';
         }
         if (isset($max) && isset($_POST['qty']) && $_POST['qty'] > $max) {
             $qty = $_POST['qty'] = $max;
             $v = $max;
             $k = 1;
             if (isset($min)) {
                 $k = $min;
             }
             $enote = '<p><strong class="eshoperror error">' . sprintf(__('Warning: The quantity must equal or be greater than %s, with a maximum of %s.', 'eshop'), $k, $v) . '</strong></p>';
         }
         //update products in the cart
         if (isset($_POST['save']) && $_POST['save'] == 'true' && isset($_SESSION['eshopcart' . $blog_id])) {
             $eshopcartarray = $_SESSION['eshopcart' . $blog_id];
             foreach ($eshopcartarray as $productid => $opt) {
                 $needle = array(" ", ".");
                 $sessproductid = str_replace($needle, "_", $productid);
                 foreach ($_POST as $key => $value) {
                     if ($key == $sessproductid) {
                         foreach ($value as $notused => $qty) {
                             if (isset($tochkkey) && $tochkkey == $key && $tochkqty == $qty) {
                                 $qty = 0;
                             }
                             if ($qty == "0") {
                                 unset($_SESSION['eshopcart' . $blog_id][$productid]);
                             } else {
                                 $postid = $eshopid = $_SESSION['eshopcart' . $blog_id][$productid]['postid'];
                                 $eshop_product = maybe_unserialize(get_post_meta($postid, '_eshop_product', true));
                                 $optnum = $_SESSION['eshopcart' . $blog_id][$productid]['option'];
                                 if (isset($eshop_product['products'][$_SESSION['eshopcart' . $blog_id][$productid]['option']]['stkqty'])) {
                                     $stkqty = $eshop_product['products'][$_SESSION['eshopcart' . $blog_id][$productid]['option']]['stkqty'];
                                 }
                                 //recheck stkqty
                                 $stocktable = $wpdb->prefix . "eshop_stock";
                                 $stktableqty = $wpdb->get_var("SELECT available FROM {$stocktable} where post_id={$eshopid} AND option_id={$optnum}");
                                 if (isset($stktableqty) && is_numeric($stktableqty)) {
                                     $stkqty = $stktableqty;
                                 }
                                 if (!ctype_digit(trim($qty)) || strlen($qty) > 3) {
                                     $v = '999';
                                     if (isset($max)) {
                                         $v = $max;
                                     }
                                     $error = '<p><strong class="eshoperror error">' . sprintf(__('Error: The quantity must contain numbers only, with a maximum of %s.', 'eshop'), $v) . '</strong></p>';
                                 } elseif ('yes' == $eshopoptions['stock_control'] && $stkqty < $qty) {
                                     $error = '<p><strong class="eshoperror error">' . __('Error: That quantity is not available for that product.', 'eshop') . '</strong></p>';
                                 } elseif (isset($min) && isset($qty) && $qty < $min) {
                                     $qty = $min;
                                     $v = '999';
                                     if (isset($max)) {
                                         $v = $max;
                                     }
                                     $k = $min;
                                     $enote = '<p><strong class="eshoperror error">' . sprintf(__('Warning: The quantity must equal or be greater than %s, with a maximum of %s.', 'eshop'), $k, $v) . '</strong></p>';
                                 } elseif (isset($max) && isset($qty) && $qty > $max) {
                                     $qty = $max;
                                     $v = $max;
                                     $k = 1;
                                     if (isset($min)) {
                                         $k = $min;
                                     }
                                     $enote = '<p><strong class="eshoperror error">' . sprintf(__('Warning: The quantity must equal or be greater than %s, with a maximum of %s.', 'eshop'), $k, $v) . '</strong></p>';
                                 } else {
                                     $_SESSION['eshopcart' . $blog_id][$productid]['qty'] = $qty;
                                 }
                             }
                         }
                     }
                 }
             }
             $_SESSION['final_price' . $blog_id] = calculate_price();
             //$_SESSION['items'.$blog_id] = calculate_items();
         }
     }
     //any errors will print here.
     if (isset($error)) {
         $_SESSION['eshopcart' . $blog_id]['error'] = $error;
     }
     if (isset($enote)) {
         $_SESSION['eshopcart' . $blog_id]['enote'] = $enote;
     }
     if (isset($_SESSION['eshopcart' . $blog_id]) && sizeof($_SESSION['eshopcart' . $blog_id]) == '0') {
         unset($_SESSION['eshopcart' . $blog_id]);
         unset($_SESSION['final_price' . $blog_id]);
         unset($_SESSION['items' . $blog_id]);
     }
 }
Exemplo n.º 3
0
function get_item_info(&$item, $item_id = "", $quantity = "")
{
    global $db, $table_prefix, $site_id;
    $dbp = new VA_SQL();
    $dbp->DBType = $db->DBType;
    $dbp->DBDatabase = $db->DBDatabase;
    $dbp->DBHost = $db->DBHost;
    $dbp->DBPort = $db->DBPort;
    $dbp->DBUser = $db->DBUser;
    $dbp->DBPassword = $db->DBPassword;
    $dbp->DBPersistent = $db->DBPersistent;
    $item_id = isset($item["ITEM_ID"]) ? $item["ITEM_ID"] : $item_id;
    $quantity = isset($item["QUANTITY"]) ? $item["QUANTITY"] : $quantity;
    $is_price_edit = isset($item["PRICE_EDIT"]) ? $item["PRICE_EDIT"] : 0;
    if (!$is_price_edit) {
        $quantity_price = get_quantity_price($item_id, $quantity);
        if (is_array($quantity_price) && sizeof($quantity_price) == 3) {
            $item["ITEM_ID"] = $item_id;
            $item["PRICE"] = $quantity_price[0];
            $item["PROPERTIES_DISCOUNT"] = $quantity_price[1];
            $item["DISCOUNT"] = $quantity_price[2];
        } else {
            // check original price
            $price_type = get_session("session_price_type");
            if ($price_type == 1) {
                $price_field = "trade_price";
                $sales_field = "trade_sales";
                $additional_price_field = "trade_additional_price";
            } else {
                $price_field = "price";
                $sales_field = "sales_price";
                $additional_price_field = "additional_price";
            }
            $sql = " SELECT " . $price_field . "," . $sales_field . ",is_sales ";
            $sql .= " FROM " . $table_prefix . "items ";
            $sql .= " WHERE item_id=" . $dbp->tosql($item_id, INTEGER);
            $dbp->query($sql);
            if ($dbp->next_record()) {
                $product_price = calculate_price($dbp->f($price_field), $dbp->f("is_sales"), $dbp->f($sales_field));
            } else {
                $product_price = isset($item["PRICE"]) ? $item["PRICE"] : "";
            }
            $item["ITEM_ID"] = $item_id;
            $item["PRICE"] = $product_price;
            $item["PROPERTIES_DISCOUNT"] = 0;
            $item["DISCOUNT"] = 1;
            // discount applicable
        }
    }
}
Exemplo n.º 4
0
     $user_price_action = $q_prices[2];
 }
 $properties_price = $db->f($properties_field);
 if ($user_price > 0 && ($user_price_action > 0 || !$discount_type)) {
     if ($is_sales) {
         $sales_price = $user_price;
     } else {
         $price = $user_price;
     }
 }
 $accessory_tax_id = $db->f("tax_id");
 $accessory_tax_free = $db->f("tax_free");
 if ($user_tax_free) {
     $accessory_tax_free = $user_tax_free;
 }
 $accessory_price = calculate_price($price, $is_sales, $sales_price);
 if ($user_price_action != 1) {
     if ($discount_type == 1 || $discount_type == 3) {
         $accessory_price -= round($accessory_price * $discount_amount / 100, 2);
     } elseif ($discount_type == 2) {
         $accessory_price -= round($discount_amount, 2);
     } elseif ($discount_type == 4) {
         $accessory_price -= round(($accessory_price - $buying_price) * $discount_amount / 100, 2);
     }
 }
 // add properties and components prices
 $accessory_price += $properties_price;
 set_tax_price($accessory_id, $accessory_type_id, $accessory_price, 1, 0, $accessory_tax_id, $accessory_tax_free, "accessory_price", "", "accessory_tax_price", false, 0, 0, false);
 $t->set_var("accessory_id", $accessory_id);
 $t->set_var("accessory_name", $accessory_name);
 $t->set_var("accessory_a_title", htmlspecialchars($accessory_a_title));
Exemplo n.º 5
0
 public function checkout()
 {
     //$this->Cookie->destroy();
     /*if($this->Cookie->check('Basket')){
     			$cookie=$this->Cookie->read('Basket');
     			
     		}*/
     $items = array();
     $i = 0;
     $ids = array();
     if (isset($this->data['item']) && !empty($this->data['item'])) {
         $restaurant = $this->Restaurant->find('first', array('conditions' => array('Restaurant.id' => $this->data['restaurant_id'])));
         if (!empty($restaurant['Restaurant']['facilities'])) {
             $facilities = explode('|', $restaurant['Restaurant']['facilities']);
             $facs = $this->Facility->find('all', array('conditions' => array('Facility.id IN' => $facilities)));
             $this->set('facilities', $facs);
         }
         foreach ($this->data['item'] as $dat) {
             foreach ($dat as $id => $qty) {
                 if (!in_array($id, $ids)) {
                     $items[$id] = $qty;
                     $ids[] = $id;
                 } else {
                     $items[$id] += $qty;
                 }
             }
         }
         $this->Deal->unbindModel(array('belongsTo' => array('Restaurant')));
         $deals = $this->Deal->find('first', array('conditions' => array('Deal.restaurant_id' => $restaurant['Restaurant']['id'])));
         if (!empty($deals)) {
             $this->set('deal', $deals);
         }
         if (count($ids) > 1) {
             $func = 'IN';
         } else {
             $func = null;
         }
         $menu = $this->Menu->find('all', array('conditions' => array('Menu.id ' . $func => $ids)));
         if (!empty($menu)) {
             $totalprice = $totalqty = $i = 0;
             foreach ($menu as $mn) {
                 if (!empty($deals)) {
                     $price = calculate_price($mn['Menu']['price'], $deals['Deal']['value'], $deals['Deal']['discount_type']);
                 }
                 foreach ($items as $ind => $itm) {
                     if ($ind == $mn['Menu']['id']) {
                         $menu[$i]['Menu']['qty'] = $itm;
                         $totalprice += $price * $itm;
                         $totalqty += $itm;
                     }
                 }
                 $i++;
             }
             //pr($menu); die;
             if (isset($cookie) && !empty($cookie)) {
                 foreach ($cookie['menu'] as $ckm) {
                     if (!in_array($ckm['Menu']['id'], $ids)) {
                         /*-------Add already existing item to new menu list----*/
                         $menu[$i] = $ckm;
                         $totalprice += $ckm['Menu']['price'] * $ckm['Menu']['qty'];
                         $totalqty += $ckm['Menu']['qty'];
                         $i++;
                     } else {
                         /*----update item quantity and corresponding total price in new menu list----*/
                         $j = 0;
                         foreach ($menu as $mn) {
                             if ($mn['Menu']['id'] == $ckm['Menu']['id']) {
                                 $menu[$j]['Menu']['qty'] += $ckm['Menu']['qty'];
                                 $totalprice += $cookie['totalprice'];
                                 $totalqty += $cookie['totalqty'];
                             }
                             $j++;
                         }
                     }
                 }
             }
             $this->Cookie->time = 3600;
             // 1 hour
             $this->Cookie->write('Basket.menu', $menu);
             $this->Cookie->write('Basket.totalqty', $totalqty);
             $this->Cookie->write('Basket.restaurant_id', $restaurant['Restaurant']['id']);
             $this->Cookie->write('Basket.totalprice', $totalprice);
             $this->set('restaurant', $restaurant);
             $this->set('totalprice', $totalprice);
             $this->set('totalqty', $totalqty);
         }
         $this->set('menu', $menu);
     } else {
         $this->redirect('/');
     }
     $this->render('checkout');
 }
 function rebill($dat = '')
 {
     global $config, $db, $t, $cc_core;
     if ($dat == '') {
         $dat = date('Y-m-d');
     }
     $tomorrow = date('Y-m-d', strtotime($dat) + 3600 * 24);
     $plugin = 'manual_euro_bank';
     $payments = $db->get_expired_payments($dat, $dat, $plugin);
     foreach ($payments as $p) {
         if ($p['data']['CANCELLED']) {
             continue;
         }
         $product = get_product($p['product_id']);
         if (!$product->config['is_recurring']) {
             continue;
         }
         $pc =& new PriceCalculator();
         $pc->addProduct($p['product_id']);
         $pc->setTax(get_member_tax($p['member_id']));
         $terms =& $pc->calculate();
         $pp = array('member_id' => $p['member_id'], 'product_id' => $p['product_id'], 'paysys_id' => $p['paysys_id'], 'begin_date' => $dat, 'expire_date' => $product->get_expire($dat), 'amount' => calculate_price($p['product_id'], $p['member_id'], $vars, $prices));
         if ($err = $db->add_payment($pp)) {
             trigger_error("Cannot add payment : {$err}", E_USER_WARNING);
         }
         $payment_id = $GLOBALS['_amember_added_payment_id'];
         $this->signup_moderator_mail($payment_id, $signup = false);
     }
 }
Exemplo n.º 7
0
     if (!strlen($item_image)) {
         $item_image = $product_no_image;
     } else {
         $image_exists = true;
     }
 }
 $product_friendly_url = $db->f("friendly_url");
 if ($friendly_urls && $product_friendly_url) {
     $product_url = $product_friendly_url . $friendly_extension;
 } else {
     $product_url = get_custom_friendly_url("product_details.php") . "?item_id=" . $item_id;
 }
 $properties_discount = 0;
 $discount_applicable = 1;
 if (!$is_price_edit) {
     $price = calculate_price($price, $is_sales, $sales_price);
     $quantity_price = get_quantity_price($item_id, $quantity);
     if (sizeof($quantity_price)) {
         $price = $quantity_price[0];
         $properties_discount = $quantity_price[1];
         $discount_applicable = $quantity_price[2];
     }
     if ($discount_applicable) {
         if ($user_discount_type == 1 || $user_discount_type == 3) {
             $price -= round($price * $user_discount_amount / 100, 2);
         } elseif ($user_discount_type == 2) {
             $price -= round($user_discount_amount, 2);
         } elseif ($user_discount_type == 4) {
             $price -= round(($price - $buying_price) * $user_discount_amount / 100, 2);
         }
     }
Exemplo n.º 8
0
include 'curl.php';
$org_name = $_GET["org"];
// This is a base price per hour for users - R$ 18,00
$min_price = 18;
$org_uri = "https://api.github.com/orgs/" . $org_name;
$org_members_uri = "https://api.github.com/orgs/" . $org_name . "/members";
$user_uri = "https://api.github.com/users/";
// Get the user logins from an organization and build an array of URIs
// (e.g. array("api.github.com/members/memberX", "api.github.com/members/memberY") )
$members_uris_arr = array();
$members_arr = json_decode(curl_get_content($org_members_uri, $token));
foreach ($members_arr as $i => $member) {
    $members_uris_arr[$i] = $user_uri . $member->login;
}
// Use the built array to pass to the cURL function (curl_get_content_mt) that gets all the info for each user.
$developers_arr = curl_get_content_mt($members_uris_arr, $token);
foreach ($developers_arr as $i => $developer) {
    $developer->price = calculate_price($min_price, $developer->followers, $developer->public_repos);
    // add the user calculated price in users/developers array
}
// Prints the final JSON string that will be used by the client.
echo json_encode($developers_arr, JSON_UNESCAPED_SLASHES | JSON_PRETTY_PRINT);
/**
 * Function to calculate the user price based on FOLLOWERS and REPOS that this user has.
 * Each followers worths R$ 1,00 and each repo R$ 0,50.
 */
function calculate_price($minimum_price, $followers, $repos)
{
    $price = $minimum_price + $followers * 1.0 + $repos * 0.5;
    return number_format($price, 2, ',', '');
}