本文整理汇总了PHP中Magento\Tax\Helper\Data类的典型用法代码示例。如果您正苦于以下问题:PHP Data类的具体用法?PHP Data怎么用?PHP Data使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Data类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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;
}
开发者ID:pavelnovitsky,项目名称:magento2,代码行数:28,代码来源:Price.php
示例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;
}
}
}
}
}
开发者ID:kidaa30,项目名称:magento2-platformsh,代码行数:35,代码来源:CustomerLoggedInObserver.php
示例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;
}
开发者ID:Atlis,项目名称:docker-magento2,代码行数:32,代码来源:Tax.php
示例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;
}
开发者ID:whoople,项目名称:magento2-testing,代码行数:14,代码来源:UpdateProductOptionsObserver.php
示例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);
}
开发者ID:koliaGI,项目名称:magento2,代码行数:37,代码来源:DataTest.php
示例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;
}
开发者ID:nja78,项目名称:magento2,代码行数:39,代码来源:Observer.php
示例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;
}
开发者ID:pavelnovitsky,项目名称:magento2,代码行数:42,代码来源:Price.php
示例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');
}
}
开发者ID:nja78,项目名称:magento2,代码行数:13,代码来源:Grid.php
示例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;
}
开发者ID:Doability,项目名称:magento2dev,代码行数:24,代码来源:GetPriceConfigurationObserver.php
示例10: testAfterAddressSave
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);
}
开发者ID:kid17,项目名称:magento2,代码行数:17,代码来源:SessionTest.php
示例11: _getAmountData
/**
* 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);
}
}
开发者ID:pradeep-wagento,项目名称:magento2,代码行数:15,代码来源:Request.php
示例12: getPrice
/**
* 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;
}
开发者ID:Atlis,项目名称:docker-magento2,代码行数:16,代码来源:AbstractOptions.php
示例13: getWhichCalcPriceToUse
/**
* 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;
}
开发者ID:koliaGI,项目名称:magento2,代码行数:17,代码来源:GetPriceConfigurationObserver.php
示例14: 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();
}
开发者ID:pradeep-wagento,项目名称:magento2,代码行数:14,代码来源:Price.php
示例15: 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;
}
开发者ID:pradeep-wagento,项目名称:magento2,代码行数:18,代码来源:Adjustment.php
示例16: 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;
}
}
开发者ID:pradeep-wagento,项目名称:magento2,代码行数:16,代码来源:TaxAdjustment.php
示例17: 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]));
}
开发者ID:Atlis,项目名称:docker-magento2,代码行数:16,代码来源:AttributePriceTest.php
示例18: 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()]);
}
}
}
开发者ID:BlackIkeEagle,项目名称:magento2-continuousphp,代码行数:19,代码来源:AfterAddressSaveObserver.php
示例19: 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;
}
开发者ID:aiesh,项目名称:magento2,代码行数:21,代码来源:AttributePrice.php
示例20: aroundDispatch
/**
* @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);
}
开发者ID:kidaa30,项目名称:magento2-platformsh,代码行数:21,代码来源:ContextPlugin.php
注:本文中的Magento\Tax\Helper\Data类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论