From 8d002bbb8de2c8a82e0a97724965cc85c0db0982 Mon Sep 17 00:00:00 2001 From: David Herbert Date: Wed, 10 Dec 2014 15:42:03 +0000 Subject: [PATCH] Fix add image assets when creating product fixture Reorder product fixture creation to prevent save method being called prematurely when adding images to the media gallery. --- src/MageTest/MagentoExtension/Fixture/Product.php | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/src/MageTest/MagentoExtension/Fixture/Product.php b/src/MageTest/MagentoExtension/Fixture/Product.php index 64e9b00..62d8062 100644 --- a/src/MageTest/MagentoExtension/Fixture/Product.php +++ b/src/MageTest/MagentoExtension/Fixture/Product.php @@ -84,16 +84,16 @@ public function create(array $attributes) \Mage::app()->setCurrentStore(\Mage_Core_Model_App::ADMIN_STORE_ID); - $this->setProductImageAssets($attributes); - $this->model ->setWebsiteIds(array_map(function($website) { return $website->getId(); }, $websiteHelper->getWebsites())) ->setData($this->mergeAttributes($attributes)) - ->setCreatedAt(null) - ->getResource() - ->save($this->model); + ->setCreatedAt(null); + + $this->setProductImageAssets($attributes); + + $this->model->save(); \Mage::app()->setCurrentStore(\Mage_Core_Model_App::DISTRO_STORE_ID); @@ -218,9 +218,7 @@ private function setProductImageAssets(array $attributes) } $visibility = array('thumbnail', 'small_image', 'image'); - $this->model - ->addImageToMediaGallery($imagePath, $visibility, false, false) - ->save(); + $this->model->addImageToMediaGallery($imagePath, $visibility, false, false); } } }