Пример #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);
     }
 }
Пример #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;
         }
     }
 }
Пример #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;
         }
     }
 }