Example #1
0
 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);
 }
Example #2
0
 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");
     }
 }
Example #3
0
 /**
  * deletes the Trusted Shops articles from the database if shop owner has
  * no Excellence service anymore
  *
  * @throws Exception
  * @throws NotFoundException
  * @throws ParameterMissingException
  */
 public function deleteTrustedShopsArticles()
 {
     $builder = $this->getQueryBuilder();
     $tsIds = $builder->getQuery()->getArrayResult();
     if (empty($tsIds)) {
         return;
     }
     /* @var Article $articleResource */
     $articleResource = new Article();
     $articleResource->setManager($this->em);
     try {
         foreach ($tsIds as $tsId) {
             $articleResource->delete($tsId['id']);
         }
     } catch (ValidationException $e) {
         $errors = array();
         /** @var ConstraintViolation $violation */
         foreach ($e->getViolations() as $violation) {
             $errors[] = sprintf('%s: %s', $violation->getPropertyPath(), $violation->getMessage());
         }
         throw new Exception(implode(', ', $errors));
     }
 }
Example #4
0
 /**
  * @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);
 }
Example #5
-1
 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);
     }
 }