Beispiel #1
0
 /**
  * main action
  */
 public function mainAction()
 {
     require_once 'models/ecommerce/ecommerce_price.php';
     $Price = new ecommerce_price();
     // type
     $types = $Price->getTypes();
     foreach ($types as $type) {
         $this->tpl->assign('TYPE', $type);
         if ($type == $_POST['price']['type'] || $type == $this->GET['type']) {
             $this->tpl->assign('SELECTED', "selected='selected'");
         } else {
             $this->tpl->assign('SELECTED', "");
         }
         $this->tpl->parse('content.type');
     }
     if ($_POST['save']) {
         $price_data = $_POST['price'];
         // FIXME: form_currency_inline hack
         $price_data['currency_code'] = $_POST['client']['customer']['currency_code'];
         if ($id = $Price->priceInsert($price_data)) {
             msg("Price added.");
             require_once 'models/ecommerce/ecommerce_product_variety.php';
             $Product_variety = new ecommerce_product_variety();
             $pd = $Product_variety->detail($price_data['product_variety_id']);
         } else {
             return false;
         }
     }
     $this->tpl->assign('PRICE', $_POST['price']);
     return true;
 }
Beispiel #2
0
 /**
  * main action
  */
 public function mainAction()
 {
     require_once 'models/ecommerce/ecommerce_product_variety.php';
     require_once 'models/ecommerce/ecommerce_product.php';
     $Product_variety = new ecommerce_product_variety();
     $Product = new ecommerce_product();
     $this->tpl->assign('VARIETY_CONF', $Product_variety->conf);
     $Product_variety->set('id', $this->GET['id']);
     if ($_POST['save'] == 'save') {
         if ($id = $Product_variety->updateVariety($_POST['product']['variety'])) {
             msg("Product variety updated.");
             /*onxshopGoTo($_SESSION['last_diff'], 2);*/
         } else {
             msg("Can't add the product variety, is you product SKU unique?");
         }
     }
     $variety = $Product_variety->getVarietyDetail($this->GET['id']);
     $variety['publish'] = $variety['publish'] == 1 ? 'checked="checked" ' : '';
     $p = $Product->detail($variety['product_id']);
     $p['variety'] = $variety;
     $this->tpl->assign('PRODUCT', $p);
     /**
      * display confirmation if notifications are about to be sent out
      */
     require_once 'models/common/common_watchdog.php';
     $Watchdog = new common_watchdog();
     $this->tpl->assign('NOTIFICATIONS', array('back_in_stock_customer' => $Watchdog->checkWatchdog('back_in_stock_customer', $variety_id, 0, 1, true)));
     return true;
 }
 /**
  * main action
  */
 public function mainAction()
 {
     /**
      * check variety_id input
      */
     if (is_numeric($this->GET['id'])) {
         $variety_id = $this->GET['id'];
     } else {
         msg("Variety ID is not numeric", 'error');
         return false;
     }
     /**
      * initialize
      */
     require_once 'models/ecommerce/ecommerce_product_variety.php';
     require_once 'models/ecommerce/ecommerce_product.php';
     $Product_variety = new ecommerce_product_variety();
     $Product = new ecommerce_product();
     $this->tpl->assign('VARIETY_CONF', $Product_variety->conf);
     /**
      * update variety
      */
     if ($_POST['save'] == 'save') {
         if (!isset($_POST['product']['variety']['publish'])) {
             $_POST['product']['variety']['publish'] = 0;
         }
         if ($id = $Product_variety->updateVariety($_POST['product']['variety'])) {
             msg("Product variety ID {$variety_id} updated.");
             /*onxshopGoTo($_SESSION['last_diff'], 2);*/
         } else {
             msg("Can't update the product variety, is you product code unique?", 'error');
         }
     }
     /**
      * get detail
      */
     $variety = $Product_variety->getVarietyDetail($variety_id);
     $variety['publish'] = $variety['publish'] == 1 ? 'checked="checked" ' : '';
     //alert if net weight is bigger than gross weight
     if ($variety['weight'] > $variety['weight_gross']) {
         msg("Net weight is bigger than gross weight", "error");
     }
     $p = $Product->detail($variety['product_id']);
     $p['variety'] = $variety;
     $this->tpl->assign('PRODUCT', $p);
     /**
      * display confirmation if notifications are about to be sent out
      */
     require_once 'models/common/common_watchdog.php';
     $Watchdog = new common_watchdog();
     $this->tpl->assign('NOTIFICATIONS', array('back_in_stock_customer' => $Watchdog->checkWatchdog('back_in_stock_customer', $variety['id'], 0, 1, true)));
     return true;
 }
 /**
  * main action
  */
 public function mainAction()
 {
     if (is_numeric($this->GET['id'])) {
         $variety_id = $this->GET['id'];
     } else {
         return false;
     }
     require_once 'models/ecommerce/ecommerce_product_variety.php';
     $ProductVariety = new ecommerce_product_variety();
     //keep the same naming as in product_variety_edit controller
     $product = array();
     $product['variety'] = $ProductVariety->getDetail($variety_id);
     $this->tpl->assign('PRODUCT', $product);
     return true;
 }
 /**
  * main action
  */
 public function mainAction()
 {
     /**
      * include variety confg
      */
     require_once 'models/ecommerce/ecommerce_product_variety.php';
     $variety_conf = ecommerce_product_variety::initConfiguration();
     $this->tpl->assign('VARIETY_CONF', $variety_conf);
     /**
      * product
      */
     require_once 'models/ecommerce/ecommerce_product.php';
     $Product = new ecommerce_product();
     $product = $Product->getProductDetail($this->GET['id']);
     if (is_array($product['variety'])) {
         foreach ($product['variety'] as $variety) {
             if ($variety['publish'] == 0) {
                 $this->tpl->assign('DISABLED', 'disabled');
             } else {
                 $this->tpl->assign('DISABLED', '');
             }
             $Image = new Onxshop_Request("component/image&relation=product_variety&node_id={$variety['id']}");
             $this->tpl->assign('IMAGE', $Image->getContent());
             $this->tpl->assign('VARIETY', $variety);
             $this->tpl->parse('content.variety');
         }
     } else {
         msg('This product has no variety.');
     }
     return true;
 }
 /**
  * main action
  */
 public function mainAction()
 {
     /**
      * input
      */
     if (is_numeric($this->GET['product_variety_id'])) {
         $product_variety_id = $this->GET['product_variety_id'];
     } else {
         $product_variety_id = false;
     }
     /**
      * initialize
      */
     require_once 'models/ecommerce/ecommerce_product_variety.php';
     require_once 'models/ecommerce/ecommerce_product_type.php';
     $ProductVariety = new ecommerce_product_variety();
     $ProductType = new ecommerce_product_type();
     /**
      * get product variety detail if requested
      */
     if (is_numeric($product_variety_id)) {
         $product_variety = $ProductVariety->detail($product_variety_id);
     }
     /**
      * prepare product type id (either for requested product variety or default one)
      */
     if (is_numeric($product_variety['product_type_id'])) {
         $product_type_id = $product_variety['product_type_id'];
     } else {
         $product_type_id = $ProductType->conf['default_id'];
     }
     /**
      * listing published items
      */
     $types = $ProductType->listing("publish = 1");
     foreach ($types as $type) {
         $this->tpl->assign('TYPE', $type);
         if ($type['id'] == $product_type_id) {
             $this->tpl->assign('SELECTED', 'selected="selected"');
         } else {
             $this->tpl->assign('SELECTED', '');
         }
         $this->tpl->parse('content.type');
     }
     return true;
 }
 /**
  * main action
  */
 public function mainAction()
 {
     $product_data = $_POST['product'];
     if (!isset($product_data['variety']['product_id'])) {
         $product_data['variety']['product_id'] = $product_data['id'];
     }
     require_once 'models/ecommerce/ecommerce_product_variety.php';
     $Product_variety = new ecommerce_product_variety();
     $this->tpl->assign("VARIETY_CONF", $Product_variety->conf);
     if ($_POST['save']) {
         if ($id = $Product_variety->insertFullVariety($product_data['variety'])) {
             msg("Product variety id={$id} has been added.");
             //empty
             $product_data = array();
         } else {
             msg("Can't add the product variety for product id={$product_data['variety']['product_id']}. Is your product SKU unique? Did you fill in stock value?");
         }
     }
     $this->tpl->assign('PRODUCT', $product_data);
     return true;
 }
 /**
  * get content
  */
 function getContentItemsProductIdList($basket_id)
 {
     if (!is_numeric($basket_id)) {
         msg("ecommerce_basket->getContentItemsProductIdList(): basket_id is not numeric", 'error', 1);
         return false;
     }
     require_once 'models/ecommerce/ecommerce_product_variety.php';
     $Product_variety = new ecommerce_product_variety();
     $variety_ids = $this->getContentItemsVarietyIdList($basket_id);
     $id_list = array();
     foreach ($variety_ids as $variety_id) {
         $variety_detail = $Product_variety->detail($variety_id);
         $id_list[] = intval($variety_detail['product_id']);
     }
     return $id_list;
 }
 /**
  * get product variety list
  */
 function getProductVarietyList($product_id)
 {
     if (!is_numeric($product_id)) {
         return false;
     }
     require_once 'models/ecommerce/ecommerce_product_variety.php';
     $ProductVariety = new ecommerce_product_variety();
     $varieties = $ProductVariety->listing("product_id = {$product_id}", 'priority DESC, id ASC');
     if (is_array($varieties)) {
         foreach ($varieties as $kv => $v) {
             $variety[$kv] = $ProductVariety->getVarietyDetail($v['id']);
         }
         return $variety;
     } else {
         msg("Product id {$product_id} has no varieties", 'error', 1);
         return false;
     }
 }
Beispiel #10
0
 /**
  * descrement value on the stock
  *
  * @param array $order_data
  * @return bool
  */
 function decrementStock($order_data)
 {
     if (!is_array($order_data)) {
         msg("Cannot decrement stock", 'error');
         return false;
     }
     require_once 'models/ecommerce/ecommerce_product.php';
     $ProductVariety = new ecommerce_product_variety();
     foreach ($order_data['basket']['items'] as $item) {
         $new_stock_value = $item['product']['variety']['stock'] - $item['quantity'];
         $variety_id = $item['product']['variety']['id'];
         $ProductVariety->updateSingleAttribute('stock', $new_stock_value, $variety_id);
     }
     return true;
 }
Beispiel #11
0
 /**
  * getCustomPriceIdByMultiplicator
  */
 public function getCustomPriceIdByMultiplicator($product_variety_id, $multiplicator)
 {
     if ($this->conf['allow_multiplicator'] == 0) {
         msg("Price multiplicator is disabled", 'error');
         return false;
     }
     if (!is_numeric($product_variety_id)) {
         return false;
     }
     if (!is_numeric($multiplicator)) {
         return false;
     }
     // need to check if min_price is not set
     require_once 'models/ecommerce/ecommerce_product_variety.php';
     $Product_Varity = new ecommerce_product_variety();
     $product_variety = $Product_Varity->getDetail($product_variety_id);
     $min_price = (int) $product_variety['other_data']['min_price'];
     // linear growth by default
     $exponent = 1;
     if ($this->conf['multiplicator_growth'] == "exponential_over_1") {
         // need to check if exponent is not set
         if (is_numeric($product_variety['other_data']['exponent'])) {
             $exponent = $product_variety['other_data']['exponent'];
         } else {
             // otherwise set it as per global configuration
             if (is_numeric($this->conf['multiplicator_exponent'])) {
                 $exponent = $this->conf['multiplicator_exponent'];
             }
         }
     }
     $type = "multiplicator_{$multiplicator}";
     if ($min_price > 0) {
         $type .= "_min_{$min_price}";
     }
     if ($exponent != 1) {
         $type .= "_exponent_{$exponent}";
     }
     $price_data = $this->getLastPriceForVariety($product_variety_id, GLOBAL_DEFAULT_CURRENCY, $type);
     $common_price_data = $this->getLastPriceForVariety($product_variety_id);
     if (is_numeric($price_data['id']) && bccomp($common_price_data['value'], $price_data['value'], 3) == 0) {
         $price_id = $price_data['id'];
     } else {
         $price_data = array();
         $price_data['product_variety_id'] = $product_variety_id;
         switch ($this->conf['multiplicator_growth']) {
             case 'exponential_over_1':
                 //exponential for multiplicator value greater than 1, under 1 is linear
                 if ($multiplicator > 1) {
                     $price_data['value'] = $common_price_data['value'] * pow($multiplicator, $exponent);
                 } else {
                     $price_data['value'] = $common_price_data['value'] * $multiplicator;
                 }
                 break;
             case 'linear':
             default:
                 //linear growth
                 $price_data['value'] = $common_price_data['value'] * $multiplicator;
                 break;
         }
         if ($price_data['value'] < $min_price) {
             $price_data['value'] = $min_price;
         }
         $price_data['currency_code'] = GLOBAL_DEFAULT_CURRENCY;
         $price_data['type'] = $type;
         $price_id = $this->priceInsert($price_data);
     }
     msg("Created custom price ID {$price_id}", 'ok', 2);
     if (is_numeric($price_id)) {
         return $price_id;
     } else {
         return false;
     }
 }
 /**
  * main action
  */
 public function mainAction()
 {
     /**
      * TODO:
      * implement general updateSingleAttribute()
      */
     //print_r($_POST);
     $model = $this->GET['model'];
     $attribute = $this->GET['attribute'];
     $update_value = trim($_POST['update_value']);
     $original_value = trim($_POST['original_html']);
     // currently implemented for product_variety.name and price.value
     switch ($model) {
         case 'common_node':
             require_once 'models/common/common_node.php';
             $element_id_parts = explode('-', $_POST['element_id']);
             $variety_id = $element_id_parts[3];
             $ModelObj = new common_node();
             if (!$ModelObj->updateSingleAttribute($attribute, $update_value, $variety_id)) {
                 msg('Failed', 'error');
             }
             break;
         case 'ecommerce_product_variety':
             require_once 'models/ecommerce/ecommerce_product_variety.php';
             $element_id_parts = explode('-', $_POST['element_id']);
             $variety_id = $element_id_parts[3];
             $ModelObj = new ecommerce_product_variety();
             if (!$ModelObj->updateSingleAttribute($attribute, $update_value, $variety_id)) {
                 msg('Failed', 'error');
             }
             break;
         case 'ecommerce_price':
             require_once 'models/ecommerce/ecommerce_price.php';
             $ModelObj = new ecommerce_price();
             $element_id_parts = explode('-', $_POST['element_id']);
             $variety_id = $element_id_parts[3];
             $last_price = $ModelObj->getLastPriceForVariety($variety_id);
             //remove anything else than number and decimal point
             $update_value = preg_replace("/[^0-9\\.]*/", '', $update_value);
             //update only when the new price is different than old price
             if (round($last_price['value'], 2) != round($update_value, 2)) {
                 if (!$ModelObj->updateSingleAttribute('value', $update_value, $last_price['id'])) {
                     msg('Failed', 'error');
                 }
             }
             break;
         case 'international_translation':
             require_once 'models/international/international_translation.php';
             $element_id_parts = explode('-', $_POST['element_id']);
             $updated_id = $element_id_parts[3];
             $ModelObj = new international_translation();
             if (!$ModelObj->updateSingleAttribute($attribute, $update_value, $updated_id)) {
                 msg('Failed', 'error');
             }
             break;
         default:
             return false;
             break;
     }
     if ($update_value != $original_value) {
         $value = $update_value;
     } else {
         $value = $original_value;
     }
     $this->tpl->assign('VALUE', $value);
     return true;
 }
 /**
  * main action
  */
 public function mainAction()
 {
     return false;
     set_time_limit(0);
     $process = $this->GET['process'];
     $process = 0;
     require_once 'models/ecommerce/ecommerce_product.php';
     require_once 'models/ecommerce/ecommerce_product_variety.php';
     require_once 'models/ecommerce/ecommerce_price.php';
     require_once 'models/common/common_node.php';
     $Product = new ecommerce_product();
     $Product_variety = new ecommerce_product_variety();
     $Price = new ecommerce_price();
     $Node = new common_node();
     //START THE TRANSACTION
     $Product->db->beginTransaction();
     //get data file
     if ($this->GET['data_file'] != '') {
         $data_file = ONXSHOP_PROJECT_DIR . $this->GET['data_file'];
         if (file_exists($data_file)) {
             $google_base = $this->convertCSVtoAssocMArray($data_file, ";");
         } else {
             msg("Datafile {$data_file} does not exists", 'error');
         }
     }
     foreach ($google_base as $gb) {
         $onxshop_product['name'] = ucwords(strtolower(trim($gb['title'])));
         //check if the product name has been changed, if not, it's only new variety
         if ($watch_name != $onxshop_product['name']) {
             $watch_name = $onxshop_product['name'];
             $onxshop_product['teaser'] = $gb['teaser'];
             if ($gb['description'] != '') {
                 $onxshop_product['description'] = $gb['description'];
             } else {
                 $onxshop_product['description'] = $onxshop_product['name'];
             }
             $onxshop_product['priority'] = 0;
             $onxshop_product['brand_id'] = 1;
             $onxshop_product['publish'] = 1;
             //Food
             //if ($gb['tax_percent'] == 19) $onxshop_product['product_type_id'] = 7;
             //Food-Bio
             //else if ($gb['tax_percent'] == 5) $onxshop_product['product_type_id'] = 8;
             /*
             if ($gb['vat_group'] == 'tea') $onxshop_product['product_type_id'] = 9;
             else if ($gb['vat_group'] == 'tea ware') $onxshop_product['product_type_id'] = 10;
             else msg("Unknown vat group (product_type_id) {$gb['vat_group']}", 'error');
             */
             $onxshop_product['product_type_id'] = 9;
             //other data
             unset($onxshop_product['other_data']);
             if ($gb['other_data-taste'] != '') {
                 $onxshop_product['other_data']['taste'] = $gb['other_data-taste'];
             }
             if ($gb['other_data-infuse'] != '') {
                 $onxshop_product['other_data']['infuse'] = $gb['other_data-infuse'];
             }
             if ($gb['other_data-drink'] != '') {
                 $onxshop_product['other_data']['drink'] = $gb['other_data-drink'];
             }
             $onxshop_product['other_data'] = serialize($onxshop_product['other_data']);
             //taxonomy
             $_POST['product']['rt'][] = '';
             /*
             				switch (strtolower($gb['taxonomy-region'])) {
             					case 'china':
             						$_POST['product']['rt'][] =  18;
             					break;
             					case 'india':
             						$_POST['product']['rt'][] =  19;
             					break;
             					case 'japan':
             						$_POST['product']['rt'][] =  20;
             					break;
             					case 'sri lanka':
             						$_POST['product']['rt'][] =  21;
             					break;
             					case 'taiwan':
             						$_POST['product']['rt'][] =  34;
             					break;
             				}*/
             switch (trim($gb['brand'])) {
                 case 'Aqualeader':
                     $_POST['product']['rt'][] = 6;
                     break;
                 case 'Atlantic':
                     $_POST['product']['rt'][] = 14;
                     break;
                 case 'Bosta':
                     $_POST['product']['rt'][] = 19;
                     break;
                 case 'Catalina':
                     $_POST['product']['rt'][] = 16;
                     break;
                 case 'Doughboy':
                     $_POST['product']['rt'][] = 8;
                     break;
                 case 'Easy Cove':
                     $_POST['product']['rt'][] = 22;
                     break;
                 case 'Equinox':
                     $_POST['product']['rt'][] = 7;
                     break;
                 case 'Esther Williams':
                     $_POST['product']['rt'][] = 4;
                     break;
                 case 'Folkpool':
                     $_POST['product']['rt'][] = 9;
                     break;
                 case 'Freedom':
                     $_POST['product']['rt'][] = 11;
                     break;
                 case 'Garden Leisure':
                     $_POST['product']['rt'][] = 10;
                     break;
                 case 'Hayward':
                     $_POST['product']['rt'][] = 23;
                     break;
                 case 'Insta':
                     $_POST['product']['rt'][] = 17;
                     break;
                 case 'Kafko':
                     $_POST['product']['rt'][] = 15;
                     break;
                 case 'Kreepy Krauly':
                     $_POST['product']['rt'][] = 25;
                     break;
                 case 'Plastica':
                     $_POST['product']['rt'][] = 21;
                     break;
                 case 'Polaris':
                     $_POST['product']['rt'][] = 24;
                     break;
                 case 'Pomaz':
                     $_POST['product']['rt'][] = 12;
                     break;
                 case 'Spaform':
                     $_POST['product']['rt'][] = 13;
                     break;
                 case 'Sta-Rite':
                     $_POST['product']['rt'][] = 26;
                     break;
                 case 'Vogue':
                     $_POST['product']['rt'][] = 5;
                     break;
                 case 'Voyager':
                     $_POST['product']['rt'][] = 18;
                     break;
                 case 'Waterpik':
                     $_POST['product']['rt'][] = 20;
                     break;
             }
             $_Onxshop_Request = new Onxshop_Request("bo/component/relation_taxonomy~relation=product:id={$product_id}~");
             //print_r($onxshop_product);
             $product_id = $Product->insert($onxshop_product);
             if (is_numeric($product_id)) {
                 //image add
                 if ($gb['image_link'] != '') {
                     $_POST['file']['title'] = $onxshop_product['name'];
                     $_POST['file']['src'] = "var/files/products/{$gb['image_link']}.jpg";
                     $_POST['file']['priority'] = 0;
                     $_POST['file']['role'] = 'main';
                     $_POST['file']['node_id'] = $product_id;
                     $_POST['add'] = 'add';
                     $file = ONXSHOP_PROJECT_DIR . $_POST['file']['src'];
                     if (file_exists($file)) {
                         $_Onxshop_Request = new Onxshop_Request("bo/component/form_file~relation=product~");
                     } else {
                         msg("File {$file} does not exists", 'error');
                     }
                     unset($_POST['file']);
                 }
                 //add to node
                 $_POST['product']['name'] = $onxshop_product['name'];
                 $_POST['product']['publish'] = 1;
                 $_POST['product']['pin'][] = '';
                 $_POST['product']['pin'][] = $gb['page_id'];
                 $_Onxshop_Request = new Onxshop_Request("bo/component/ecommerce/relation_product_in_nodes~id={$product_id}~");
                 unset($_POST['product']);
             }
         }
         if (is_numeric($product_id)) {
             $onxshop_product_variety['name'] = $gb['variety_name'];
             $onxshop_product_variety['product_id'] = $product_id;
             $onxshop_product_variety['sku'] = $gb['sku'];
             if (is_numeric($gb['weight'])) {
                 $onxshop_product_variety['weight'] = $gb['weight'];
             } else {
                 $onxshop_product_variety['weight'] = -1;
             }
             $onxshop_product_variety['stock'] = $gb['stock'];
             $onxshop_product_variety['priority'] = 0;
             $onxshop_product_variety['description'] = '';
             $product_variety_id = $Product_variety->insert($onxshop_product_variety);
             //print_r($onxshop_product_variety);
             if (is_numeric($product_variety_id)) {
                 $onxshop_price['product_variety_id'] = $product_variety_id;
                 $onxshop_price['currency_code'] = $GLOBALS['onxshop_conf']['global']['default_currency'];
                 $onxshop_price['value'] = $gb['price'];
                 //$onxshop_price['value'] = $gb['price'] / 117.5 * 100;
                 $onxshop_price['type'] = 'common';
                 $onxshop_price['date'] = date('c');
                 $price_id = $Price->insert($onxshop_price);
             }
         }
     }
     // COMPLETE THE TRANSACTION
     if ($process) {
         if ($Product->db->commit()) {
             msg('CompleteTrans');
         } else {
             msg('Some error in the import, try debug.');
         }
     } else {
         msg("Some errors in import has occurred", 'error');
         msg('RollbackTrans');
         //$this->tpl->parse();
         $Product->db->rollBack();
     }
 }
 /**
  * Returns delivery rate according to given order value and weight
  * 
  * @param  int   $carrier_id  Carrier Id
  * @param  float $order_value Order value ($basket['sub_total']['price'])
  * @param  float $weight      Order weight ($basket['total_weight_gross'])
  * @return bool|float         Delivery rate (excl. VAT), which can be zero (= free delivery), or false, which
  *                            indicates given method cannot be used with given order value and weight
  */
 function getDeliveryRate($carrier_id, $order_value, $weight)
 {
     if (!is_numeric($carrier_id)) {
         return false;
     }
     if (!is_numeric($order_value)) {
         return false;
     }
     if (!is_numeric($weight)) {
         return false;
     }
     // convert weight units
     require_once 'models/ecommerce/ecommerce_product_variety.php';
     $product_variety_conf = ecommerce_product_variety::initConfiguration();
     $Variety = new ecommerce_product_variety();
     $weight = $Variety->convertWeight($weight, $product_variety_conf['weight_units'], 'g');
     // check order value
     $carrier = $this->getDetail($carrier_id);
     $order_value = round($order_value, 2);
     // make sure to avoid rounding errors
     if ($order_value < $carrier['order_value_from'] || $order_value >= $carrier['order_value_to']) {
         return false;
     }
     // check weight
     require_once 'models/ecommerce/ecommerce_delivery_carrier_rate.php';
     $Rate = new ecommerce_delivery_carrier_rate();
     $rates = $Rate->listing("carrier_id = {$carrier_id} AND weight_from <= {$weight} AND weight_to > {$weight}");
     if (count($rates) == 0) {
         return false;
     }
     if (!isset($rates[0]['price'])) {
         return false;
     }
     return $rates[0]['price'];
 }