本文整理汇总了PHP中Magento\Tax\Helper\Data类的典型用法代码示例。如果您正苦于以下问题:PHP Data类的具体用法?PHP Data怎么用?PHP Data使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Data类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getAfterElementHtml
/**
* @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;
}
示例2: execute
/**
* @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;
}
}
}
}
}
示例3: convertAttribute
/**
* 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;
}
示例4: getWhichCalcPriceToUse
/**
* 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;
}
示例5: testGetWeeeAttributesForBundle
/**
* @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);
}
示例6: getPriceConfiguration
/**
* 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;
}
示例7: convertAttribute
/**
* 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;
}
示例8: getInclExclTaxMessage
/**
* 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');
}
}
示例9: execute
/**
* 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;
}
示例10: displayBothPrices
/**
* 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();
}
示例11: extractAdjustment
/**
* 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;
}
示例12: isIncludedInDisplayPrice
/**
* 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;
}
}
示例13: testAfterPrepareAdjustmentConfig
/**
* 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]));
}
示例14: execute
/**
* @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()]);
}
}
}
示例15: afterPrepareAdjustmentConfig
/**
* 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;
}