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


PHP DataObject::getStore方法代码示例

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


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

示例1: _getRequestCacheKey

 /**
  * Get cache key value for specific tax rate request
  *
  * @param   \Magento\Framework\DataObject $request
  * @return  string
  */
 protected function _getRequestCacheKey($request)
 {
     $store = $request->getStore();
     $key = '';
     if ($store instanceof \Magento\Store\Model\Store) {
         $key = $store->getId() . '|';
     } elseif (is_numeric($store)) {
         $key = $store . '|';
     }
     $key .= $request->getProductClassId() . '|' . $request->getCustomerClassId() . '|' . $request->getCountryId() . '|' . $request->getRegionId() . '|' . $request->getPostcode();
     return $key;
 }
开发者ID:kidaa30,项目名称:magento2-platformsh,代码行数:18,代码来源:Calculation.php

示例2: _getRates

 /**
  * Returns tax rates for request - either pereforms SELECT from DB, or returns already cached result
  * Notice that productClassId due to optimization can be array of ids
  *
  * @param \Magento\Framework\DataObject $request
  * @return array
  * @SuppressWarnings(PHPMD.CyclomaticComplexity)
  * @SuppressWarnings(PHPMD.NPathComplexity)
  * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
  */
 protected function _getRates($request)
 {
     // Extract params that influence our SELECT statement and use them to create cache key
     $storeId = $this->_storeManager->getStore($request->getStore())->getId();
     $customerClassId = $request->getCustomerClassId();
     $countryId = $request->getCountryId();
     $regionId = $request->getRegionId();
     $postcode = $request->getPostcode();
     // Process productClassId as it can be array or usual value. Form best key for cache.
     $productClassId = $request->getProductClassId();
     $ids = is_array($productClassId) ? $productClassId : [$productClassId];
     foreach ($ids as $key => $val) {
         $ids[$key] = (int) $val;
         // Make it integer for equal cache keys even in case of null/false/0 values
     }
     $ids = array_unique($ids);
     sort($ids);
     $productClassKey = implode(',', $ids);
     // Form cache key and either get data from cache or from DB
     $cacheKey = implode('|', [$storeId, $customerClassId, $productClassKey, $countryId, $regionId, $postcode]);
     if (!isset($this->_ratesCache[$cacheKey])) {
         // Make SELECT and get data
         $select = $this->getConnection()->select();
         $select->from(['main_table' => $this->getMainTable()], ['tax_calculation_rate_id', 'tax_calculation_rule_id', 'customer_tax_class_id', 'product_tax_class_id'])->where('customer_tax_class_id = ?', (int) $customerClassId);
         if ($productClassId) {
             $select->where('product_tax_class_id IN (?)', $productClassId);
         }
         $ifnullTitleValue = $this->getConnection()->getCheckSql('title_table.value IS NULL', 'rate.code', 'title_table.value');
         $ruleTableAliasName = $this->getConnection()->quoteIdentifier('rule.tax_calculation_rule_id');
         $select->join(['rule' => $this->getTable('tax_calculation_rule')], $ruleTableAliasName . ' = main_table.tax_calculation_rule_id', ['rule.priority', 'rule.position', 'rule.calculate_subtotal'])->join(['rate' => $this->getTable('tax_calculation_rate')], 'rate.tax_calculation_rate_id = main_table.tax_calculation_rate_id', ['value' => 'rate.rate', 'rate.tax_country_id', 'rate.tax_region_id', 'rate.tax_postcode', 'rate.tax_calculation_rate_id', 'rate.code'])->joinLeft(['title_table' => $this->getTable('tax_calculation_rate_title')], "rate.tax_calculation_rate_id = title_table.tax_calculation_rate_id " . "AND title_table.store_id = '{$storeId}'", ['title' => $ifnullTitleValue])->where('rate.tax_country_id = ?', $countryId)->where("rate.tax_region_id IN(?)", [0, (int) $regionId]);
         $postcodeIsNumeric = is_numeric($postcode);
         $postcodeIsRange = false;
         $originalPostcode = null;
         if (is_string($postcode) && preg_match('/^(.+)-(.+)$/', $postcode, $matches)) {
             if ($countryId == self::USA_COUNTRY_CODE && is_numeric($matches[2]) && strlen($matches[2]) == 4) {
                 $postcodeIsNumeric = true;
                 $originalPostcode = $postcode;
                 $postcode = $matches[1];
             } else {
                 $postcodeIsRange = true;
                 $zipFrom = $matches[1];
                 $zipTo = $matches[2];
             }
         }
         if ($postcodeIsNumeric || $postcodeIsRange) {
             $selectClone = clone $select;
             $selectClone->where('rate.zip_is_range IS NOT NULL');
         }
         $select->where('rate.zip_is_range IS NULL');
         if ($postcode != '*' || $postcodeIsRange) {
             $select->where("rate.tax_postcode IS NULL OR rate.tax_postcode IN('*', '', ?)", $postcodeIsRange ? $postcode : $this->_createSearchPostCodeTemplates($postcode, $originalPostcode));
             if ($postcodeIsNumeric) {
                 $selectClone->where('? BETWEEN rate.zip_from AND rate.zip_to', $postcode);
             } elseif ($postcodeIsRange) {
                 $selectClone->where('rate.zip_from >= ?', $zipFrom)->where('rate.zip_to <= ?', $zipTo);
             }
         }
         /**
          * @see ZF-7592 issue http://framework.zend.com/issues/browse/ZF-7592
          */
         if ($postcodeIsNumeric || $postcodeIsRange) {
             $select = $this->getConnection()->select()->union(['(' . $select . ')', '(' . $selectClone . ')']);
         }
         $select->order('priority ' . \Magento\Framework\DB\Select::SQL_ASC)->order('tax_calculation_rule_id ' . \Magento\Framework\DB\Select::SQL_ASC)->order('tax_country_id ' . \Magento\Framework\DB\Select::SQL_DESC)->order('tax_region_id ' . \Magento\Framework\DB\Select::SQL_DESC)->order('tax_postcode ' . \Magento\Framework\DB\Select::SQL_DESC)->order('value ' . \Magento\Framework\DB\Select::SQL_DESC);
         $fetchResult = $this->getConnection()->fetchAll($select);
         $filteredRates = [];
         if ($fetchResult) {
             foreach ($fetchResult as $rate) {
                 if (!isset($filteredRates[$rate['tax_calculation_rate_id']])) {
                     $filteredRates[$rate['tax_calculation_rate_id']] = $rate;
                 }
             }
         }
         $this->_ratesCache[$cacheKey] = array_values($filteredRates);
     }
     return $this->_ratesCache[$cacheKey];
 }
开发者ID:pradeep-wagento,项目名称:magento2,代码行数:87,代码来源:Calculation.php

示例3: testGetTaxPrice

 /**
  * @param \Magento\Framework\DataObject $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 getTaxPriceDataProvider
  */
 public function testGetTaxPrice($input, $expectOutputPrice, $configs = [], $productClassName = 'DefaultProductClass')
 {
     $this->setUpDefaultRules();
     /** @var \Magento\Catalog\Api\ProductRepositoryInterface $productRepository */
     $productRepository = $this->objectManager->get('Magento\\Catalog\\Api\\ProductRepositoryInterface');
     /** @var \Magento\Catalog\Model\Product $product */
     $product = $productRepository->get('simple');
     $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->getTaxPrice($product, $input->getPrice(), $input->getIncludingTax(), $shippingAddress, $billingAddress, $this->taxClasses['DefaultCustomerClass'], $input->getStore(), $input->getPriceIncludesTax(), $input->getRoundPrice());
     if ($input->getNotEqual()) {
         $this->assertNotEquals($expectOutputPrice, $price);
     } else {
         $this->assertEquals($expectOutputPrice, $price);
     }
 }
开发者ID:BlackIkeEagle,项目名称:magento2-continuousphp,代码行数:32,代码来源:DataTest.php


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