/** * @depends testGetOneShouldBeSuccessful * @param $article\Shopware\Models\Article\Article */ public function testDeleteShouldBeSuccessful($article) { $this->resource->setResultMode(\Shopware\Components\Api\Resource\Variant::HYDRATE_OBJECT); $deleteByNumber = true; /** @var $articleDetail \Shopware\Models\Article\Detail */ foreach ($article->getDetails() as $articleDetail) { $deleteByNumber = !$deleteByNumber; if ($deleteByNumber) { $result = $this->resource->delete($articleDetail->getId()); } else { $result = $this->resource->deleteByNumber($articleDetail->getNumber()); } $this->assertInstanceOf('\\Shopware\\Models\\Article\\Detail', $result); $this->assertEquals(null, $result->getId()); } // Delete the whole article at last $this->resourceArticle->delete($article->getId()); }
public function testAssignCategoriesByPathShouldBeSuccessful() { // Delete previous data try { $id = $this->resource->getIdFromNumber('hollo-1'); if (!empty($id)) { $this->resource->delete($id); } } catch (Exception $e) { } // Associate three kinds of categories with the article: // category by id, category by path, new category by path $article = $this->resource->create(array('name' => 'Hähnchenschnitzel Hollo', 'active' => true, 'tax' => 19, 'supplier' => 'Onkel Tom', 'categories' => array(array('path' => 'Deutsch|Genusswelten|Tees und Zubehör|Tees'), array('path' => 'Deutsch|Genusswelten|Tees und Zubehör|Süßstoff'), array('id' => 16)), 'mainDetail' => array('number' => 'hollo-1', 'prices' => array(array('customerGroupKey' => 'EK', 'price' => 4.99))))); $ids = array_map(function ($category) { return $category->getId(); }, $article->getCategories()->toArray()); $ids = array_flip($ids); $this->assertArrayHasKey(12, $ids); $this->assertArrayHasKey(16, $ids); $this->assertCount(3, $ids); }
/** * 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)); } }