/** * @param array $data * @dataProvider aroundGetStockItemDataProvider */ public function testAroundGetStockItem(array $data) { $subjectMock = $this->getMock('Magento\\CatalogInventory\\Model\\Quote\\Item\\QuantityValidator\\Initializer\\Option', [], [], '', false); $quoteItemMock = $this->getMock('Magento\\Quote\\Model\\Quote\\Item', ['getProductType', '__wakeup'], [], '', false); $quoteItemMock->expects($this->once())->method('getProductType')->will($this->returnValue($data['product_type'])); $stockItemMock = $this->getMock('Magento\\CatalogInventory\\Model\\Stock\\Item', ['setProductName', '__wakeup'], [], '', false); $matcherMethod = $data['matcher_method']; $stockItemMock->expects($this->{$matcherMethod}())->method('setProductName'); $optionMock = $this->getMock('Magento\\Quote\\Model\\Quote\\Item\\Option', ['getProduct', '__wakeup'], [], '', false); $proceed = function () use($stockItemMock) { return $stockItemMock; }; $model = new ConfigurableProduct(); $model->aroundGetStockItem($subjectMock, $proceed, $optionMock, $quoteItemMock, 0); }
$dataWritten = false; $writer = new CsvWriter($feedFilename); $productIds = Mage::getModel('catalog/product')->getCollection()->addAttributeToFilter('type_id', array('eq' => 'configurable'))->addAttributeToFilter('status', array('eq' => Mage_Catalog_Model_Product_Status::STATUS_ENABLED))->getAllIds(); $open = count($productIds); foreach ($productIds as $id) { $product = Mage::getModel('catalog/product')->load($id); $websites = $product->getWebsiteIds(); if (!inMainStore($websites)) { $websites = implode(",", $websites); echo "[wrong website] skip {$id}, websites: {$websites}\n"; $skippedProducts++; continue; } $data = []; $categoryData = []; $configProduct = new ConfigurableProduct($product); $categories = $configProduct->getCategoryIds(); $hasActiveCategories = false; echo sprintf("(%s) %s %s\n", --$open, str_pad($configProduct->getId(), 5), str_pad($configProduct->getName(), 30)); foreach ($categories as $categoryId) { $category = new Category($categoryId); if ($category->isVisible() && strlen($category->getName()) > 0 && !$category->isExcluded()) { if ($hasActiveCategories) { $categoryData['alternateCategoryId'][] = $categoryId; $categoryData['alternateCategoryName'][] = $category->getName(); $categoryData['alternateCategoryTree'][] = $category->getCategoryTree(); } else { $categoryData['defaultCategoryId'] = $categoryId; $categoryData['defaultCategoryName'] = $category->getName(); $categoryData['defaultCategoryTree'] = $category->getCategoryTree(); $categoryData['productType'] = $category->getName();
/** * insert product function * @return Object */ public function procShopToolInsertProduct() { $shopModel = $this->model; $productRepository = $shopModel->getProductRepository(); $imageRepository = $shopModel->getImageRepository(); $args = Context::getRequestVars(); if(is_array($args->filesToUpload)) $args->images = $imageRepository->createImagesUploadedFiles($args->filesToUpload); if(!isset($args->primary_image) && isset($args->images)) $args->images[0]->is_primary = 'Y'; if(isset($args->primary_image) && isset($args->images[$args->primary_image])) { $args->images[$args->primary_image]->is_primary = 'Y'; unset($args->primary_image); } $logged_info = Context::get('logged_info'); $args->member_srl = $logged_info->member_srl; $args->module_srl = $this->module_info->module_srl; if($args->product_type == 'simple') { $product = new SimpleProduct($args); } else { $product = new ConfigurableProduct($args); } try { if (!$product->isPersisted()) { $productRepository->insertProduct($product); if ($product->isSimple()) { $this->setMessage("Saved simple product successful"); $returnUrl = getNotEncodedUrl('', 'act', 'dispShopToolManageProducts'); } else { $this->setMessage("Saved configurable product successful"); $returnUrl = getNotEncodedUrl('', 'act', 'dispShopToolAddAssociatedProducts','product_srl',$product->product_srl); } } else { $product->delete_images = $args->delete; $productRepository->updateProduct($product); if ($product->isSimple()) { $this->setMessage("Updated simple product successfull"); } else { $this->setMessage("Updated configurable product successfull"); } if ($product->isSimple() && $product->parent_product_srl) { $returnUrl = getNotEncodedUrl('', 'act', 'dispShopToolEditProduct', 'product_srl', $product->parent_product_srl); } else { $returnUrl = getNotEncodedUrl('', 'act', 'dispShopToolManageProducts'); } } $productRepository->updatePrimaryImageFilename($product); } catch(Exception $e) { return new Object(-1, $e->getMessage()); } $this->setRedirectUrl($returnUrl); }