コード例 #1
0
 /**
  * Converts Article categories to ProductModel categories.
  *
  * @param Article         $entity
  * @param ProductDocument $document
  */
 protected function extractCategories(Article $entity, ProductDocument $document)
 {
     try {
         $categories = [];
         /** @var ObjectToCategory $relation */
         foreach ($entity->getCategories() as $relation) {
             if ($relation->getCategory()->isActive()) {
                 $categories[] = $relation->getCategory()->getId();
             }
         }
         $document->setCategories($categories);
     } catch (EntityNotFoundException $exception) {
         // No categories. Just ignore.
     }
 }
コード例 #2
0
 /**
  * Test for modify().
  */
 public function testModify()
 {
     /** @var Article $parent */
     $parent = $this->getMockForAbstractClass('ONGR\\OXIDConnectorBundle\\Entity\\Article');
     $parent->setId('parentId');
     /** @var Category $category */
     $category = $this->getMockForAbstractClass('ONGR\\OXIDConnectorBundle\\Entity\\Category');
     $category->setId('inactiveCategoryId');
     $category->setActive(false);
     /** @var Category $activeCategory */
     $activeCategory = $this->getMockForAbstractClass('ONGR\\OXIDConnectorBundle\\Entity\\Category');
     $activeCategory->setId('activeCategoryId');
     $activeCategory->setActive(true);
     /** @var ArticleToCategory $objToCat */
     $objToCat = $this->getMockForAbstractClass('ONGR\\OXIDConnectorBundle\\Entity\\ArticleToCategory');
     $objToCat->setCategory($category);
     /** @var ArticleToCategory $activeObjToCat */
     $activeObjToCat = $this->getMockForAbstractClass('ONGR\\OXIDConnectorBundle\\Entity\\ArticleToCategory');
     $activeObjToCat->setCategory($activeCategory);
     /** @var ArticleExtension $extension */
     $extension = $this->getMockForAbstractClass('ONGR\\OXIDConnectorBundle\\Entity\\ArticleExtension');
     $extension->setLongDesc('Long description');
     /** @var Vendor $vendor */
     $vendor = $this->getMockForAbstractClass('ONGR\\OXIDConnectorBundle\\Entity\\Vendor');
     $vendor->setTitle('Vendor A');
     /** @var Manufacturer $manufacturer */
     $manufacturer = $this->getMockForAbstractClass('ONGR\\OXIDConnectorBundle\\Entity\\Manufacturer');
     $manufacturer->setTitle('Manufacturer A');
     /** @var Article $entity */
     $entity = $this->getMockForAbstractClass('ONGR\\OXIDConnectorBundle\\Entity\\Article');
     // Attribute to be added to Category.
     $attribute = new Attribute();
     $attribute->setId(123);
     $attribute->setPos(1);
     $attribute->setTitle('testAttributeTitle');
     $artToAttr = new ArticleToAttribute();
     $artToAttr->setId(321);
     $artToAttr->setPos(1);
     $artToAttr->setArticle($entity);
     $artToAttr->setAttribute($attribute);
     $entity->setId('id123')->setActive(true)->setArtNum('abc123')->setTitle('Any title')->setShortDesc('Short description')->setPrice(12.34)->setTPrice(43.21)->setExtension($extension)->addCategory($objToCat)->addCategory($activeObjToCat)->setStock(5)->setStockFlag(1)->setVendor($vendor)->setManufacturer($manufacturer)->addAttribute($artToAttr);
     $entity->setVariants($this->getVariants($entity));
     $expectedDocument = new ProductDocument();
     $expectedDocument->setId('id123');
     $expectedDocument->setActive(true);
     $expectedDocument->setSku('abc123');
     $expectedDocument->setTitle('Any title');
     $expectedDocument->setDescription('Short description');
     $expectedDocument->setPrice(12.34);
     $expectedDocument->setOldPrice(43.21);
     $expectedDocument->setLongDescription('Long description');
     $expectedDocument->setCategories(['activeCategoryId']);
     $expectedDocument->setStock(5);
     $expectedDocument->setVendor('Vendor A');
     $expectedDocument->setManufacturer('Manufacturer A');
     $expectedDocument->setVariants($this->getExpectedVariants());
     $expectedDocument->setUrls(new \ArrayIterator());
     $expectedDocument->setExpiredUrls([]);
     $attObj = new AttributeObject();
     $attObj->setPos(1);
     $attObj->setTitle('testAttributeTitle');
     $expectedDocument->setAttributes([$attObj]);
     $document = new ProductDocument();
     /** @var ItemPipelineEvent|\PHPUnit_Framework_MockObject_MockObject $event */
     $event = $this->getMock('ONGR\\ConnectionsBundle\\Pipeline\\Event\\ItemPipelineEvent', [], [], '', false);
     $this->modifier->modify(new ImportItem($entity, $document), $event);
     $this->assertEquals($expectedDocument, $document);
 }