コード例 #1
0
 /**
  * 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;
 }
コード例 #2
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;
     }
 }