Пример #1
0
 /**
  * Updates product record
  *
  */
 protected function update()
 {
     ActiveRecordModel::beginTransaction();
     try {
         // modify product counters for categories
         $catUpdate = new ARUpdateFilter();
         // determines the changes for activeProductCount and availableProductCount fields
         $activeChange = 0;
         $availableChange = 0;
         // when isEnabled flag is modified the activeProductCount will always either increase or decrease
         if ($this->isEnabled->isModified()) {
             $activeChange = $this->isEnabled->get() ? 1 : -1;
             // when the stock count is larger than 0, the availableProductCount should also change by one
             if ($this->isDownloadable() || !$this->stockCount->isModified() && $this->stockCount->get() > 0) {
                 $availableChange = $this->isEnabled->get() ? 1 : -1;
             }
         }
         if ($this->stockCount->isModified() && $this->isEnabled->get()) {
             // decrease available product count
             if ($this->stockCount->get() == 0 && $this->stockCount->getInitialValue() > 0) {
                 $availableChange = -1;
             } else {
                 if ($this->stockCount->get() > 0 && $this->stockCount->getInitialValue() == 0) {
                     $availableChange = 1;
                 }
             }
         }
         if ($activeChange != 0) {
             $catUpdate->addModifier('activeProductCount', new ARExpressionHandle('activeProductCount ' . ($activeChange > 0 ? '+' : '-') . ' 1'));
         }
         if ($availableChange != 0) {
             $catUpdate->addModifier('availableProductCount', new ARExpressionHandle('availableProductCount ' . ($availableChange > 0 ? '+' : '-') . ' 1'));
         }
         parent::update();
         if (!$this->isLoaded()) {
             $this->load(array('Category'));
         }
         if ($this->category->get()) {
             $this->updateCategoryCounters($catUpdate, $this->category->get());
         }
         $update = new ARUpdateFilter();
         $update->addModifier('dateUpdated', new ARExpressionHandle('NOW()'));
         $update->setCondition(new EqualsCond(new ARFieldHandle(__CLASS__, 'ID'), $this->getID()));
         ActiveRecordModel::updateRecordSet(__CLASS__, $update);
         ActiveRecordModel::commit();
     } catch (Exception $e) {
         ActiveRecordModel::rollback();
         throw $e;
     }
 }
Пример #2
0
 protected function update()
 {
     if (is_null($this->shipment->get()) || !$this->shipment->get()->getID()) {
         $this->shipment->setNull(false);
         $this->shipment->resetModifiedStatus();
     }
     if ($this->isModified()) {
         $user = $this->customerOrder->get()->user->get();
         if ($user) {
             $user->load();
         }
         if ($this->price->isNull()) {
             $this->price->set($this->getProduct()->getItemPrice($this));
         }
         return parent::update();
     } else {
         return false;
     }
 }