diff --git a/spec/MageTest/MagentoExtension/Fixture/ProductSpec.php b/spec/MageTest/MagentoExtension/Fixture/ProductSpec.php index c9be2ba..8cb26b3 100644 --- a/spec/MageTest/MagentoExtension/Fixture/ProductSpec.php +++ b/spec/MageTest/MagentoExtension/Fixture/ProductSpec.php @@ -70,6 +70,8 @@ function let() $this->model->shouldReceive('getResource')->andReturn($productResourceModel); $this->model->shouldReceive('getAttributes')->andReturn(array()); + $this->model->shouldReceive('setAttributeSetId')->andReturn($productModel); + $this->model->shouldReceive('setTypeId')->andReturn($productModel); } function it_should_throw_exception_if_sku_is_not_defined() @@ -221,4 +223,23 @@ function it_should_load_object_and_delete_it_when_delete_is_requested() $this->delete(554); } + + function it_should_fill_attribute_set_and_type_id_before_loading_attributes() + { + $productData = array( + 'sku' => 'test_sku', + 'attribute_set_id' => 123, + ); + + $this->model->shouldReceive('setData')->andReturn($this->model); + $this->model->shouldReceive('setCreatedAt')->andReturn($this->model); + $this->model->shouldReceive('setWebsiteIds')->andReturn($this->model); + $this->model->shouldReceive('getIdBySku')->andReturn(false); + + $this->model->shouldReceive('setAttributeSetId')->with(123)->once()->ordered(); + $this->model->shouldReceive('setTypeId')->with('simple')->atLeast()->once()->ordered(); + $this->model->shouldReceive('getAttributes')->atLeast()->once()->ordered(); + + $this->create($productData); + } } diff --git a/src/MageTest/MagentoExtension/Fixture/Product.php b/src/MageTest/MagentoExtension/Fixture/Product.php index 64e9b00..f113e4c 100644 --- a/src/MageTest/MagentoExtension/Fixture/Product.php +++ b/src/MageTest/MagentoExtension/Fixture/Product.php @@ -80,6 +80,10 @@ public function create(array $attributes) $this->model->setTypeId($attributes['type_id']); } + if (!empty($attributes['attribute_set_id'])) { + $this->model->setAttributeSetId($attributes['attribute_set_id']); + } + $this->validateAttributes(array_keys($attributes)); \Mage::app()->setCurrentStore(\Mage_Core_Model_App::ADMIN_STORE_ID); @@ -169,6 +173,11 @@ private function attributeExists($attribute) protected function getDefaultAttributes() { $productModel = $this->serviceContainer['productModel'](); + + if ($productModel->getTypeId() == '') { + $productModel->setTypeId(\Mage_Catalog_Model_Product_Type::TYPE_SIMPLE); + } + $typeId = $productModel->getTypeId(); if ($this->defaultAttributes[$typeId]) {