/** * @param Market_ProductModel $product * * @return bool * @throws Exception * @throws \Exception */ public function save(Market_ProductModel $product) { if (!$product->id) { $record = new Market_ProductRecord(); } else { $record = Market_ProductRecord::model()->findById($product->id); if (!$record) { throw new Exception(Craft::t('No product exists with the ID “{id}”', ['id' => $product->id])); } } $record->availableOn = $product->availableOn; $record->expiresOn = $product->expiresOn; $record->typeId = $product->typeId; $record->authorId = $product->authorId; $record->promotable = $product->promotable; $record->freeShipping = $product->freeShipping; $record->taxCategoryId = $product->taxCategoryId; $record->validate(); $product->addErrors($record->getErrors()); MarketDbHelper::beginStackedTransaction(); try { if (!$product->hasErrors()) { if (craft()->elements->saveElement($product)) { $record->id = $product->id; $record->save(false); MarketDbHelper::commitStackedTransaction(); return true; } } } catch (\Exception $e) { MarketDbHelper::rollbackStackedTransaction(); throw $e; } MarketDbHelper::rollbackStackedTransaction(); return false; }