public function testSeoCategory() { $this->dispatch("/"); $data = $this->getSimpleTestData(); $data['categories'] = Shopware()->Db()->fetchAll("SELECT DISTINCT id FROM s_categories LIMIT 5, 10"); $first = $data['categories'][3]; $second = $data['categories'][4]; $data['seoCategories'] = array(array('shopId' => 1, 'categoryId' => $first['id']), array('shopId' => 2, 'categoryId' => $second['id'])); $article = $this->resource->create($data); $this->resource->setResultMode(Shopware\Components\Api\Resource\Resource::HYDRATE_OBJECT); /**@var $article Shopware\Models\Article\Article*/ $article = $this->resource->getOne($article->getId()); $german = Shopware()->Modules()->Categories()->sGetCategoryIdByArticleId($article->getId(), null, 1); $english = Shopware()->Modules()->Categories()->sGetCategoryIdByArticleId($article->getId(), null, 2); $this->assertEquals($first['id'], $german); $this->assertEquals($second['id'], $english); }
public function testCategoryAssignment() { $number = 'CategoryAssignment' . uniqid(); $data = $this->getSimpleTestData(); $data['mainDetail']['number'] = $number; $categories = Shopware()->Db()->fetchAll("SELECT id FROM s_categories WHERE parent = 3 ORDER BY id LIMIT 2"); $data['categories'] = $categories; $article = $this->resource->create($data); $normal = Shopware()->Db()->fetchCol("SELECT categoryID FROM s_articles_categories WHERE articleID = ?", array($article->getId())); $denormalized = Shopware()->Db()->fetchCol("SELECT categoryID FROM s_articles_categories_ro WHERE articleID = ?", array($article->getId())); $this->assertCount(2, $normal); $this->assertCount(4, $denormalized); foreach ($categories as $category) { $this->assertContains($category['id'], $normal); $this->assertContains($category['id'], $denormalized); } $rewriteCategories = Shopware()->Db()->fetchAll("SELECT id FROM s_categories WHERE parent = 3 ORDER BY id LIMIT 2, 2"); $data = array('categories' => $rewriteCategories); $this->resource->update($article->getId(), $data); $normal = Shopware()->Db()->fetchCol("SELECT categoryID FROM s_articles_categories WHERE articleID = ?", array($article->getId())); $denormalized = Shopware()->Db()->fetchCol("SELECT categoryID FROM s_articles_categories_ro WHERE articleID = ?", array($article->getId())); $this->assertCount(2, $normal); $this->assertCount(4, $denormalized); foreach ($rewriteCategories as $category) { $this->assertContains($category['id'], $normal); $this->assertContains($category['id'], $denormalized, "Denormalized array contains not the expected category id"); } $additionally = Shopware()->Db()->fetchAll("SELECT id FROM s_categories WHERE parent = 3 ORDER BY id LIMIT 2"); $data = array('__options_categories' => array('replace' => false), 'categories' => $additionally); $this->resource->update($article->getId(), $data); $normal = Shopware()->Db()->fetchCol("SELECT categoryID FROM s_articles_categories WHERE articleID = ?", array($article->getId())); $denormalized = Shopware()->Db()->fetchCol("SELECT categoryID FROM s_articles_categories_ro WHERE articleID = ?", array($article->getId())); $this->assertCount(4, $normal); $this->assertCount(8, $denormalized); foreach ($rewriteCategories as $category) { $this->assertContains($category['id'], $normal); $this->assertContains($category['id'], $denormalized, "Denormalized array contains not the expected category id"); } foreach ($additionally as $category) { $this->assertContains($category['id'], $normal); $this->assertContains($category['id'], $denormalized, "Denormalized array contains not the expected category id"); } }
/** * create the TS-Article * * @param array $articleData * @throws NotFoundException * @throws ParameterMissingException * @throws ValidationException */ private function createArticle(array $articleData) { /* @var Article $articleResource */ $articleResource = new Article(); $articleResource->setManager($this->em); $articleDetailRepostiory = $this->em->getRepository('Shopware\\Models\\Article\\Detail'); $articleDetailModel = $articleDetailRepostiory->findOneBy(array('number' => $articleData['mainDetail']['number'])); /* @var ArticleModel $articleModel */ $articleModel = null; if ($articleDetailModel) { if ($this->checkIfArticleExists($articleDetailModel)) { $articleModel = $articleDetailModel->getArticle(); } else { $this->deleteDetail($articleDetailModel); } } if ($articleModel) { $articleResource->update($articleModel->getId(), $articleData); $this->createArticleTranslation($articleModel, true); } else { $newArticle = $articleResource->create($articleData); $this->createArticleTranslation($newArticle); } }
/** * @param array $data * @return Models\Article\Article */ public function createArticle(array $data) { $this->removeArticle($data['mainDetail']['number']); $this->createdProducts[] = $data['mainDetail']['number']; return $this->articleApi->create($data); }
public function testNewConfiguratorOptionForVariant() { $data = $this->getSimpleArticleData(); $data['mainDetail'] = $this->getSimpleVariantData(); $configuratorSet = $this->getSimpleConfiguratorSet(1, 2); $data['configuratorSet'] = $configuratorSet; $article = $this->resourceArticle->create($data); // Create 5 new variants $batchData = array(); $names = array(); for ($i = 0; $i < 5; $i++) { $create = $this->getSimpleVariantData(); $create['articleId'] = $article->getId(); $options = $this->getVariantOptionsOfSet($configuratorSet); unset($options[0]['optionId']); $name = 'New-' . uniqid(); $names[] = $name; $options[0]['option'] = $name; $create['configuratorOptions'] = $options; $batchData[] = $create; } // Run batch operations $result = $this->resource->batch($batchData); $this->resource->setResultMode(\Shopware\Components\Api\Resource\Resource::HYDRATE_ARRAY); foreach ($result as $operation) { $this->assertTrue($operation['success']); $variant = $this->resource->getOne($operation['data']['id']); $this->assertCount(1, $variant['configuratorOptions']); $option = $variant['configuratorOptions'][0]; $this->assertContains($option['name'], $names); } }