Esempio n. 1
0
 public static function getQuantityDiscounts($product_id, $shop_id, $currency_id, $country_id, $group_id, $product_attribute_id = null, $all_combinations = false, $customer_id = 0)
 {
     if (!JeproshopSpecificPriceModelSpecificPrice::isFeaturePublished()) {
         return array();
     }
     $now = date('Y-m-d H:i:s');
     $db = JFactory::getDBO();
     $query = "SELECT *, " . JeproshopSpecificPriceModelSpecificPrice::getScoreQuery($product_id, $shop_id, $currency_id, $country_id, $group_id, $customer_id);
     $query .= " FROM " . $db->quoteName('#__jeproshop_specific_price') . " WHERE " . $db->quoteName('product_id') . " IN(0, " . (int) $product_id . ") AND ";
     $query .= (!$all_combinations ? $db->quoteName('product_attribute_id') . " IN(0, " . (int) $product_attribute_id . ") AND " : "") . $db->quoteName('shop_id');
     $query .= " IN(0, " . (int) $shop_id . ") AND " . $db->quoteName('currency_id') . " IN(0, " . (int) $currency_id . ") AND " . $db->quoteName('country_id');
     $query .= " IN(0, " . (int) $country_id . ") AND " . $db->quoteName('group_id') . " IN(0, " . (int) $group_id . ") AND " . $db->quoteName('customer_id') . " IN(0, ";
     $query .= (int) $customer_id . " ) AND( (" . $db->quoteName('from') . " = '0000-00-00 00:00:00' OR '" . $now . "' >= " . $db->quoteName('from') . ") AND (";
     $query .= $db->quoteName('to') . " = '0000-00-00 00:00:00' OR '" . $now . "' <= " . $db->quoteName('to') . ")) ORDER BY " . $db->quoteName('product_attribute_id');
     $query .= " DESC, " . $db->quoteName('from_quantity') . " DESC, " . $db->quoteName('specific_price_rule_id') . " ASC, " . $db->quoteName('score') . " DESC ";
     $db->setQuery($query);
     $res = $db->loadObjectList();
     $targeted_prices = array();
     $last_quantity = array();
     foreach ($res as $specific_price) {
         if (!isset($last_quantity[(int) $specific_price->product_attribute_id])) {
             $last_quantity[(int) $specific_price->product_attribute_id] = $specific_price->from_quantity;
         } elseif ($last_quantity[(int) $specific_price->product_attribute_id] == $specific_price->from_quantity) {
             continue;
         }
         $last_quantity[(int) $specific_price->product_attribute_id] = $specific_price->from_quantity;
         if ($specific_price->from_quantity > 1) {
             $targeted_prices[] = $specific_price;
         }
     }
     return $targeted_prices;
 }
Esempio n. 2
0
 public static function getSpecificPrice($product_id, $shop_id, $currency_id, $country_id, $group_id, $quantity, $product_attribute_id = null, $customer_id = 0, $cart_id = 0, $real_quantity = 0)
 {
     if (!JeproshopSpecificPriceModelSpecificPrice::isFeaturePublished()) {
         return array();
     }
     /*
      ** The date is not taken into account for the cache, but this is for the better because it keeps the consistency for the whole script.
      ** The price must not change between the top and the bottom of the page
      */
     $db = JFactory::getDBO();
     $key = (int) $product_id . '_' . (int) $shop_id . '_' . (int) $currency_id . '_' . (int) $country_id . '_' . (int) $group_id . '_' . (int) $quantity . '_' . (int) $product_attribute_id . '_' . (int) $cart_id . '_' . (int) $customer_id . '_' . (int) $real_quantity;
     if (!array_key_exists($key, JeproshopSpecificPriceModelSpecificPrice::$_specific_price_cache)) {
         $now = date('Y-m-d H:i:s');
         $query = "SELECT *, " . JeproshopSpecificPriceModelSpecificPrice::getScoreQuery($product_id, $shop_id, $currency_id, $country_id, $group_id, $customer_id);
         $query .= " FROM " . $db->quoteName('#__jeproshop_specific_price') . " WHERE " . $db->quoteName('product_id') . " IN (0, " . (int) $product_id . ") AND ";
         $query .= $db->quoteName('product_attribute_id') . " IN (0, " . (int) $product_attribute_id . ") AND " . $db->quoteName('shop_id') . " IN (0, " . (int) $shop_id;
         $query .= ") AND " . $db->quoteName('currency_id') . " IN (0, " . (int) $currency_id . ") AND " . $db->quoteName('country_id') . " IN (0, " . (int) $country_id;
         $query .= ") AND " . $db->quoteName('group_id') . " IN (0, " . (int) $group_id . ") AND " . $db->quoteName('customer_id') . " IN (0, " . (int) $customer_id . ") ";
         $query .= "AND ( (" . $db->quoteName('from') . " = '0000-00-00 00:00:00' OR '" . $now . "' >= " . $db->quoteName('from') . ") AND (" . $db->quoteName('to');
         $query .= " = '0000-00-00 00:00:00' OR '" . $now . "' <= " . $db->quoteName('to') . ") ) AND cart_id IN (0, " . (int) $cart_id . ") AND IF(" . $db->quoteName('from_quantity');
         $query .= " > 1, " . $db->quoteName('from_quantity') . ", 0) <= ";
         $query .= JeproshopSettingModelSetting::getValue('qty_discount_on_combination') || !$cart_id || !$real_quantity ? (int) $quantity : max(1, (int) $real_quantity);
         $query .= " ORDER BY " . $db->quoteName('product_attribute_id') . " DESC, " . $db->quoteName('from_quantity') . " DESC, " . $db->quoteName('specific_price_rule_id');
         $query .= " ASC, " . $db->quoteName('score') . " DESC";
         $db->setQuery($query);
         JeproshopSpecificPriceModelSpecificPrice::$_specific_price_cache[$key] = $db->loadObject();
         //Db::getInstance(_PS_USE_SQL_SLAVE_)->getRow($query);
     }
     return JeproshopSpecificPriceModelSpecificPrice::$_specific_price_cache[$key];
 }