Ejemplo n.º 1
0
 /**
  * Change a product
  *
  * @param \Thelia\Core\Event\Product\ProductUpdateEvent $event
  */
 public function update(ProductUpdateEvent $event)
 {
     if (null !== ($product = ProductQuery::create()->findPk($event->getProductId()))) {
         $product->setDispatcher($event->getDispatcher())->setRef($event->getRef())->setLocale($event->getLocale())->setTitle($event->getTitle())->setDescription($event->getDescription())->setChapo($event->getChapo())->setPostscriptum($event->getPostscriptum())->setVisible($event->getVisible() ? 1 : 0)->setVirtual($event->getVirtual() ? 1 : 0)->setBrandId($event->getBrandId() <= 0 ? null : $event->getBrandId())->save();
         // Update default category (ifd required)
         $product->updateDefaultCategory($event->getDefaultCategory());
         $event->setProduct($product);
     }
 }
Ejemplo n.º 2
0
 /**
  * Change a product
  *
  * @param \Thelia\Core\Event\Product\ProductUpdateEvent $event
  */
 public function update(ProductUpdateEvent $event)
 {
     if (null !== ($product = ProductQuery::create()->findPk($event->getProductId()))) {
         $con = Propel::getWriteConnection(ProductTableMap::DATABASE_NAME);
         $con->beginTransaction();
         try {
             $product->setDispatcher($event->getDispatcher())->setRef($event->getRef())->setLocale($event->getLocale())->setTitle($event->getTitle())->setDescription($event->getDescription())->setChapo($event->getChapo())->setPostscriptum($event->getPostscriptum())->setVisible($event->getVisible() ? 1 : 0)->setVirtual($event->getVirtual() ? 1 : 0)->setBrandId($event->getBrandId() <= 0 ? null : $event->getBrandId())->save($con);
             // Update default category (ifd required)
             $product->updateDefaultCategory($event->getDefaultCategory());
             $event->setProduct($product);
             $con->commit();
         } catch (PropelException $e) {
             $con->rollBack();
             throw $e;
         }
     }
 }
Ejemplo n.º 3
0
 /**
  * Change a product
  *
  * @param \Thelia\Core\Event\Product\ProductUpdateEvent $event
  */
 public function update(ProductUpdateEvent $event)
 {
     if (null !== ($product = ProductQuery::create()->findPk($event->getProductId()))) {
         $con = Propel::getWriteConnection(ProductTableMap::DATABASE_NAME);
         $con->beginTransaction();
         try {
             $prevRef = $product->getRef();
             $product->setDispatcher($event->getDispatcher())->setRef($event->getRef())->setLocale($event->getLocale())->setTitle($event->getTitle())->setDescription($event->getDescription())->setChapo($event->getChapo())->setPostscriptum($event->getPostscriptum())->setVisible($event->getVisible() ? 1 : 0)->setVirtual($event->getVirtual() ? 1 : 0)->setBrandId($event->getBrandId() <= 0 ? null : $event->getBrandId())->save($con);
             // Update default PSE (if product has no attributes and the product's ref change)
             $defaultPseRefChange = $prevRef !== $product->getRef() && 0 === $product->getDefaultSaleElements()->countAttributeCombinations();
             if ($defaultPseRefChange) {
                 $defaultPse = $product->getDefaultSaleElements();
                 $defaultPse->setRef($product->getRef())->save();
             }
             // Update default category (if required)
             $product->updateDefaultCategory($event->getDefaultCategory());
             $event->setProduct($product);
             $con->commit();
         } catch (PropelException $e) {
             $con->rollBack();
             throw $e;
         }
     }
 }
Ejemplo n.º 4
0
 /**
  * @param ProductUpdateEvent $updateEvent
  *
  * @return Response
  */
 protected function performAdditionalUpdateAction($updateEvent)
 {
     // Associate the file if it's a virtual product
     // and with only 1 PSE
     $virtualDocumentId = intval($updateEvent->getVirtualDocumentId());
     if ($virtualDocumentId >= 0) {
         $defaultPSE = ProductSaleElementsQuery::create()->filterByProductId($updateEvent->getProductId())->filterByIsDefault(true)->findOne();
         if (null !== $defaultPSE) {
             if ($virtualDocumentId !== 0) {
                 $assocEvent = new MetaDataCreateOrUpdateEvent('virtual', MetaData::PSE_KEY, $defaultPSE->getId(), $virtualDocumentId);
                 $this->dispatch(TheliaEvents::META_DATA_UPDATE, $assocEvent);
             } else {
                 $assocEvent = new MetaDataDeleteEvent('virtual', MetaData::PSE_KEY, $defaultPSE->getId());
                 $this->dispatch(TheliaEvents::META_DATA_DELETE, $assocEvent);
             }
         }
     }
     return null;
 }