Example #1
0
 /**
  * Get final price expression
  * 
  * @param Varien_Db_Adapter_Interface $write
  * @param Zend_Db_Expr $price
  * @param Zend_Db_Expr $specialPrice
  * @param Zend_Db_Expr $specialFrom
  * @param Zend_Db_Expr $specialTo
  * 
  * @return Zend_Db_Expr 
  */
 public function getFinalPriceExpr($write, $price, $specialPrice, $specialFrom, $specialTo)
 {
     if ($this->getVersionHelper()->isGe1600()) {
         $currentDate = $write->getDatePartSql('cwd.website_date');
         if ($this->getVersionHelper()->isGe1700()) {
             $groupPrice = $write->getCheckSql('gp.price IS NULL', "{$price}", 'gp.price');
         }
         $specialFromDate = $write->getDatePartSql($specialFrom);
         $specialToDate = $write->getDatePartSql($specialTo);
         $specialFromUse = $write->getCheckSql("{$specialFromDate} <= {$currentDate}", '1', '0');
         $specialToUse = $write->getCheckSql("{$specialToDate} >= {$currentDate}", '1', '0');
         $specialFromHas = $write->getCheckSql("{$specialFrom} IS NULL", '1', "{$specialFromUse}");
         $specialToHas = $write->getCheckSql("{$specialTo} IS NULL", '1', "{$specialToUse}");
         $finalPrice = $write->getCheckSql("{$specialFromHas} > 0 AND {$specialToHas} > 0" . " AND {$specialPrice} < {$price}", $specialPrice, $price);
         if ($this->getVersionHelper()->isGe1700()) {
             $finalPrice = $write->getCheckSql("{$groupPrice} < {$finalPrice}", $groupPrice, $finalPrice);
         }
     } else {
         $currentDate = new Zend_Db_Expr('cwd.date');
         $finalPrice = new Zend_Db_Expr("IF(IF({$specialFrom} IS NULL, 1, " . "IF(DATE({$specialFrom}) <= {$currentDate}, 1, 0)) > 0 AND IF({$specialTo} IS NULL, 1, " . "IF(DATE({$specialTo}) >= {$currentDate}, 1, 0)) > 0 AND {$specialPrice} < {$price}, " . "{$specialPrice}, {$price})");
     }
     return $finalPrice;
 }