コード例 #1
0
ファイル: ProductPrice.php プロジェクト: larryu/magento-b2b
 /**
  * (non-PHPdoc)
  * @see BaseEntityAbstract::preSave()
  */
 public function preSave()
 {
     if ($this->getStart()->afterOrEqualTo($this->getEnd())) {
         throw new EntityException('Error: Price(ID=' . $this->getId() . ') start(=' . $this->getStart() . ') must be earlier than end(=' . $this->getEnd() . ')!');
     }
     $where = 'active = 1 AND productId = :pId AND typeId = :typeId AND ( (start <= :start and :end <= end) or (:start <= start and :end <= end) or (start <= :start and end <= :end) or (:start <= start and end <= :end))';
     $params = array('pId' => $this->getProduct()->getId(), 'typeId' => $this->getType()->getId(), 'start' => trim($this->getStart()), 'end' => trim($this->getEnd()));
     if (($id = trim($this->getId())) !== '') {
         $where .= ' AND id != :id';
         $params['id'] = $id;
     }
     if (ProductPrice::countByCriteria($where, $params) > 0) {
         throw new EntityException('There is already a price for this product that covers time from "' . $this->getStart() . '" to "' . $this->getEnd() . '"');
     }
 }