Beispiel #1
0
 /**
  * try to attach a new item to an existing cart
  *
  * @param EventDispatcherInterface $dispatcher
  * @param \Thelia\Model\Cart       $cart
  * @param int                      $productId
  * @param ProductSaleElements      $productSaleElements
  * @param float                    $quantity
  * @param ProductPriceTools        $productPrices
  *
  * @return CartItem
  */
 protected function doAddItem(EventDispatcherInterface $dispatcher, CartModel $cart, $productId, ProductSaleElements $productSaleElements, $quantity, ProductPriceTools $productPrices)
 {
     $cartItem = new CartItem();
     $cartItem->setDisptacher($dispatcher);
     $cartItem->setCart($cart)->setProductId($productId)->setProductSaleElementsId($productSaleElements->getId())->setQuantity($quantity)->setPrice($productPrices->getPrice())->setPromoPrice($productPrices->getPromoPrice())->setPromo($productSaleElements->getPromo())->setPriceEndOfLife(time() + ConfigQuery::read("cart.priceEOF", 60 * 60 * 24 * 30))->save();
     return $cartItem;
 }
 /**
  * @param array $data
  * @param ProductSaleElements $pse
  * @param Product $product
  *
  * Process update on product sale elements values
  */
 protected function processUpdateAction(array $data, ProductSaleElements $pse, Product $product)
 {
     list($price, $salePrice) = $this->extractPrices($data);
     $event = new ProductSaleElementUpdateEvent($product, $pse->getId());
     $event->setWeight($data["weight"])->setTaxRuleId($data["tax_rule_id"])->setEanCode($data["ean_code"])->setOnsale($data["onsale"])->setReference($data["reference"])->setIsdefault($data["isdefault"])->setIsnew($data["isnew"])->setCurrencyId($data["currency_id"])->setPrice($price)->setSalePrice($salePrice)->setQuantity($data["quantity"])->setFromDefaultCurrency($data["use_exchange_rate"]);
     $this->dispatch(TheliaEvents::PRODUCT_UPDATE_PRODUCT_SALE_ELEMENT, $event);
 }
 /**
  * Declares an association between this object and a ChildProductSaleElements object.
  *
  * @param                  ChildProductSaleElements $v
  * @return                 \Thelia\Model\ProductSaleElementsProductDocument The current object (for fluent API support)
  * @throws PropelException
  */
 public function setProductSaleElements(ChildProductSaleElements $v = null)
 {
     if ($v === null) {
         $this->setProductSaleElementsId(NULL);
     } else {
         $this->setProductSaleElementsId($v->getId());
     }
     $this->aProductSaleElements = $v;
     // Add binding for other direction of this n:n relationship.
     // If this object has already been added to the ChildProductSaleElements object, it will not be re-added.
     if ($v !== null) {
         $v->addProductSaleElementsProductDocument($this);
     }
     return $this;
 }
Beispiel #4
0
 /**
  * Filter the query by a related \Thelia\Model\ProductSaleElements object
  *
  * @param \Thelia\Model\ProductSaleElements|ObjectCollection $productSaleElements The related object(s) to use as filter
  * @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL
  *
  * @return ChildCartItemQuery The current query, for fluid interface
  */
 public function filterByProductSaleElements($productSaleElements, $comparison = null)
 {
     if ($productSaleElements instanceof \Thelia\Model\ProductSaleElements) {
         return $this->addUsingAlias(CartItemTableMap::PRODUCT_SALE_ELEMENTS_ID, $productSaleElements->getId(), $comparison);
     } elseif ($productSaleElements instanceof ObjectCollection) {
         if (null === $comparison) {
             $comparison = Criteria::IN;
         }
         return $this->addUsingAlias(CartItemTableMap::PRODUCT_SALE_ELEMENTS_ID, $productSaleElements->toKeyValue('PrimaryKey', 'Id'), $comparison);
     } else {
         throw new PropelException('filterByProductSaleElements() only accepts arguments of type \\Thelia\\Model\\ProductSaleElements or Collection');
     }
 }
 protected function getPSEVirtualDocument(ProductSaleElementsModel $pse)
 {
     /**
      * Compute documents with the associated loop
      */
     $documentLoop = new Document($this->container);
     // select only not visible documents
     $documentLoop->initializeArgs(["product" => $pse->getProductId(), "visible" => 0]);
     $documents = $documentLoop->exec($documentPagination);
     $documentId = intval(MetaDataQuery::getVal("virtual", "pse", $pse->getId()));
     $data = [];
     /** @var \Thelia\Core\Template\Element\LoopResultRow $document */
     for ($documents->rewind(); $documents->valid(); $documents->next()) {
         $document = $documents->current();
         $data[] = ["id" => $document->get("ID"), "url" => $document->get("DOCUMENT_URL"), "title" => $document->get("TITLE"), "is_associated" => $documentId === $document->get("ID"), "filename" => $document->model->getFile()];
     }
     return $data;
 }
 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);
 }
Beispiel #7
0
 /**
  * Update an existing product sale element
  *
  * @param  ProductSaleElementUpdateEvent $event
  * @throws \Exception
  */
 public function update(ProductSaleElementUpdateEvent $event)
 {
     $salesElement = ProductSaleElementsQuery::create()->findPk($event->getProductSaleElementId());
     $con = Propel::getWriteConnection(ProductSaleElementsTableMap::DATABASE_NAME);
     $con->beginTransaction();
     try {
         // Update the product's tax rule
         $event->getProduct()->setTaxRuleId($event->getTaxRuleId())->save($con);
         // If product sale element is not defined, create it.
         if ($salesElement == null) {
             $salesElement = new ProductSaleElements();
             $salesElement->setProduct($event->getProduct());
         }
         // If this PSE is the default one, be sure to have *only one* default for this product
         if ($event->getIsDefault()) {
             ProductSaleElementsQuery::create()->filterByProduct($event->getProduct())->filterByIsDefault(true)->filterById($event->getProductSaleElementId(), Criteria::NOT_EQUAL)->update(['IsDefault' => false], $con);
         }
         // Update sale element
         $salesElement->setRef($event->getReference())->setQuantity($event->getQuantity())->setPromo($event->getOnsale())->setNewness($event->getIsnew())->setWeight($event->getWeight())->setIsDefault($event->getIsDefault())->setEanCode($event->getEanCode())->save();
         // Update/create price for current currency
         $productPrice = ProductPriceQuery::create()->filterByCurrencyId($event->getCurrencyId())->filterByProductSaleElementsId($salesElement->getId())->findOne($con);
         // If price is not defined, create it.
         if ($productPrice == null) {
             $productPrice = new ProductPrice();
             $productPrice->setProductSaleElements($salesElement)->setCurrencyId($event->getCurrencyId());
         }
         // Check if we have to store the price
         $productPrice->setFromDefaultCurrency($event->getFromDefaultCurrency());
         if ($event->getFromDefaultCurrency() == 0) {
             // Store the price
             $productPrice->setPromoPrice($event->getSalePrice())->setPrice($event->getPrice());
         } else {
             // Do not store the price.
             $productPrice->setPromoPrice(0)->setPrice(0);
         }
         $productPrice->save($con);
         // Store all the stuff !
         $con->commit();
     } catch (\Exception $ex) {
         $con->rollback();
         throw $ex;
     }
 }
 /**
  * Exclude object from result
  *
  * @param   ChildProductSaleElements $productSaleElements Object to remove from the list of results
  *
  * @return ChildProductSaleElementsQuery The current query, for fluid interface
  */
 public function prune($productSaleElements = null)
 {
     if ($productSaleElements) {
         $this->addUsingAlias(ProductSaleElementsTableMap::ID, $productSaleElements->getId(), Criteria::NOT_EQUAL);
     }
     return $this;
 }