protected function insert() { $this->product->get()->updateCategoryCounters($this->product->get()->getCountUpdateFilter(), $this->category->get()); $this->product->get()->registerAdditionalCategory($this->category->get()); $insertResult = parent::insert(); Category::updateCategoryIntervals($this->product->get()); return $insertResult; }
/** * @todo move the SKU checking to insert() - otherwise seems to break some tests for now */ public function save($forceOperation = null) { self::beginTransaction(); if ($this->manufacturer->get()) { $this->manufacturer->get()->save(); } // update parent inventory counter if ($this->stockCount->isModified() && $this->parent->get()) { $stockDifference = $this->stockCount->get() - $this->stockCount->getInitialValue(); $this->parent->get()->stockCount->set($this->parent->get()->stockCount->get() + $stockDifference); $this->parent->get()->save(); } parent::save($forceOperation); // generate SKU automatically if not set if (!$this->sku->get()) { ClassLoader::import('application.helper.check.IsUniqueSkuCheck'); if (!$this->parent->get()) { $sku = $this->getID(); do { $check = new IsUniqueSkuCheck('', $this); $exists = $check->isValid('SKU' . $sku); if (!$exists) { $sku = '0' . $sku; } } while (!$exists); $sku = 'SKU' . $sku; } else { $sku = $this->parent->get()->sku->get() . '-'; $k = 0; do { $k++; $check = new IsUniqueSkuCheck('', $this); $exists = $check->isValid($sku . $k); } while (!$exists); $sku .= $k; } $this->sku->set($sku); parent::save(); } $this->getSpecification()->save(); $this->getPricingHandler()->save(); $this->saveRelationships(); Category::updateCategoryIntervals($this->getID()); self::commit(); }