Пример #1
0
 /**
  * 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;
 }
 /**
  * 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'];
 }