/**
  * @param array $data
  * @return array
  *
  * Return the untaxed prices to store
  */
 protected function extractPrices(array $data)
 {
     $calculator = new Calculator();
     $calculator->loadTaxRuleWithoutProduct(TaxRuleQuery::create()->findPk($data["tax_rule_id"]), Country::getShopLocation());
     $price = null === $data["price_with_tax"] ? $data["price"] : $calculator->getUntaxedPrice($data["price_with_tax"]);
     $salePrice = null === $data["sale_price_with_tax"] ? $data["sale_price"] : $calculator->getUntaxedPrice($data["sale_price_with_tax"]);
     return [$price, $salePrice];
 }
Ejemplo n.º 2
0
 /**
  * Calculate taxed/untexted price for a product
  *
  * @param $price
  * @param $price_type
  * @param  Product $product
  * @param  bool    $convert
  * @return string
  */
 protected function computePrice($price, $price_type, Product $product, $convert = false)
 {
     $calc = new Calculator();
     $calc->load($product, Country::getShopLocation());
     if ($price_type == 'without_tax') {
         $return_price = $calc->getTaxedPrice($price);
     } elseif ($price_type == 'with_tax') {
         $return_price = $calc->getUntaxedPrice($price);
     } else {
         $return_price = $price;
     }
     if ($convert != 0) {
         $return_price = $price * Currency::getDefaultCurrency()->getRate();
     }
     return floatval($return_price);
 }
Ejemplo n.º 3
0
 /**
  * Update the promo status of the sale's selected products and combinations
  *
  * @param  ProductSaleStatusUpdateEvent              $event
  * @throws \RuntimeException
  * @throws \Exception
  * @throws \Propel\Runtime\Exception\PropelException
  */
 public function updateProductsSaleStatus(ProductSaleStatusUpdateEvent $event)
 {
     $taxCalculator = new Calculator();
     $sale = $event->getSale();
     // Get all selected product sale elements for this sale
     if (null !== ($saleProducts = SaleProductQuery::create()->filterBySale($sale)->orderByProductId())) {
         $saleOffsetByCurrency = $sale->getPriceOffsets();
         $offsetType = $sale->getPriceOffsetType();
         $con = Propel::getWriteConnection(SaleTableMap::DATABASE_NAME);
         $con->beginTransaction();
         try {
             /** @var SaleProduct $saleProduct */
             foreach ($saleProducts as $saleProduct) {
                 // Reset all sale status on product's PSE
                 ProductSaleElementsQuery::create()->filterByProductId($saleProduct->getProductId())->update(['Promo' => false], $con);
                 $taxCalculator->load($saleProduct->getProduct($con), CountryModel::getShopLocation());
                 $attributeAvId = $saleProduct->getAttributeAvId();
                 $pseRequest = ProductSaleElementsQuery::create()->filterByProductId($saleProduct->getProductId());
                 // If no attribute AV id is defined, consider ALL product combinations
                 if (!is_null($attributeAvId)) {
                     // Find PSE attached to combination containing this attribute av :
                     // SELECT * from product_sale_elements pse
                     // left join attribute_combination ac on ac.product_sale_elements_id = pse.id
                     // where pse.product_id=363
                     // and ac.attribute_av_id = 7
                     // group by pse.id
                     $pseRequest->useAttributeCombinationQuery(null, Criteria::LEFT_JOIN)->filterByAttributeAvId($attributeAvId)->endUse();
                 }
                 $pseList = $pseRequest->find();
                 if (null !== $pseList) {
                     $this->updateProductSaleElementsPrices($pseList, $sale->getActive(), $offsetType, $taxCalculator, $saleOffsetByCurrency, $con);
                 }
             }
             $con->commit();
         } catch (PropelException $e) {
             $con->rollback();
             throw $e;
         }
     }
 }
Ejemplo n.º 4
0
 /**
  * Calculate taxed/untexted price for a product
  *
  * @param $price
  * @param $price_type
  * @param  Product $product
  * @param  bool    $convert
  * @return string
  */
 protected function computePrice($price, $price_type, Product $product, $convert = false)
 {
     $calc = new Calculator();
     $calc->load($product, Country::getShopLocation());
     if ($price_type == 'without_tax') {
         $return_price = $calc->getTaxedPrice($price);
     } elseif ($price_type == 'with_tax') {
         $return_price = $calc->getUntaxedPrice($price);
     } else {
         $return_price = $price;
     }
     if ($convert != 0) {
         $return_price = $price * Currency::getDefaultCurrency()->getRate();
     }
     // Format the number using '.', to perform further calculation
     return NumberFormat::getInstance($this->getRequest())->formatStandardNumber($return_price);
 }
Ejemplo n.º 5
0
 /**
  * Format an address to a postal label
  *
  * @param AddressInterface $address
  * @param null $locale
  * @param null $originCountry
  * @param array $options
  * @return string
  */
 public function postalLabelFormat(AddressInterface $address, $locale = null, $originCountry = null, $options = [])
 {
     $locale = $this->normalizeLocale($locale);
     $addressFormatRepository = new AddressFormatRepository();
     $countryRepository = new CountryRepository();
     $subdivisionRepository = new SubdivisionRepository();
     if (null === $originCountry) {
         $countryId = Country::getShopLocation();
         if (null === ($country = CountryQuery::create()->findPk($countryId))) {
             $country = Country::getDefaultCountry();
         }
         $originCountry = $country->getIsoalpha2();
     }
     $formatter = new PostalLabelFormatter($addressFormatRepository, $countryRepository, $subdivisionRepository, $originCountry, $locale, $options);
     $addressFormatted = $formatter->format($address);
     return $addressFormatted;
 }