/**
  * Returns a new CurrencyQuery object.
  *
  * @param     string $modelAlias The alias of a model in the query
  * @param     CurrencyQuery|Criteria $criteria Optional Criteria to build the query from
  *
  * @return CurrencyQuery
  */
 public static function create($modelAlias = null, $criteria = null)
 {
     if ($criteria instanceof CurrencyQuery) {
         return $criteria;
     }
     $query = new CurrencyQuery();
     if (null !== $modelAlias) {
         $query->setModelAlias($modelAlias);
     }
     if ($criteria instanceof Criteria) {
         $query->mergeWith($criteria);
     }
     return $query;
 }
Example #2
0
 public static function getDefaultCurrency()
 {
     if (null === self::$defaultCurrency) {
         self::$defaultCurrency = CurrencyQuery::create()->findOneByByDefault(1);
         if (null === self::$defaultCurrency) {
             throw new \RuntimeException("No default currency is defined. Please define one.");
         }
     }
     return self::$defaultCurrency;
 }
Example #3
0
 /**
  * Duplicate the current existing cart. Only the token is changed
  *
  * @param string $token
  * @param Customer $customer
  * @param Currency $currency
  * @param EventDispatcherInterface $dispatcher
  * @return Cart
  * @throws \Exception
  * @throws \Propel\Runtime\Exception\PropelException
  */
 public function duplicate($token, Customer $customer = null, Currency $currency = null, EventDispatcherInterface $dispatcher = null)
 {
     if (!$dispatcher) {
         return false;
     }
     $cartItems = $this->getCartItems();
     $cart = new Cart();
     $cart->setAddressDeliveryId($this->getAddressDeliveryId());
     $cart->setAddressInvoiceId($this->getAddressInvoiceId());
     $cart->setToken($token);
     $discount = 0;
     if (null === $currency) {
         $currencyQuery = CurrencyQuery::create();
         $currency = $currencyQuery->findPk($this->getCurrencyId()) ?: $currencyQuery->findOneByByDefault(1);
     }
     $cart->setCurrency($currency);
     if ($customer) {
         $cart->setCustomer($customer);
         if ($customer->getDiscount() > 0) {
             $discount = $customer->getDiscount();
         }
     }
     $cart->save();
     foreach ($cartItems as $cartItem) {
         $product = $cartItem->getProduct();
         $productSaleElements = $cartItem->getProductSaleElements();
         if ($product && $productSaleElements && $product->getVisible() == 1 && ($productSaleElements->getQuantity() >= $cartItem->getQuantity() || $product->getVirtual() === 1 || !ConfigQuery::checkAvailableStock())) {
             $item = new CartItem();
             $item->setCart($cart);
             $item->setProductId($cartItem->getProductId());
             $item->setQuantity($cartItem->getQuantity());
             $item->setProductSaleElements($productSaleElements);
             $prices = $productSaleElements->getPricesByCurrency($currency, $discount);
             $item->setPrice($prices->getPrice())->setPromoPrice($prices->getPromoPrice())->setPromo($productSaleElements->getPromo());
             $item->save();
             $dispatcher->dispatch(TheliaEvents::CART_ITEM_DUPLICATE, new CartItemDuplicationItem($item, $cartItem));
         }
     }
     try {
         $this->delete();
     } catch (\Exception $e) {
         // just fail silently in some cases
     }
     return $cart;
 }
Example #4
0
 /**
  * Get the associated Currency object
  *
  * @param      PropelPDO $con Optional Connection object.
  * @return                 Currency The associated Currency object.
  * @throws PropelException
  */
 public function getCurrency(PropelPDO $con = null)
 {
     if ($this->aCurrency === null && $this->default_currency_id !== null) {
         $this->aCurrency = CurrencyQuery::create()->findPk($this->default_currency_id, $con);
         /* The following can be used additionally to
               guarantee the related object contains a reference
               to this object.  This level of coupling may, however, be
               undesirable since it could result in an only partially populated collection
               in the referenced object.
               $this->aCurrency->addCountrys($this);
            */
     }
     return $this->aCurrency;
 }
Example #5
0
 /**
  * Removes this object from datastore and sets delete attribute.
  *
  * @param      PropelPDO $con
  * @return void
  * @throws PropelException
  * @throws Exception
  * @see        BaseObject::setDeleted()
  * @see        BaseObject::isDeleted()
  */
 public function delete(PropelPDO $con = null)
 {
     if ($this->isDeleted()) {
         throw new PropelException("This object has already been deleted.");
     }
     if ($con === null) {
         $con = Propel::getConnection(CurrencyPeer::DATABASE_NAME, Propel::CONNECTION_WRITE);
     }
     $con->beginTransaction();
     try {
         $deleteQuery = CurrencyQuery::create()->filterByPrimaryKey($this->getPrimaryKey());
         $ret = $this->preDelete($con);
         // symfony_behaviors behavior
         foreach (sfMixer::getCallables('BaseCurrency:delete:pre') as $callable) {
             if (call_user_func($callable, $this, $con)) {
                 $con->commit();
                 return;
             }
         }
         if ($ret) {
             $deleteQuery->delete($con);
             $this->postDelete($con);
             // symfony_behaviors behavior
             foreach (sfMixer::getCallables('BaseCurrency:delete:post') as $callable) {
                 call_user_func($callable, $this, $con);
             }
             $con->commit();
             $this->setDeleted(true);
         } else {
             $con->commit();
         }
     } catch (Exception $e) {
         $con->rollBack();
         throw $e;
     }
 }