Пример #1
0
 /**
  * Calculate the price for a product, applying rules and coupons
  *
  * @param    float
  * @param    object
  * @param    string
  * @param    int
  * @return float
  */
 public function calculatePrice($fltPrice, $objSource, $strField, $intTaxClass)
 {
     if ($objSource instanceof IsotopePrice && ($strField == 'price' || $strField == 'low_price' || $strField == 'net_price' || $strField == 'gross_price')) {
         // @todo try not to use getRelated() because it loads variants
         $objRules = Rule::findByProduct($objSource->getRelated('pid'), $strField, $fltPrice);
         if (null !== $objRules) {
             while ($objRules->next()) {
                 // Check cart quantity
                 if ($objRules->minItemQuantity > 0 || $objRules->maxItemQuantity > 0) {
                     if ($objRules->quantityMode == 'cart_products') {
                         $intTotal = Isotope::getCart()->countItems();
                     } elseif ($objRules->quantityMode == 'cart_items') {
                         $intTotal = Isotope::getCart()->sumItemsQuantity();
                     } else {
                         $objItem = Isotope::getCart()->getItemForProduct($objSource->getRelated('pid'));
                         $intTotal = null === $objItem ? 0 : $objItem->quantity;
                     }
                     if ($objRules->minItemQuantity > 0 && $objRules->minItemQuantity > $intTotal || $objRules->maxItemQuantity > 0 && $objRules->maxItemQuantity < $intTotal) {
                         continue;
                     }
                 }
                 // We're unable to apply variant price rules to low_price (see #3189)
                 if ($strField == 'low_price' && $objRules->productRestrictions == 'variants') {
                     continue;
                 }
                 if ($objRules->current()->isPercentage()) {
                     $fltDiscount = 100 + $objRules->current()->getPercentage();
                     $fltDiscount = round($fltPrice - $fltPrice / 100 * $fltDiscount, 10);
                     $fltDiscount = $fltDiscount > 0 ? floor($fltDiscount * 100) / 100 : ceil($fltDiscount * 100) / 100;
                     $fltPrice = $fltPrice - $fltDiscount;
                 } else {
                     $fltPrice = $fltPrice + $objRules->discount;
                 }
             }
         }
     }
     return $fltPrice;
 }