/** * Exclude object from result * * @param ChildSaleProduct $saleProduct Object to remove from the list of results * * @return ChildSaleProductQuery The current query, for fluid interface */ public function prune($saleProduct = null) { if ($saleProduct) { $this->addUsingAlias(SaleProductTableMap::ID, $saleProduct->getId(), Criteria::NOT_EQUAL); } return $this; }
/** * Process update sale * * @param SaleUpdateEvent $event * @param $eventName * @param EventDispatcherInterface $dispatcher * @throws PropelException */ public function update(SaleUpdateEvent $event, $eventName, EventDispatcherInterface $dispatcher) { if (null !== ($sale = SaleQuery::create()->findPk($event->getSaleId()))) { $sale->setDispatcher($dispatcher); $con = Propel::getWriteConnection(SaleTableMap::DATABASE_NAME); $con->beginTransaction(); try { // Disable all promo flag on sale's currently selected products, // to reset promo status of the products that have been removed from the selection. $sale->setActive(false); $now = new \DateTime(); $startDate = $event->getStartDate(); $endDate = $event->getEndDate(); $update = $startDate <= $now && $now <= $endDate; if ($update) { $dispatcher->dispatch(TheliaEvents::UPDATE_PRODUCT_SALE_STATUS, new ProductSaleStatusUpdateEvent($sale)); } $sale->setActive($event->getActive())->setStartDate($startDate)->setEndDate($endDate)->setPriceOffsetType($event->getPriceOffsetType())->setDisplayInitialPrice($event->getDisplayInitialPrice())->setLocale($event->getLocale())->setSaleLabel($event->getSaleLabel())->setTitle($event->getTitle())->setDescription($event->getDescription())->setChapo($event->getChapo())->setPostscriptum($event->getPostscriptum())->save($con); $event->setSale($sale); // Update price offsets SaleOffsetCurrencyQuery::create()->filterBySaleId($sale->getId())->delete($con); foreach ($event->getPriceOffsets() as $currencyId => $priceOffset) { $saleOffset = new SaleOffsetCurrency(); $saleOffset->setCurrencyId($currencyId)->setSaleId($sale->getId())->setPriceOffsetValue($priceOffset)->save($con); } // Update products SaleProductQuery::create()->filterBySaleId($sale->getId())->delete($con); $productAttributesArray = $event->getProductAttributes(); foreach ($event->getProducts() as $productId) { if (isset($productAttributesArray[$productId])) { foreach ($productAttributesArray[$productId] as $attributeId) { $saleProduct = new SaleProduct(); $saleProduct->setSaleId($sale->getId())->setProductId($productId)->setAttributeAvId($attributeId)->save($con); } } else { $saleProduct = new SaleProduct(); $saleProduct->setSaleId($sale->getId())->setProductId($productId)->setAttributeAvId(null)->save($con); } } if ($update) { // Update related products sale status $dispatcher->dispatch(TheliaEvents::UPDATE_PRODUCT_SALE_STATUS, new ProductSaleStatusUpdateEvent($sale)); } $con->commit(); } catch (PropelException $e) { $con->rollback(); throw $e; } } }
/** * Filter the query by a related \Thelia\Model\SaleProduct object * * @param \Thelia\Model\SaleProduct|ObjectCollection $saleProduct the related object to use as filter * @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL * * @return ChildProductQuery The current query, for fluid interface */ public function filterBySaleProduct($saleProduct, $comparison = null) { if ($saleProduct instanceof \Thelia\Model\SaleProduct) { return $this->addUsingAlias(ProductTableMap::ID, $saleProduct->getProductId(), $comparison); } elseif ($saleProduct instanceof ObjectCollection) { return $this->useSaleProductQuery()->filterByPrimaryKeys($saleProduct->getPrimaryKeys())->endUse(); } else { throw new PropelException('filterBySaleProduct() only accepts arguments of type \\Thelia\\Model\\SaleProduct or Collection'); } }