예제 #1
0
 /**
  * Returns the price for a specific shopper group,
  * Returns nothing, when the shopper group has no price
  *
  * @param int $product_id
  * @param int $shopper_group_id
  * @param boolean $check_multiple_prices
  * @param string $additionalSQL
  * @return mixed
  */
 function getPriceByShopperGroup($product_id, $shopper_group_id, $check_multiple_prices = false, $additionalSQL = '')
 {
     global $auth;
     static $resultcache = array();
     $db = new ps_DB();
     $vendor_id = $_SESSION['ps_vendor_id'];
     if (empty($shopper_group_id)) {
         ps_shopper_group::makeDefaultShopperGroupInfo();
         $shopper_group_id = $GLOBALS['vendor_info'][$vendor_id]['default_shopper_group_id'];
     }
     $whereClause = 'WHERE product_id=%s AND shopper_group_id=%s ';
     $whereClause = sprintf($whereClause, intval($product_id), intval($shopper_group_id));
     $q = "SELECT `product_price`, `product_price_id`, `product_currency` FROM `#__{vm}_product_price` {$whereClause} {$additionalSQL}";
     $sig = sprintf("%u\n", crc32($q));
     if (!isset($resultcache[$sig])) {
         $db->query($q);
         if (!$db->next_record()) {
             return false;
         }
         $price_info["product_price"] = $db->f("product_price") * ((100 - $auth["shopper_group_discount"]) / 100);
         $price_info["product_currency"] = $db->f("product_currency");
         $price_info["product_base_price"] = $db->f("product_price") * ((100 - $auth["shopper_group_discount"]) / 100);
         $price_info["product_has_multiple_prices"] = $db->num_rows() > 1;
         $price_info["product_price_id"] = $db->f("product_price_id");
         $price_info["item"] = true;
         $GLOBALS['product_info'][$product_id]['price'] = $price_info;
         // Store the result for later
         $resultcache[$sig] = $price_info;
         return $GLOBALS['product_info'][$product_id]['price'];
     } else {
         return $resultcache[$sig];
     }
 }
예제 #2
0
 /**
  * Returns the price for a specific shopper group,
  * Returns nothing, when the shopper group has no price
  *
  * @param int $product_id
  * @param int $shopper_group_id
  * @param boolean $check_multiple_prices
  * @param string $additionalSQL
  * @return mixed
  */
 function getPriceByShopperGroup($product_id, $shopper_group_id, $check_multiple_prices = false, $additionalSQL = '')
 {
     global $auth;
     static $resultcache = array();
     $db = new ps_DB();
     $vendor_id = $_SESSION['ps_vendor_id'];
     if (empty($shopper_group_id)) {
         ps_shopper_group::makeDefaultShopperGroupInfo();
         $shopper_group_id = $GLOBALS['vendor_info'][$vendor_id]['default_shopper_group_id'];
     }
     $dontUseCustomDiscount = 0;
     if ($shopper_group_id != $GLOBALS['vendor_info'][$vendor_id]['default_shopper_group_id']) {
         // отменяем пользовательскую скидку, если товар продаётся без скидок
         if ($this->getProductNodiscount($product_id)) {
             $shopper_group_id = $GLOBALS['vendor_info'][$vendor_id]['default_shopper_group_id'];
             $dontUseCustomDiscount = 1;
         }
     }
     $whereClause = 'WHERE product_id=%s AND shopper_group_id=%s ';
     $whereClause = sprintf($whereClause, intval($product_id), intval($shopper_group_id));
     $q = "SELECT `product_price`, `product_price_id`, `product_currency`, price_quantity_start FROM `#__{vm}_product_price` {$whereClause} {$additionalSQL}";
     $sig = sprintf("%u\n", crc32($q));
     if (!isset($resultcache[$sig])) {
         $db->query($q);
         if (!$db->next_record()) {
             return false;
         }
         // обнуляем групповую скидку если товар "без скидки"
         if ($dontUseCustomDiscount) {
             $shopper_group_discount = 0;
         } else {
             $shopper_group_discount = $auth["shopper_group_discount"];
         }
         // обнуляем скидку группы если есть скидка за объем
         if ($db->f('price_quantity_start') > 1) {
             $shopper_group_discount = 0;
         }
         // обнуляем скидку группы если есть скидка на товар
         $prod_discount = $this->get_discount(intval($product_id));
         if (isset($prod_discount['amount']) && $prod_discount['amount'] > 0) {
             $shopper_group_discount = 0;
         }
         $price_info["product_price"] = $db->f("product_price") * ((100 - $shopper_group_discount) / 100);
         $price_info["product_currency"] = $db->f("product_currency");
         $price_info["product_base_price"] = $db->f("product_price") * ((100 - $shopper_group_discount) / 100);
         $price_info["product_has_multiple_prices"] = $db->num_rows() > 1;
         $price_info["product_price_id"] = $db->f("product_price_id");
         $price_info["item"] = true;
         $GLOBALS['product_info'][$product_id]['price'] = $price_info;
         // Store the result for later
         $resultcache[$sig] = $price_info;
         // проверяем ещё цены
         while ($db->next_record()) {
             $price_info["product_price_nd"] = $db->f('product_price');
         }
         $GLOBALS['product_info'][$product_id]['price'] = $price_info;
         $resultcache[$sig] = $price_info;
         return $GLOBALS['product_info'][$product_id]['price'];
     } else {
         return $resultcache[$sig];
     }
 }