/** * @covers Thelia\Action\ProductSaleElement::createClonePSE * @depends testCloneFile * @param ProductCloneEvent $event * @return ProductCloneEvent */ public function testCreateClonePSE(ProductCloneEvent $event) { $originalProductPSE = ProductSaleElementsQuery::create()->filterByProductId($event->getOriginalProduct()->getId())->findOne(); $currencyId = ProductPriceQuery::create()->filterByProductSaleElementsId($originalProductPSE->getId())->select('CURRENCY_ID')->findOne(); // Call function to test $action = new ProductSaleElement(); $clonedProductPSEId = $action->createClonePSE($event, $originalProductPSE, $currencyId); // Get created PSE $cloneProductPSE = ProductSaleElementsQuery::create()->findOneById($clonedProductPSEId); // Check clone PSE information $this->assertInstanceOf('Thelia\\Model\\ProductSaleElements', $cloneProductPSE, 'Instance of clone PSE must be Thelia\\Model\\ProductSaleElements'); $this->assertEquals($event->getClonedProduct()->getId(), $cloneProductPSE->getProductId(), 'ProductID must be equal'); $this->assertStringStartsWith($event->getClonedProduct()->getRef(), $cloneProductPSE->getRef(), 'PSE\'s ref must start with product\'s ref'); $this->assertEquals($originalProductPSE->getWeight(), $cloneProductPSE->getWeight(), 'Weight must be equal'); // Get attribute combination $originalAttributeCombination = AttributeCombinationQuery::create()->findOneByProductSaleElementsId($originalProductPSE->getId()); $cloneAttributeCombination = AttributeCombinationQuery::create()->findOneByProductSaleElementsId($clonedProductPSEId); // Check clone PSE's attribute combination if exist if ($cloneAttributeCombination != null) { $this->assertInstanceOf('Thelia\\Model\\AttributeCombination', $cloneAttributeCombination, 'Instance of clone PSE\'s attribute combination must be Thelia\\Model\\AttributeCombination'); $this->assertEquals($originalAttributeCombination->getAttributeId(), $cloneAttributeCombination->getAttributeId(), 'AttributeID must be equal'); $this->assertEquals($originalAttributeCombination->getAttributeAvId(), $cloneAttributeCombination->getAttributeAvId(), 'AttributeAvID must be equal'); $this->assertEquals($clonedProductPSEId, $cloneAttributeCombination->getProductSaleElementsId(), 'PSE ID must be equal'); } return ['event' => $event, 'originalPSE' => $originalProductPSE, 'clonePSE' => $cloneProductPSE]; }
public function cloneAssociatedContent(ProductCloneEvent $event) { // Get original product associated contents $originalProductAssocConts = ProductAssociatedContentQuery::create()->findByProductId($event->getOriginalProduct()->getId()); // Set clone product associated contents foreach ($originalProductAssocConts as $originalProductAssocCont) { $clonedProductCreatePAC = new ProductAddContentEvent($event->getClonedProduct(), $originalProductAssocCont->getContentId()); $event->getDispatcher()->dispatch(TheliaEvents::PRODUCT_ADD_CONTENT, $clonedProductCreatePAC); } }
public function cloneFileI18n($originalProductFileI18ns, $clonedProductFile, $type, ProductCloneEvent $event, EventDispatcherInterface $dispatcher) { // Set clone files I18n /** @var ProductDocumentI18n $originalProductFileI18n */ foreach ($originalProductFileI18ns as $originalProductFileI18n) { // Update file with current I18n info. Update or create I18n according to existing or absent Locale in DB $clonedProductFile->setLocale($originalProductFileI18n->getLocale())->setTitle($originalProductFileI18n->getTitle())->setDescription($originalProductFileI18n->getDescription())->setChapo($originalProductFileI18n->getChapo())->setPostscriptum($originalProductFileI18n->getPostscriptum()); // Create and dispatch event $clonedProductUpdateFileEvent = new FileCreateOrUpdateEvent($event->getClonedProduct()->getId()); $clonedProductUpdateFileEvent->setModel($clonedProductFile); switch ($type) { case 'images': $dispatcher->dispatch(TheliaEvents::IMAGE_UPDATE, $clonedProductUpdateFileEvent); break; case 'documents': $dispatcher->dispatch(TheliaEvents::DOCUMENT_UPDATE, $clonedProductUpdateFileEvent); break; } } }
public function updateClonePSE(ProductCloneEvent $event, $clonedProductPSEId, ProductSaleElements $originalProductPSE, $key) { $originalProductPSEPrice = ProductPriceQuery::create()->findOneByProductSaleElementsId($originalProductPSE->getId()); $clonedProductUpdatePSEEvent = new ProductSaleElementUpdateEvent($event->getClonedProduct(), $clonedProductPSEId); $clonedProductUpdatePSEEvent->setReference($event->getClonedProduct()->getRef() . '-' . ($key + 1))->setIsdefault($originalProductPSE->getIsDefault())->setFromDefaultCurrency(0)->setWeight($originalProductPSE->getWeight())->setQuantity($originalProductPSE->getQuantity())->setOnsale($originalProductPSE->getPromo())->setIsnew($originalProductPSE->getNewness())->setEanCode($originalProductPSE->getEanCode())->setTaxRuleId($event->getOriginalProduct()->getTaxRuleId())->setPrice($originalProductPSEPrice->getPrice())->setSalePrice($originalProductPSEPrice->getPromoPrice())->setCurrencyId($originalProductPSEPrice->getCurrencyId()); $this->eventDispatcher->dispatch(TheliaEvents::PRODUCT_UPDATE_PRODUCT_SALE_ELEMENT, $clonedProductUpdatePSEEvent); }
public function cloneAccessories(ProductCloneEvent $event) { // Get original product accessories $originalProductAccessoryList = AccessoryQuery::create()->findByProductId($event->getOriginalProduct()->getId()); // Set clone product accessories foreach ($originalProductAccessoryList as $originalProductAccessory) { $clonedProductAddAccessoryEvent = new ProductAddAccessoryEvent($event->getClonedProduct(), $originalProductAccessory->getAccessory()); $event->getDispatcher()->dispatch(TheliaEvents::PRODUCT_ADD_ACCESSORY, $clonedProductAddAccessoryEvent); } }