当前位置: 首页>>代码示例>>PHP>>正文


PHP Data::getPrice方法代码示例

本文整理汇总了PHP中Magento\Tax\Helper\Data::getPrice方法的典型用法代码示例。如果您正苦于以下问题:PHP Data::getPrice方法的具体用法?PHP Data::getPrice怎么用?PHP Data::getPrice使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Magento\Tax\Helper\Data的用法示例。


在下文中一共展示了Data::getPrice方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: 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

示例2: _getPriceConfiguration

 /**
  * Get price configuration
  *
  * @param \Magento\Catalog\Model\Product\Option\Value|\Magento\Catalog\Model\Product\Option $option
  * @return array
  */
 protected function _getPriceConfiguration($option)
 {
     $data = array();
     $data['price'] = $this->_coreData->currency($option->getPrice(true), false, false);
     $data['oldPrice'] = $this->_coreData->currency($option->getPrice(false), false, false);
     $data['priceValue'] = $option->getPrice(false);
     $data['type'] = $option->getPriceType();
     $data['exclTaxPrice'] = $price = $this->_taxData->getPrice($option->getProduct(), $data['price'], false);
     $data['inclTaxPrice'] = $price = $this->_taxData->getPrice($option->getProduct(), $data['price'], true);
     return $data;
 }
开发者ID:Atlis,项目名称:docker-magento2,代码行数:17,代码来源:Options.php

示例3: testGetPrice

 /**
  * @param \Magento\Framework\Object $input
  * @param float $expectOutputPrice
  * @param string[] $configs
  * @param string $productClassName
  *
  * @magentoDataFixture Magento/Catalog/_files/products.php
  * @magentoDataFixture Magento/Customer/_files/customer.php
  * @magentoDataFixture Magento/Customer/_files/customer_address.php
  * @magentoDbIsolation enabled
  * @dataProvider getPriceDataProvider
  */
 public function testGetPrice($input, $expectOutputPrice, $configs = [], $productClassName = 'DefaultProductClass')
 {
     $this->setUpDefaultRules();
     $fixtureProductId = 1;
     /** @var \Magento\Catalog\Model\Product $product */
     $product = $this->objectManager->create('Magento\\Catalog\\Model\\Product')->load($fixtureProductId);
     $product->setTaxClassId($this->taxClasses[$productClassName]);
     $shippingAddress = $this->getCustomerAddress();
     $billingAddress = $shippingAddress;
     foreach ($configs as $config) {
         $this->scopeConfig->setValue($config['path'], $config['value'], ScopeInterface::SCOPE_STORE, 'default');
     }
     $price = $this->helper->getPrice($product, $input->getPrice(), $input->getIncludingTax(), $shippingAddress, $billingAddress, $this->taxClasses['DefaultCustomerClass'], $input->getStore(), $input->getPriceIncludesTax(), $input->getRoundPrice());
     $this->assertEquals($expectOutputPrice, $price);
 }
开发者ID:Atlis,项目名称:docker-magento2,代码行数:27,代码来源:DataTest.php

示例4: _getFinalPrice

 /**
  * Calculate final price
  *
  * @param Product $product
  * @param \Magento\Store\Model\Store $store
  * @param bool $inclTax
  * @param bool $isSalePriceAllowed
  * @return float|null
  */
 private function _getFinalPrice($product, $store, $inclTax, $isSalePriceAllowed)
 {
     // calculate sale_price attribute value
     $salePriceAttribute = $this->getGroupAttributeSalePrice();
     $salePriceMapValue = null;
     $finalPrice = null;
     if (!is_null($salePriceAttribute)) {
         $salePriceMapValue = $salePriceAttribute->getProductAttributeValue($product);
     }
     if (!is_null($salePriceMapValue) && floatval($salePriceMapValue) > 0.0001) {
         $finalPrice = $salePriceMapValue;
     } else {
         if ($isSalePriceAllowed) {
             $finalPrice = $this->catalogPrice->getCatalogPrice($product, $store, $inclTax);
         }
     }
     if ($product->getTypeId() != Product\Type::TYPE_BUNDLE) {
         $finalPrice = $this->_taxData->getPrice($product, $finalPrice, $inclTax, null, null, null, $product->getStoreId());
     }
     return $finalPrice;
 }
开发者ID:Atlis,项目名称:docker-magento2,代码行数:30,代码来源:Price.php

示例5: _processPrice

 /**
  * Process price emails
  *
  * @param \Magento\ProductAlert\Model\Email $email
  * @return $this
  */
 protected function _processPrice(\Magento\ProductAlert\Model\Email $email)
 {
     $email->setType('price');
     foreach ($this->_getWebsites() as $website) {
         /* @var $website \Magento\Store\Model\Website */
         if (!$website->getDefaultGroup() || !$website->getDefaultGroup()->getDefaultStore()) {
             continue;
         }
         if (!$this->_scopeConfig->getValue(self::XML_PATH_PRICE_ALLOW, \Magento\Store\Model\ScopeInterface::SCOPE_STORE, $website->getDefaultGroup()->getDefaultStore()->getId())) {
             continue;
         }
         try {
             $collection = $this->_priceColFactory->create()->addWebsiteFilter($website->getId())->setCustomerOrder();
         } catch (\Exception $e) {
             $this->_errors[] = $e->getMessage();
             return $this;
         }
         $previousCustomer = null;
         $email->setWebsite($website);
         foreach ($collection as $alert) {
             try {
                 if (!$previousCustomer || $previousCustomer->getId() != $alert->getCustomerId()) {
                     $customer = $this->_customerAccountService->getCustomer($alert->getCustomerId());
                     if ($previousCustomer) {
                         $email->send();
                     }
                     if (!$customer) {
                         continue;
                     }
                     $previousCustomer = $customer;
                     $email->clean();
                     $email->setCustomerData($customer);
                 } else {
                     $customer = $previousCustomer;
                 }
                 /** @var \Magento\Catalog\Model\Product $product */
                 $product = $this->_productFactory->create()->setStoreId($website->getDefaultStore()->getId())->load($alert->getProductId());
                 if (!$product) {
                     continue;
                 }
                 $product->setCustomerGroupId($customer->getGroupId());
                 if ($alert->getPrice() > $product->getFinalPrice()) {
                     $productPrice = $product->getFinalPrice();
                     $product->setFinalPrice($this->_taxData->getPrice($product, $productPrice));
                     $product->setPrice($this->_taxData->getPrice($product, $product->getPrice()));
                     $email->addPriceProduct($product);
                     $alert->setPrice($productPrice);
                     $alert->setLastSendDate($this->_dateFactory->create()->gmtDate());
                     $alert->setSendCount($alert->getSendCount() + 1);
                     $alert->setStatus(1);
                     $alert->save();
                 }
             } catch (\Exception $e) {
                 $this->_errors[] = $e->getMessage();
             }
         }
         if ($previousCustomer) {
             try {
                 $email->send();
             } catch (\Exception $e) {
                 $this->_errors[] = $e->getMessage();
             }
         }
     }
     return $this;
 }
开发者ID:Atlis,项目名称:docker-magento2,代码行数:72,代码来源:Observer.php

示例6: getTotalPrices

 /**
  * Retrieve Price considering tier price
  *
  * @param  \Magento\Catalog\Model\Product $product
  * @param  string|null                $which
  * @param  bool|null                  $includeTax
  * @param  bool                       $takeTierPrice
  * @return float|array
  */
 public function getTotalPrices($product, $which = null, $includeTax = null, $takeTierPrice = true)
 {
     // check calculated price index
     if ($product->getData('min_price') && $product->getData('max_price')) {
         $minimalPrice = $this->_taxData->getPrice($product, $product->getData('min_price'), $includeTax);
         $maximalPrice = $this->_taxData->getPrice($product, $product->getData('max_price'), $includeTax);
         $this->_isPricesCalculatedByIndex = true;
     } else {
         /**
          * Check if product price is fixed
          */
         $finalPrice = $product->getFinalPrice();
         if ($product->getPriceType() == self::PRICE_TYPE_FIXED) {
             $minimalPrice = $maximalPrice = $this->_taxData->getPrice($product, $finalPrice, $includeTax);
         } else {
             // PRICE_TYPE_DYNAMIC
             $minimalPrice = $maximalPrice = 0;
         }
         $options = $this->getOptions($product);
         $minPriceFounded = false;
         if ($options) {
             foreach ($options as $option) {
                 /* @var $option \Magento\Bundle\Model\Option */
                 $selections = $option->getSelections();
                 if ($selections) {
                     $selectionMinimalPrices = array();
                     $selectionMaximalPrices = array();
                     foreach ($option->getSelections() as $selection) {
                         /* @var $selection \Magento\Bundle\Model\Selection */
                         if (!$selection->isSalable()) {
                             /**
                              * @todo CatalogInventory Show out of stock Products
                              */
                             continue;
                         }
                         $qty = $selection->getSelectionQty();
                         $item = $product->getPriceType() == self::PRICE_TYPE_FIXED ? $product : $selection;
                         $selectionMinimalPrices[] = $this->_taxData->getPrice($item, $this->getSelectionFinalTotalPrice($product, $selection, 1, $qty, true, $takeTierPrice), $includeTax);
                         $selectionMaximalPrices[] = $this->_taxData->getPrice($item, $this->getSelectionFinalTotalPrice($product, $selection, 1, null, true, $takeTierPrice), $includeTax);
                     }
                     if (count($selectionMinimalPrices)) {
                         $selMinPrice = min($selectionMinimalPrices);
                         if ($option->getRequired()) {
                             $minimalPrice += $selMinPrice;
                             $minPriceFounded = true;
                         } elseif (true !== $minPriceFounded) {
                             $selMinPrice += $minimalPrice;
                             $minPriceFounded = false === $minPriceFounded ? $selMinPrice : min($minPriceFounded, $selMinPrice);
                         }
                         if ($option->isMultiSelection()) {
                             $maximalPrice += array_sum($selectionMaximalPrices);
                         } else {
                             $maximalPrice += max($selectionMaximalPrices);
                         }
                     }
                 }
             }
         }
         // condition is TRUE when all product options are NOT required
         if (!is_bool($minPriceFounded)) {
             $minimalPrice = $minPriceFounded;
         }
         $customOptions = $product->getOptions();
         if ($product->getPriceType() == self::PRICE_TYPE_FIXED && $customOptions) {
             foreach ($customOptions as $customOption) {
                 /* @var $customOption \Magento\Catalog\Model\Product\Option */
                 $values = $customOption->getValues();
                 if ($values) {
                     $prices = array();
                     foreach ($values as $value) {
                         /* @var $value \Magento\Catalog\Model\Product\Option\Value */
                         $valuePrice = $value->getPrice(true);
                         $prices[] = $valuePrice;
                     }
                     if (count($prices)) {
                         if ($customOption->getIsRequire()) {
                             $minimalPrice += $this->_taxData->getPrice($product, min($prices), $includeTax);
                         }
                         $multiTypes = array(\Magento\Catalog\Model\Product\Option::OPTION_TYPE_CHECKBOX, \Magento\Catalog\Model\Product\Option::OPTION_TYPE_MULTIPLE);
                         if (in_array($customOption->getType(), $multiTypes)) {
                             $maximalValue = array_sum($prices);
                         } else {
                             $maximalValue = max($prices);
                         }
                         $maximalPrice += $this->_taxData->getPrice($product, $maximalValue, $includeTax);
                     }
                 } else {
                     $valuePrice = $customOption->getPrice(true);
                     if ($customOption->getIsRequire()) {
                         $minimalPrice += $this->_taxData->getPrice($product, $valuePrice, $includeTax);
                     }
//.........这里部分代码省略.........
开发者ID:Atlis,项目名称:docker-magento2,代码行数:101,代码来源:Price.php

示例7: getItemBaseOriginalPrice

 /**
  * Return item base original price
  *
  * @param AbstractItem $item
  * @return float
  */
 public function getItemBaseOriginalPrice($item)
 {
     return $this->_taxData->getPrice($item, $item->getBaseOriginalPrice(), true);
 }
开发者ID:Atlis,项目名称:docker-magento2,代码行数:10,代码来源:Validator.php


注:本文中的Magento\Tax\Helper\Data::getPrice方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。