Exemple #1
0
 /**
  * @return mixed
  */
 public function getAfterElementHtml()
 {
     $html = parent::getAfterElementHtml();
     /**
      * getEntityAttribute - use __call
      */
     $addJsObserver = false;
     if ($attribute = $this->getEntityAttribute()) {
         if (!($storeId = $attribute->getStoreId())) {
             $storeId = $this->getForm()->getDataObject()->getStoreId();
         }
         $store = $this->_storeManager->getStore($storeId);
         $html .= '<strong>' . $this->_localeCurrency->getCurrency($store->getBaseCurrencyCode())->getSymbol() . '</strong>';
         if ($this->_taxData->priceIncludesTax($store)) {
             if ($attribute->getAttributeCode() !== 'cost') {
                 $addJsObserver = true;
                 $html .= ' <strong>[' . __('Inc. Tax') . '<span id="dynamic-tax-' . $attribute->getAttributeCode() . '"></span>]</strong>';
             }
         }
     }
     if ($addJsObserver) {
         $html .= $this->_getTaxObservingCode($attribute);
     }
     return $html;
 }
 /**
  * @param Observer $observer
  * @return void
  * @SuppressWarnings(PHPMD.CyclomaticComplexity)
  */
 public function execute(Observer $observer)
 {
     if ($this->moduleManager->isEnabled('Magento_PageCache') && $this->cacheConfig->isEnabled() && $this->taxHelper->isCatalogPriceDisplayAffectedByTax()) {
         /** @var \Magento\Customer\Model\Data\Customer $customer */
         $customer = $observer->getData('customer');
         $customerGroupId = $customer->getGroupId();
         $customerGroup = $this->groupRepository->getById($customerGroupId);
         $customerTaxClassId = $customerGroup->getTaxClassId();
         $this->customerSession->setCustomerTaxClassId($customerTaxClassId);
         /** @var \Magento\Customer\Api\Data\AddressInterface[] $addresses */
         $addresses = $customer->getAddresses();
         if (isset($addresses)) {
             $defaultShippingFound = false;
             $defaultBillingFound = false;
             foreach ($addresses as $address) {
                 if ($address->isDefaultBilling()) {
                     $defaultBillingFound = true;
                     $this->customerSession->setDefaultTaxBillingAddress(['country_id' => $address->getCountryId(), 'region_id' => $address->getRegion() ? $address->getRegion()->getRegionId() : null, 'postcode' => $address->getPostcode()]);
                 }
                 if ($address->isDefaultShipping()) {
                     $defaultShippingFound = true;
                     $this->customerSession->setDefaultTaxShippingAddress(['country_id' => $address->getCountryId(), 'region_id' => $address->getRegion() ? $address->getRegion()->getRegionId() : null, 'postcode' => $address->getPostcode()]);
                 }
                 if ($defaultShippingFound && $defaultBillingFound) {
                     break;
                 }
             }
         }
     }
 }
Exemple #3
0
 /**
  * Set current attribute to entry (for specified product)
  *
  * @param \Magento\Catalog\Model\Product $product
  * @param \Magento\Framework\Gdata\Gshopping\Entry $entry
  * @return \Magento\Framework\Gdata\Gshopping\Entry
  */
 public function convertAttribute($product, $entry)
 {
     $entry->cleanTaxes();
     if ($this->_taxData->getConfig()->priceIncludesTax()) {
         return $entry;
     }
     $calc = $this->calculation;
     $customerTaxClass = $calc->getDefaultCustomerTaxClass($product->getStoreId());
     $rates = $calc->getRatesByCustomerAndProductTaxClasses($customerTaxClass, $product->getTaxClassId());
     $targetCountry = $this->_config->getTargetCountry($product->getStoreId());
     $ratesTotal = 0;
     foreach ($rates as $rate) {
         if ($targetCountry == $rate['country']) {
             $regions = $this->_parseRegions($rate['state'], $rate['postcode']);
             $ratesTotal += count($regions);
             if ($ratesTotal > self::RATES_MAX) {
                 throw new \Magento\Framework\Model\Exception(__("Google shopping only supports %1 tax rates per product", self::RATES_MAX));
             }
             foreach ($regions as $region) {
                 $entry->addTax(array('tax_rate' => $rate['value'] * 100, 'tax_country' => empty($rate['country']) ? '*' : $rate['country'], 'tax_region' => $region));
             }
         }
     }
     return $entry;
 }
 /**
  * Returns which product price to use as a basis for the Weee's final price
  *
  * @param  int|null $storeId
  * @return string
  */
 protected function getWhichCalcPriceToUse($storeId = null)
 {
     $calcPrice = 'finalPrice';
     if ($this->weeeData->geDisplayExcl($storeId) || $this->weeeData->geDisplayExlDescIncl($storeId) || $this->taxData->priceIncludesTax() && $this->taxData->displayPriceExcludingTax()) {
         $calcPrice = 'basePrice';
     }
     return $calcPrice;
 }
Exemple #5
0
 /**
  * Check if we have display prices including and excluding tax
  * With corrections for Dynamic prices
  *
  * @return bool
  */
 public function displayBothPrices()
 {
     $product = $this->getProduct();
     if ($product->getPriceType() == \Magento\Bundle\Model\Product\Price::PRICE_TYPE_DYNAMIC && $product->getPriceModel()->getIsPricesCalculatedByIndex() !== false) {
         return false;
     }
     return $this->_taxHelper->displayBothPrices();
 }
 /**
  * Extract adjustment amount from the given amount value
  *
  * @param float $amount
  * @param SaleableInterface $saleableItem
  * @param null|array $context
  * @return float
  */
 public function extractAdjustment($amount, SaleableInterface $saleableItem, $context = [])
 {
     if ($this->taxHelper->priceIncludesTax()) {
         $adjustedAmount = $this->catalogHelper->getTaxPrice($saleableItem, $amount, false, null, null, null, null, null, false);
         $result = $amount - $adjustedAmount;
     } else {
         $result = 0.0;
     }
     return $result;
 }
 /**
  * Define if adjustment is included in display price
  *
  * @return bool
  */
 public function isIncludedInDisplayPrice()
 {
     if ($this->taxHelper->displayPriceExcludingTax()) {
         return false;
     }
     if ($this->weeeHelper->isEnabled() == true && $this->weeeHelper->isTaxable() == true && $this->weeeHelper->typeOfDisplay([\Magento\Weee\Model\Tax::DISPLAY_EXCL]) == false) {
         return true;
     } else {
         return false;
     }
 }
 /**
  * test for method afterPrepareAdjustmentConfig
  */
 public function testAfterPrepareAdjustmentConfig()
 {
     $this->productMock->expects($this->once())->method('getTaxClassId')->will($this->returnValue('tax-class-id'));
     $this->calculationMock->expects($this->exactly(2))->method('getRateRequest')->will($this->returnValue($this->rateRequestMock));
     $this->calculationMock->expects($this->exactly(2))->method('getRate')->with($this->equalTo($this->rateRequestMock))->will($this->returnValue(99.09999999999999));
     $this->productMock->expects($this->once())->method('getPriceInfo')->will($this->returnValue($this->priceInfoMock));
     $this->priceInfoMock->expects($this->once())->method('getAdjustment')->with($this->equalTo(\Magento\Tax\Pricing\Adjustment::ADJUSTMENT_CODE))->will($this->returnValue($this->adjustmentMock));
     $this->adjustmentMock->expects($this->once())->method('isIncludedInBasePrice')->will($this->returnValue(true));
     $this->taxHelperMock->expects($this->once())->method('displayPriceIncludingTax')->will($this->returnValue(true));
     $this->taxHelperMock->expects($this->once())->method('displayBothPrices')->will($this->returnValue(true));
     $expected = ['product' => $this->productMock, 'defaultTax' => 99.09999999999999, 'currentTax' => 99.09999999999999, 'customerId' => 1, 'includeTax' => true, 'showIncludeTax' => true, 'showBothPrices' => true];
     $this->assertEquals($expected, $this->plugin->afterPrepareAdjustmentConfig($this->attributePriceMock, ['product' => $this->productMock, 'defaultTax' => 0, 'currentTax' => 0, 'customerId' => 1]));
 }
 /**
  * @param Observer $observer
  * @return void
  * @SuppressWarnings(PHPMD.CyclomaticComplexity)
  */
 public function execute(Observer $observer)
 {
     if ($this->moduleManager->isEnabled('Magento_PageCache') && $this->cacheConfig->isEnabled() && $this->taxHelper->isCatalogPriceDisplayAffectedByTax()) {
         /** @var $customerAddress Address */
         $address = $observer->getCustomerAddress();
         // Check if the address is either the default billing, shipping, or both
         if ($this->isDefaultBilling($address)) {
             $this->customerSession->setDefaultTaxBillingAddress(['country_id' => $address->getCountryId(), 'region_id' => $address->getRegion() ? $address->getRegionId() : null, 'postcode' => $address->getPostcode()]);
         }
         if ($this->isDefaultShipping($address)) {
             $this->customerSession->setDefaultTaxShippingAddress(['country_id' => $address->getCountryId(), 'region_id' => $address->getRegion() ? $address->getRegionId() : null, 'postcode' => $address->getPostcode()]);
         }
     }
 }
Exemple #10
0
 /**
  * Get Tax Adjustments for configurable product
  *
  * @param \Magento\ConfigurableProduct\Pricing\Price\AttributePrice $attribute
  * @param array $result
  * @return array
  */
 public function afterPrepareAdjustmentConfig(\Magento\ConfigurableProduct\Pricing\Price\AttributePrice $attribute, array $result)
 {
     $product = $result['product'];
     $productClassId = $product->getTaxClassId();
     $defaultValue = $this->taxCalculationService->getDefaultCalculatedRate($productClassId, $result['customerId']);
     $result['defaultTax'] = $defaultValue + $result['defaultTax'];
     $currentTax = $this->taxCalculationService->getCalculatedRate($productClassId, $result['customerId']);
     $result['currentTax'] = $currentTax + $result['currentTax'];
     $adjustment = $product->getPriceInfo()->getAdjustment(\Magento\Tax\Pricing\Adjustment::ADJUSTMENT_CODE);
     $result['includeTax'] = $adjustment->isIncludedInBasePrice();
     $result['showIncludeTax'] = $this->taxHelper->displayPriceIncludingTax();
     $result['showBothPrices'] = $this->taxHelper->displayBothPrices();
     return $result;
 }
 /**
  * @param \Magento\Framework\App\ActionInterface $subject
  * @param callable $proceed
  * @param \Magento\Framework\App\RequestInterface $request
  * @return mixed
  * @SuppressWarnings(PHPMD.UnusedFormalParameter)
  */
 public function aroundDispatch(\Magento\Framework\App\ActionInterface $subject, \Closure $proceed, \Magento\Framework\App\RequestInterface $request)
 {
     if (!$this->customerSession->isLoggedIn() || !$this->moduleManager->isEnabled('Magento_PageCache') || !$this->cacheConfig->isEnabled() || !$this->taxHelper->isCatalogPriceDisplayAffectedByTax()) {
         return $proceed($request);
     }
     $defaultBillingAddress = $this->customerSession->getDefaultTaxBillingAddress();
     $defaultShippingAddress = $this->customerSession->getDefaultTaxShippingAddress();
     $customerTaxClassId = $this->customerSession->getCustomerTaxClassId();
     if (!empty($defaultBillingAddress) || !empty($defaultShippingAddress)) {
         $taxRates = $this->taxCalculation->getTaxRates($defaultBillingAddress, $defaultShippingAddress, $customerTaxClassId);
         $this->httpContext->setValue('tax_rates', $taxRates, 0);
     }
     return $proceed($request);
 }
Exemple #12
0
 /**
  * Get full information about taxes applied to order
  *
  * @return array
  */
 public function getFullTaxInfo()
 {
     /** @var $source \Magento\Sales\Model\Order */
     $source = $this->getOrder();
     $taxClassAmount = array();
     if ($source instanceof \Magento\Sales\Model\Order) {
         $taxClassAmount = $this->_taxHelper->getCalculatedTaxes($source);
         if (empty($taxClassAmount)) {
             $rates = $this->_taxOrderFactory->create()->getCollection()->loadByOrder($source)->toArray();
             $taxClassAmount = $this->_taxCalculation->reproduceProcess($rates['items']);
         }
     }
     return $taxClassAmount;
 }
Exemple #13
0
 /**
  * Calculate amount for dynamic bundle product
  *
  * @param float $basePriceValue
  * @param Product $bundleProduct
  * @param \Magento\Bundle\Pricing\Price\BundleSelectionPrice[] $selectionPriceList
  * @param null|string $exclude
  * @return \Magento\Framework\Pricing\Amount\AmountInterface
  */
 protected function calculateDynamicBundleAmount($basePriceValue, $bundleProduct, $selectionPriceList, $exclude)
 {
     $fullAmount = 0.0;
     $adjustments = [];
     $amountList = [$this->calculator->getAmount($basePriceValue, $bundleProduct, $exclude)];
     /** @var $option \Magento\Bundle\Model\Option */
     foreach ($selectionPriceList as $selectionPrice) {
         $amountList[] = $selectionPrice->getAmount();
     }
     /** @var  Store $store */
     $store = $bundleProduct->getStore();
     $roundingMethod = $this->taxHelper->getCalculationAgorithm($store);
     /** @var \Magento\Framework\Pricing\Amount\AmountInterface $itemAmount */
     foreach ($amountList as $itemAmount) {
         if ($roundingMethod != TaxCalculationServiceInterface::CALC_TOTAL_BASE) {
             //We need to round the individual selection first
             $fullAmount += $store->roundPrice($itemAmount->getValue());
             foreach ($itemAmount->getAdjustmentAmounts() as $code => $adjustment) {
                 $adjustment = $store->roundPrice($adjustment);
                 $adjustments[$code] = isset($adjustments[$code]) ? $adjustments[$code] + $adjustment : $adjustment;
             }
         } else {
             $fullAmount += $itemAmount->getValue();
             foreach ($itemAmount->getAdjustmentAmounts() as $code => $adjustment) {
                 $adjustments[$code] = isset($adjustments[$code]) ? $adjustments[$code] + $adjustment : $adjustment;
             }
         }
     }
     if ($exclude && isset($adjustments[$exclude])) {
         $fullAmount -= $adjustments[$exclude];
         unset($adjustments[$exclude]);
     }
     return $this->amountFactory->create($fullAmount, $adjustments);
 }
Exemple #14
0
 /**
  * @dataProvider getCalculatedTaxesForOrderItemsDataProvider
  */
 public function testGetCalculatedTaxesForOrderItems($orderData, $invoiceData, $expectedResults)
 {
     $orderId = $orderData['order_id'];
     $orderShippingTaxAmount = isset($orderData['shipping_tax_amount']) ? $orderData['shipping_tax_amount'] : 0;
     $orderTaxDetails = $orderData['order_tax_details'];
     /** @var \PHPUnit_Framework_MockObject_MockObject|\Magento\Sales\Model\Order $orderMock */
     $orderMock = $this->getMockBuilder('Magento\\Sales\\Model\\Order')->disableOriginalConstructor()->getMock();
     $orderMock->expects($this->once())->method('getId')->willReturn($orderId);
     $orderMock->expects($this->once())->method('getShippingTaxAmount')->willReturn($orderShippingTaxAmount);
     $orderTaxDetailsMock = $this->mapOrderTaxItemDetail($orderTaxDetails);
     $this->orderTaxManagementMock->expects($this->any())->method('getOrderTaxDetails')->with($orderId)->will($this->returnValue($orderTaxDetailsMock));
     $invoiceShippingTaxAmount = isset($invoiceData['shipping_tax_amount']) ? $invoiceData['shipping_tax_amount'] : 0;
     $invoiceItems = $invoiceData['invoice_items'];
     /** @var \PHPUnit_Framework_MockObject_MockObject|\Magento\Sales\Model\Order\Invoice $source */
     $source = $this->getMockBuilder('Magento\\Sales\\Model\\Order\\Invoice')->disableOriginalConstructor()->getMock();
     $source->expects($this->once())->method('getOrder')->willReturn($orderMock);
     $source->expects($this->once())->method('getShippingTaxAmount')->willReturn($invoiceShippingTaxAmount);
     $source->expects($this->once())->method('getItems')->willReturn($invoiceItems);
     $this->priceCurrencyMock->expects($this->any())->method('round')->will($this->returnCallback(function ($arg) {
         return round($arg, 2);
     }));
     $result = $this->helper->getCalculatedTaxes($source);
     foreach ($result as $index => $appliedTax) {
         $expectedTax = $expectedResults[$index];
         foreach ($appliedTax as $attr => $value) {
             $this->assertEquals($expectedTax[$attr], $value, "The " . $attr . " of tax does not match");
         }
     }
 }
Exemple #15
0
 /**
  * @dataProvider dataProviderGetWeeeAttributesForBundle
  * @param int $priceIncludesTax
  * @param bool $priceDisplay
  * @param array $expectedAmount
  */
 public function testGetWeeeAttributesForBundle($priceDisplay, $priceIncludesTax, $expectedAmount)
 {
     $prodId1 = 1;
     $prodId2 = 2;
     $fptCode1 = 'fpt' . $prodId1;
     $fptCode2 = 'fpt' . $prodId2;
     $weeeObject1 = new \Magento\Framework\DataObject(['code' => $fptCode1, 'amount' => '15', 'amount_excl_tax' => '15.0000', 'tax_amount' => '1']);
     $weeeObject2 = new \Magento\Framework\DataObject(['code' => $fptCode2, 'amount' => '10', 'amount_excl_tax' => '10.0000', 'tax_amount' => '5']);
     $expectedObject1 = new \Magento\Framework\DataObject(['code' => $fptCode1, 'amount' => $expectedAmount[0], 'amount_excl_tax' => '15.0000', 'tax_amount' => '1']);
     $expectedObject2 = new \Magento\Framework\DataObject(['code' => $fptCode2, 'amount' => $expectedAmount[1], 'amount_excl_tax' => '10.0000', 'tax_amount' => '5']);
     $expectedArray = [$prodId1 => [$fptCode1 => $expectedObject1], $prodId2 => [$fptCode2 => $expectedObject2]];
     $this->weeeTax->expects($this->any())->method('getProductWeeeAttributes')->will($this->returnValue([$weeeObject1, $weeeObject2]));
     $this->taxData->expects($this->any())->method('getPriceDisplayType')->willReturn($priceDisplay);
     $this->taxData->expects($this->any())->method('priceIncludesTax')->willReturn($priceIncludesTax);
     $productSimple = $this->getMock('\\Magento\\Catalog\\Model\\Product\\Type\\Simple', ['getId'], [], '', false);
     $productSimple->expects($this->at(0))->method('getId')->will($this->returnValue($prodId1));
     $productSimple->expects($this->at(1))->method('getId')->will($this->returnValue($prodId2));
     $productInstance = $this->getMock('\\Magento\\Bundle\\Model\\Product\\Type', [], [], '', false);
     $productInstance->expects($this->any())->method('getSelectionsCollection')->will($this->returnValue([$productSimple]));
     $store = $this->getMock('\\Magento\\Store\\Model\\Store', [], [], '', false);
     /** @var \Magento\Catalog\Model\Product $product */
     $product = $this->getMock('\\Magento\\Bundle\\Model\\Product', ['getTypeInstance', 'getStoreId', 'getStore', 'getTypeId'], [], '', false);
     $product->expects($this->any())->method('getTypeInstance')->will($this->returnValue($productInstance));
     $product->expects($this->any())->method('getStoreId')->will($this->returnValue(1));
     $product->expects($this->any())->method('getStore')->will($this->returnValue($store));
     $product->expects($this->any())->method('getTypeId')->will($this->returnValue('bundle'));
     $registry = $this->getMock('Magento\\Framework\\Registry', [], [], '', false);
     $registry->expects($this->any())->method('registry')->with('current_product')->will($this->returnValue($product));
     $result = $this->helperData->getWeeeAttributesForBundle($product);
     $this->assertEquals($expectedArray, $result);
 }
Exemple #16
0
 /**
  * Modify the options config for the front end to resemble the weee final price
  *
  * @param   \Magento\Framework\Event\Observer $observer
  * @return  $this
  * @SuppressWarnings(PHPMD.CyclomaticComplexity)
  */
 public function getPriceConfiguration(\Magento\Framework\Event\Observer $observer)
 {
     if ($this->_weeeData->isEnabled()) {
         $priceConfigObj = $observer->getData('configObj');
         $priceConfig = $priceConfigObj->getConfig();
         try {
             if (is_array($priceConfig)) {
                 foreach ($priceConfig as $keyConfigs => $configs) {
                     if (is_array($configs)) {
                         foreach ($configs as $keyConfig => $config) {
                             $calcPrice = 'finalPrice';
                             if ($this->_taxData->priceIncludesTax() && $this->_taxData->displayPriceExcludingTax()) {
                                 $calcPrice = 'basePrice';
                             }
                             if (array_key_exists('prices', $configs)) {
                                 $priceConfig[$keyConfigs]['prices']['weeePrice'] = ['amount' => $configs['prices'][$calcPrice]['amount']];
                             } else {
                                 foreach ($configs as $keyConfig => $config) {
                                     $priceConfig[$keyConfigs][$keyConfig]['prices']['weeePrice'] = ['amount' => $config['prices'][$calcPrice]['amount']];
                                 }
                             }
                         }
                     }
                 }
             }
             $priceConfigObj->setConfig($priceConfig);
         } catch (Exception $e) {
             return $this;
         }
     }
     return $this;
 }
Exemple #17
0
    /**
     * @param \Magento\Framework\App\ActionInterface $subject
     * @param callable $proceed
     * @param \Magento\Framework\App\RequestInterface $request
     * @return mixed
     * @SuppressWarnings(PHPMD.UnusedFormalParameter)
     * @SuppressWarnings(PHPMD.CyclomaticComplexity)
     * @SuppressWarnings(PHPMD.NPathComplexity)
     * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
     */
    public function aroundExecute(
        \Magento\Framework\App\ActionInterface $subject,
        \Closure $proceed,
        \Magento\Framework\App\RequestInterface $request
    ) {
        if (!$this->weeeHelper->isEnabled() ||
            !$this->customerSession->isLoggedIn() ||
            !$this->moduleManager->isEnabled('Magento_PageCache') ||
            !$this->cacheConfig->isEnabled()) {
            return $proceed($request);
        }

        $basedOn = $this->taxHelper->getTaxBasedOn();
        if ($basedOn != 'shipping' && $basedOn != 'billing') {
            return $proceed($request);
        }

        $weeeTaxRegion = $this->getWeeeTaxRegion($basedOn);
        $websiteId = $this->storeManager->getStore()->getWebsiteId();
        $countryId = $weeeTaxRegion['countryId'];
        $regionId = $weeeTaxRegion['regionId'];

        if (!$countryId && !$regionId) {
            // country and region does not exist
            return $proceed($request);
        } else if ($countryId && !$regionId) {
            // country exist and region does not exist
            $regionId = 0;
            $exist = $this->weeeTax->isWeeeInLocation(
                $countryId,
                $regionId,
                $websiteId
            );
        } else {
            // country and region exist
            $exist = $this->weeeTax->isWeeeInLocation(
                $countryId,
                $regionId,
                $websiteId
            );
            if (!$exist) {
                // just check the country for weee
                $regionId = 0;
                $exist = $this->weeeTax->isWeeeInLocation(
                    $countryId,
                    $regionId,
                    $websiteId
                );
            }
        }

        if ($exist) {
            $this->httpContext->setValue(
                'weee_tax_region',
                ['countryId' => $countryId, 'regionId' => $regionId],
                0
            );
        }
        return $proceed($request);
    }
Exemple #18
0
 /**
  * Set current attribute to entry (for specified product)
  *
  * @param Product $product
  * @param Entry $entry
  * @return Entry
  */
 public function convertAttribute($product, $entry)
 {
     $product->setWebsiteId($this->_storeManager->getStore($product->getStoreId())->getWebsiteId());
     $defaultCustomerGroup = $this->_customerGroupService->getDefaultGroup($product->getStoreId());
     $product->setCustomerGroupId($defaultCustomerGroup->getId());
     /** @var \Magento\Store\Model\Store $store */
     $store = $this->_storeManager->getStore($product->getStoreId());
     $isSalePriceAllowed = $this->_config->getTargetCountry($product->getStoreId()) == 'US';
     // get tax settings
     $priceDisplayType = $this->_taxData->getPriceDisplayType($product->getStoreId());
     $inclTax = $priceDisplayType == Config::DISPLAY_TYPE_INCLUDING_TAX;
     $finalPrice = $this->_getFinalPrice($product, $store, $inclTax, $isSalePriceAllowed);
     // calculate price attribute value
     $price = $this->_getPrice($product, $store, $priceDisplayType, $inclTax, $isSalePriceAllowed);
     if ($isSalePriceAllowed) {
         // set sale_price and effective dates for it
         if ($price && $price - $finalPrice > 0.0001) {
             $this->_setAttributePrice($entry, $product, $price);
             $this->_setAttributePrice($entry, $product, $finalPrice, 'sale_price');
             $this->_setEffectiveDate($product, $entry);
         } else {
             $this->_setAttributePrice($entry, $product, $finalPrice);
             $entry->removeContentAttribute('sale_price_effective_date');
             $entry->removeContentAttribute('sale_price');
         }
         // calculate taxes
         $tax = $this->getGroupAttributeTax();
         if (!$inclTax && !is_null($tax)) {
             $tax->convertAttribute($product, $entry);
         }
     } else {
         $this->_setAttributePrice($entry, $product, $price);
     }
     return $entry;
 }
 /**
  * Get array of arrays with tax information for display in PDF
  * array(
  *  $index => array(
  *      'amount'   => $amount,
  *      'label'    => $label,
  *      'font_size'=> $font_size
  *  )
  * )
  *
  * @return array
  * @SuppressWarnings(PHPMD.CyclomaticComplexity)
  */
 public function getFullTaxInfo()
 {
     $fontSize = $this->getFontSize() ? $this->getFontSize() : 7;
     $taxClassAmount = $this->_taxHelper->getCalculatedTaxes($this->getOrder());
     if (!empty($taxClassAmount)) {
         foreach ($taxClassAmount as &$tax) {
             $percent = $tax['percent'] ? ' (' . $tax['percent'] . '%)' : '';
             $tax['amount'] = $this->getAmountPrefix() . $this->getOrder()->formatPriceTxt($tax['tax_amount']);
             $tax['label'] = __($tax['title']) . $percent . ':';
             $tax['font_size'] = $fontSize;
         }
     } else {
         /** @var $orders \Magento\Tax\Model\Resource\Sales\Order\Tax\Collection */
         $orders = $this->_taxOrdersFactory->create();
         $rates = $orders->loadByOrder($this->getOrder())->toArray();
         $fullInfo = $this->_taxCalculation->reproduceProcess($rates['items']);
         $tax_info = [];
         if ($fullInfo) {
             foreach ($fullInfo as $info) {
                 if (isset($info['hidden']) && $info['hidden']) {
                     continue;
                 }
                 $_amount = $info['amount'];
                 foreach ($info['rates'] as $rate) {
                     $percent = $rate['percent'] ? ' (' . $rate['percent'] . '%)' : '';
                     $tax_info[] = ['amount' => $this->getAmountPrefix() . $this->getOrder()->formatPriceTxt($_amount), 'label' => __($rate['title']) . $percent . ':', 'font_size' => $fontSize];
                 }
             }
         }
         $taxClassAmount = $tax_info;
     }
     return $taxClassAmount;
 }
Exemple #20
0
 public function testGetIncExcTaxLabel()
 {
     $flag = true;
     $text = "Incl. Tax";
     $expected = " (Incl. Tax)";
     $this->taxHelper->expects($this->once())->method('getIncExcText')->with($flag)->will($this->returnValue($text));
     $this->assertEquals($expected, $this->totalsObj->getIncExcTaxLabel($flag));
 }
Exemple #21
0
 /**
  * Get including/excluding tax message
  *
  * @return \Magento\Framework\Phrase
  */
 public function getInclExclTaxMessage()
 {
     if ($this->_taxData->priceIncludesTax($this->getStore())) {
         return __('* - Enter custom price including tax');
     } else {
         return __('* - Enter custom price excluding tax');
     }
 }
 /**
  * Modify the bundle config for the front end to resemble the tax included price when tax included prices
  *
  * @param \Magento\Framework\Event\Observer $observer
  * @return $this
  * @SuppressWarnings(PHPMD.CyclomaticComplexity)
  */
 public function execute(\Magento\Framework\Event\Observer $observer)
 {
     if ($this->taxData->displayPriceIncludingTax()) {
         /** @var \Magento\Catalog\Model\Product $product */
         $product = $this->registry->registry('current_product');
         if ($product->getTypeId() == \Magento\Catalog\Model\Product\Type::TYPE_BUNDLE) {
             $priceConfigObj = $observer->getData('configObj');
             try {
                 $priceConfig = $this->recurConfigAndUpdatePrice($priceConfigObj->getConfig(), 'prices');
                 $priceConfigObj->setConfig($priceConfig);
             } catch (\Exception $e) {
                 return $this;
             }
         }
     }
     return $this;
 }
Exemple #23
0
 /**
  * @param mixed $totals
  * @param null $colspan
  * @return string
  */
 public function renderTotals($totals, $colspan = null)
 {
     if ($colspan === null) {
         $colspan = $this->_taxHelper->displayCartBothPrices() ? 5 : 3;
     }
     $totals = $this->getChildBlock('totals')->setTotals($totals)->renderTotals('', $colspan) . $this->getChildBlock('totals')->setTotals($totals)->renderTotals('footer', $colspan);
     return $totals;
 }
Exemple #24
0
 public function testAfterAddressSave()
 {
     $this->moduleManagerMock->expects($this->once())->method('isEnabled')->with('Magento_PageCache')->willReturn(true);
     $this->cacheConfigMock->expects($this->once())->method('isEnabled')->willReturn(true);
     $this->taxHelperMock->expects($this->any())->method('isCatalogPriceDisplayAffectedByTax')->willReturn(true);
     $address = $this->objectManager->getObject('Magento\\Customer\\Model\\Address');
     $address->setIsDefaultShipping(true);
     $address->setIsDefaultBilling(true);
     $address->setIsPrimaryBilling(true);
     $address->setIsPrimaryShipping(true);
     $address->setCountryId(1);
     $address->setData('postcode', 11111);
     $this->customerSessionMock->expects($this->once())->method('setDefaultTaxBillingAddress')->with(['country_id' => 1, 'region_id' => null, 'postcode' => 11111]);
     $this->customerSessionMock->expects($this->once())->method('setDefaultTaxShippingAddress')->with(['country_id' => 1, 'region_id' => null, 'postcode' => 11111]);
     $this->observerMock->expects($this->once())->method('getCustomerAddress')->willReturn($address);
     $this->session->afterAddressSave($this->observerMock);
 }
Exemple #25
0
 /**
  * Get full information about taxes applied to order
  *
  * @return array
  */
 public function getFullTaxInfo()
 {
     $source = $this->getSource();
     if (!$source instanceof \Magento\Sales\Model\Order\Invoice && !$source instanceof \Magento\Sales\Model\Order\Creditmemo) {
         $source = $this->getOrder();
     }
     $taxClassAmount = [];
     if (empty($source)) {
         return $taxClassAmount;
     }
     $taxClassAmount = $this->_taxHelper->getCalculatedTaxes($source);
     if (empty($taxClassAmount)) {
         $rates = $this->_taxOrderFactory->create()->getCollection()->loadByOrder($source)->toArray();
         $taxClassAmount = $this->_taxCalculation->reproduceProcess($rates['items']);
     }
     return $taxClassAmount;
 }
Exemple #26
0
 public function testAroundDispatch()
 {
     $this->moduleManagerMock->expects($this->any())->method('isEnabled')->with('Magento_PageCache')->willReturn(true);
     $this->cacheConfigMock->expects($this->any())->method('isEnabled')->willReturn(true);
     $this->taxHelperMock->expects($this->any())->method('isCatalogPriceDisplayAffectedByTax')->willReturn(true);
     $this->customerSessionMock->expects($this->once())->method('getDefaultTaxBillingAddress')->willReturn(['country_id' => 1, 'region_id' => null, 'postcode' => 11111]);
     $this->customerSessionMock->expects($this->once())->method('getDefaultTaxShippingAddress')->willReturn(['country_id' => 1, 'region_id' => null, 'postcode' => 11111]);
     $this->customerSessionMock->expects($this->once())->method('getCustomerTaxClassId')->willReturn(1);
     $this->taxCalculationMock->expects($this->once())->method('getTaxRates')->with(['country_id' => 1, 'region_id' => null, 'postcode' => 11111], ['country_id' => 1, 'region_id' => null, 'postcode' => 11111], 1)->willReturn([]);
     $this->httpContextMock->expects($this->once())->method('setValue')->with('tax_rates', [], 0);
     $action = $this->objectManager->getObject('Magento\\Framework\\App\\Action\\Action');
     $request = $this->getMock('\\Magento\\Framework\\App\\Request\\Http', ['getActionName'], [], '', false);
     $expectedResult = 'expectedResult';
     $proceed = function ($request) use($expectedResult) {
         return $expectedResult;
     };
     $this->contextPlugin->aroundDispatch($action, $proceed, $request);
 }
 /**
  * @param bool $inclTax
  */
 private function _prepareTestGetShippingPrice($inclTax)
 {
     $rate = $this->getMock('Magento\\Sales\\Model\\Quote\\Address\\Rate', ['__wakeup'], [], '', false);
     $rate->setPrice(self::SHIPPING_PRICE);
     $this->shippingAddress->setShippingMethod(self::SHIPPING_METHOD);
     $this->shippingAddress->expects($this->once())->method('getShippingRateByCode')->with(self::SHIPPING_METHOD)->will($this->returnValue($rate));
     $this->taxHelper->expects($this->once())->method('getShippingPrice')->with(self::SHIPPING_PRICE, $inclTax ? $this->isTrue() : $this->isFalse(), $this->shippingAddress)->will($this->returnValue(self::SHIPPING_PRICE_WITH_TAX));
     $this->store->expects($this->once())->method('formatPrice')->with(self::SHIPPING_PRICE_WITH_TAX)->will($this->returnValue(self::SHIPPING_PRICE_FORMATTED));
 }
Exemple #28
0
 /**
  * Calculate amount for order
  * @param \Magento\Sales\Model\Order $order
  * @return array
  * @throws \Exception
  */
 protected function _getAmountData(Order $order)
 {
     // if tax is included - need add to request only total amount
     if ($this->_taxData->getConfig()->priceIncludesTax()) {
         return $this->getTaxableAmount($order);
     } else {
         return $this->getNonTaxableAmount($order);
     }
 }
 /**
  * Get price with including/excluding tax
  *
  * @param float $price
  * @param bool $includingTax
  * @return float
  */
 public function getPrice($price, $includingTax = null)
 {
     if (!is_null($includingTax)) {
         $price = $this->_taxData->getPrice($this->getProduct(), $price, true);
     } else {
         $price = $this->_taxData->getPrice($this->getProduct(), $price);
     }
     return $price;
 }
 /**
  * Returns which product price to use as a basis for the Weee's final price
  *
  * @param  int|null $storeId
  * @param  array|null $weeeAttributesForBundle
  * @return string
  */
 protected function getWhichCalcPriceToUse($storeId = null, $weeeAttributesForBundle = null)
 {
     $calcPrice = 'finalPrice';
     if (!empty($weeeAttributesForBundle)) {
         if ($this->weeeData->isDisplayExcl($storeId) || $this->weeeData->isDisplayExclDescIncl($storeId) || $this->taxData->priceIncludesTax() && $this->taxData->displayPriceExcludingTax()) {
             $calcPrice = 'basePrice';
         }
     }
     return $calcPrice;
 }