| 1 | <?php |
||
| 13 | class GroupedProduct extends Product |
||
| 14 | { |
||
| 15 | private $_groupedProducts = []; |
||
| 16 | private $_groupedProductsIds = []; |
||
| 17 | |||
| 18 | public function build() |
||
| 19 | { |
||
| 20 | $mergedData = $this->_beforeBuild(); |
||
| 21 | $this->_buildGroupedSimpleProducts(); |
||
| 22 | $this->_getMageModel()->setData($mergedData); |
||
| 23 | $fixtureId = $this->_saveFixture(); |
||
| 24 | $this->_linkSimpleProducts($fixtureId); |
||
| 25 | |||
| 26 | return $fixtureId; |
||
| 27 | } |
||
| 28 | |||
| 29 | /** |
||
| 30 | * @param int $groupedProductId |
||
| 31 | */ |
||
| 32 | protected function _linkSimpleProducts($groupedProductId) |
||
| 33 | { |
||
| 34 | $this->_prepareProductIds(); |
||
| 35 | $productLinkApi = Mage::getModel('catalog/product_link_api'); |
||
| 36 | $iterator = new \ArrayIterator($this->_groupedProductsIds); |
||
| 37 | while ($iterator->valid()) { |
||
| 38 | $productLinkApi->assign( |
||
| 39 | Mage_Catalog_Model_Product_Type::TYPE_GROUPED, $groupedProductId, $iterator->current() |
||
| 40 | ); |
||
| 41 | $iterator->next(); |
||
| 42 | } |
||
| 43 | } |
||
| 44 | |||
| 45 | protected function _buildGroupedSimpleProducts() |
||
| 49 | |||
| 50 | protected function _prepareProductIds() |
||
| 51 | { |
||
| 59 | |||
| 60 | } |
||
| 61 |