/** * Internal helper function to duplicate the article link configuration from the passed article * to the new article. * @param $articleId * @param $newArticleId */ protected function duplicateArticleLinks($articleId, $newArticleId) { $article = Shopware()->Models()->find('Shopware\\Models\\Article\\Article', $newArticleId); $builder = Shopware()->Models()->createQueryBuilder(); $links = $builder->select(array('links', 'attribute'))->from('Shopware\\Models\\Article\\Link', 'links')->leftJoin('links.attribute', 'attribute')->where('links.articleId = ?1')->setParameter(1, $articleId)->getQuery()->getArrayResult(); foreach ($links as $data) { $link = new \Shopware\Models\Article\Link(); $link->fromArray($data); $link->setArticle($article); Shopware()->Models()->persist($link); } Shopware()->Models()->flush(); }
public function testCanUpdateOneToMany() { $article = new Article(); $link0 = new \Shopware\Models\Article\Link(); $link0->setName('dummy'); $link0->setLink('lorem'); $this->setProperty($link0, 'id', 1); $article->getLinks()->add($link0); $this->assertContains($link0, $article->getLinks()); $data = array('links' => array(array('id' => 2, 'name' => 'batz'))); $article->fromArray($data); $this->assertCount(1, $article->getLinks()); $this->assertNotContains($link0, $article->getLinks()); $this->assertEquals('batz', $article->getLinks()->first()->getName()); }