本文整理汇总了PHP中Magento\Framework\App\ScopeResolverInterface::getScope方法的典型用法代码示例。如果您正苦于以下问题:PHP ScopeResolverInterface::getScope方法的具体用法?PHP ScopeResolverInterface::getScope怎么用?PHP ScopeResolverInterface::getScope使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Magento\Framework\App\ScopeResolverInterface
的用法示例。
在下文中一共展示了ScopeResolverInterface::getScope方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: processQueryWithField
/**
* @param FilterInterface $filter
* @param bool $isNegation
* @param string $query
* @return string
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
*/
private function processQueryWithField(FilterInterface $filter, $isNegation, $query)
{
$currentStoreId = $this->scopeResolver->getScope()->getId();
$attribute = $this->config->getAttribute(\Magento\Catalog\Model\Product::ENTITY, $filter->getField());
$select = $this->getSelect();
$table = $attribute->getBackendTable();
if ($filter->getField() == 'price') {
$query = str_replace('price', 'min_price', $query);
$select->from(['main_table' => $this->resource->getTableName('catalog_product_index_price')], 'entity_id')->where($query);
} elseif ($filter->getField() == 'category_ids') {
return 'category_index.category_id = ' . $filter->getValue();
} else {
if ($attribute->isStatic()) {
$select->from(['main_table' => $table], 'entity_id')->where($query);
} else {
if ($filter->getType() == FilterInterface::TYPE_TERM) {
$field = $filter->getField();
$mapper = function ($value) use($field, $isNegation) {
return ($isNegation ? '-' : '') . $this->attributePrefix . $field . '_' . $value;
};
if (is_array($filter->getValue())) {
$value = implode(' ', array_map($mapper, $filter->getValue()));
} else {
$value = $mapper($filter->getValue());
}
return 'MATCH (data_index) AGAINST (' . $this->getConnection()->quote($value) . ' IN BOOLEAN MODE)';
}
$ifNullCondition = $this->getConnection()->getIfNullSql('current_store.value', 'main_table.value');
$select->from(['main_table' => $table], 'entity_id')->joinLeft(['current_store' => $table], 'current_store.attribute_id = main_table.attribute_id AND current_store.store_id = ' . $currentStoreId, null)->columns([$filter->getField() => $ifNullCondition])->where('main_table.attribute_id = ?', $attribute->getAttributeId())->where('main_table.store_id = ?', \Magento\Store\Model\Store::DEFAULT_STORE_ID)->having($query);
}
}
return 'search_index.product_id IN (
select entity_id from ' . $this->conditionManager->wrapBrackets($select) . ' as filter
)';
}
示例2: processQueryWithField
/**
* @param FilterInterface $filter
* @param bool $isNegation
* @param string $query
* @param QueryContainer $queryContainer
* @return string
*/
private function processQueryWithField(FilterInterface $filter, $isNegation, $query, QueryContainer $queryContainer)
{
$currentStoreId = $this->scopeResolver->getScope()->getId();
$attribute = $this->config->getAttribute(\Magento\Catalog\Model\Product::ENTITY, $filter->getField());
$select = $this->getConnection()->select();
$table = $attribute->getBackendTable();
if ($filter->getField() == 'price') {
$query = str_replace('price', 'min_price', $query);
$select->from(['main_table' => $this->resource->getTableName('catalog_product_index_price')], 'entity_id')->where($query);
} elseif ($filter->getField() == 'category_ids') {
return 'category_index.category_id = ' . $filter->getValue();
} else {
if ($attribute->isStatic()) {
$select->from(['main_table' => $table], 'entity_id')->where($query);
} else {
if ($filter->getType() == FilterInterface::TYPE_TERM) {
if (is_array($filter->getValue())) {
$value = sprintf('%s IN (%s)', $isNegation ? 'NOT' : '', implode(',', $filter->getValue()));
} else {
$value = ($isNegation ? '!' : '') . '= ' . $filter->getValue();
}
$filterQuery = sprintf('cpie.store_id = %d AND cpie.attribute_id = %d AND cpie.value %s', $this->scopeResolver->getScope()->getId(), $attribute->getId(), $value);
$queryContainer->addFilter($filterQuery);
return '';
}
$ifNullCondition = $this->getConnection()->getIfNullSql('current_store.value', 'main_table.value');
$select->from(['main_table' => $table], 'entity_id')->joinLeft(['current_store' => $table], 'current_store.attribute_id = main_table.attribute_id AND current_store.store_id = ' . $currentStoreId, null)->columns([$filter->getField() => $ifNullCondition])->where('main_table.attribute_id = ?', $attribute->getAttributeId())->where('main_table.store_id = ?', \Magento\Store\Model\Store::DEFAULT_STORE_ID)->having($query);
}
}
return 'search_index.entity_id IN (
select entity_id from ' . $this->conditionManager->wrapBrackets($select) . ' as filter
)';
}
示例3: getScope
/**
* {@inheritdoc}
*/
public function getScope($scopeId = null)
{
$scope = $this->scopeResolver->getScope($scopeId);
if (!$scope instanceof \Magento\Framework\Url\ScopeInterface) {
throw new \Magento\Framework\Exception\LocalizedException(new \Magento\Framework\Phrase('Invalid scope object'));
}
return $scope;
}
示例4: getScopeId
/**
* Get scope id by code
*
* @param Dimension $dimension
* @return int
*/
private function getScopeId($dimension)
{
if (is_numeric($dimension->getValue())) {
return $dimension->getValue();
} else {
return $this->scopeResolver->getScope($dimension->getValue())->getId();
}
}
示例5: generateExpression
/**
* @param Dimension $dimension
* @return string
*/
private function generateExpression(Dimension $dimension)
{
$field = $dimension->getName();
$value = $dimension->getValue();
if ('scope' === $field) {
$field = self::STORE_FIELD_NAME;
$value = $this->scopeResolver->getScope($value)->getId();
}
return $this->conditionManager->generateCondition('search_index.' . $field, '=', $value);
}
示例6: generateExpression
/**
* @param Dimension $dimension
* @param AdapterInterface $adapter
* @return string
*/
private function generateExpression(Dimension $dimension, AdapterInterface $adapter)
{
$identifier = $dimension->getName();
$value = $dimension->getValue();
if (self::DEFAULT_DIMENSION_NAME === $identifier) {
$identifier = self::STORE_FIELD_NAME;
$value = $this->scopeResolver->getScope($value)->getId();
}
return sprintf('%s = %s', $adapter->quoteIdentifier($identifier), $adapter->quote($value));
}
示例7: search
/**
* {@inheritdoc}
*/
public function search(SearchCriteriaInterface $searchCriteria)
{
$this->requestBuilder->setRequestName($searchCriteria->getRequestName());
$scope = $this->scopeResolver->getScope();
$this->requestBuilder->bindDimension('scope', $scope);
foreach ($searchCriteria->getFilterGroups() as $filterGroup) {
foreach ($filterGroup->getFilters() as $filter) {
$this->addFieldToFilter($filter->getField(), $filter->getValue());
}
}
$this->requestBuilder->setFrom($searchCriteria->getCurrentPage() * $searchCriteria->getPageSize());
$this->requestBuilder->setSize($searchCriteria->getPageSize());
$request = $this->requestBuilder->create();
$searchResponse = $this->searchEngine->search($request);
return $this->searchResponseBuilder->build($searchResponse)->setSearchCriteria($searchCriteria);
}
示例8: processQueryWithField
/**
* @param FilterInterface $filter
* @param bool $isNegation
* @param string $query
* @return string
*/
private function processQueryWithField(FilterInterface $filter, $isNegation, $query)
{
/** @var \Magento\Catalog\Model\ResourceModel\Eav\Attribute $attribute */
$attribute = $this->config->getAttribute(Product::ENTITY, $filter->getField());
if ($filter->getField() === 'price') {
$resultQuery = str_replace($this->connection->quoteIdentifier('price'), $this->connection->quoteIdentifier('price_index.min_price'), $query);
} elseif ($filter->getField() === 'category_ids') {
return 'category_ids_index.category_id = ' . $filter->getValue();
} elseif ($attribute->isStatic()) {
$alias = $this->tableMapper->getMappingAlias($filter);
$resultQuery = str_replace($this->connection->quoteIdentifier($attribute->getAttributeCode()), $this->connection->quoteIdentifier($alias . '.' . $attribute->getAttributeCode()), $query);
} elseif ($filter->getType() === FilterInterface::TYPE_TERM && in_array($attribute->getFrontendInput(), ['select', 'multiselect'], true)) {
$alias = $this->tableMapper->getMappingAlias($filter);
if (is_array($filter->getValue())) {
$value = sprintf('%s IN (%s)', $isNegation ? 'NOT' : '', implode(',', $filter->getValue()));
} else {
$value = ($isNegation ? '!' : '') . '= ' . $filter->getValue();
}
$resultQuery = sprintf('%1$s.value %2$s', $alias, $value);
} else {
$table = $attribute->getBackendTable();
$select = $this->connection->select();
$ifNullCondition = $this->connection->getIfNullSql('current_store.value', 'main_table.value');
$currentStoreId = $this->scopeResolver->getScope()->getId();
$select->from(['main_table' => $table], 'entity_id')->joinLeft(['current_store' => $table], 'current_store.attribute_id = main_table.attribute_id AND current_store.store_id = ' . $currentStoreId, null)->columns([$filter->getField() => $ifNullCondition])->where('main_table.attribute_id = ?', $attribute->getAttributeId())->where('main_table.store_id = ?', Store::DEFAULT_STORE_ID)->having($query);
$resultQuery = 'search_index.entity_id IN (
select entity_id from ' . $this->conditionManager->wrapBrackets($select) . ' as filter
)';
}
return $resultQuery;
}
示例9: getPriceFormat
/**
* Functions returns array with price formatting info
*
* @return array
* @SuppressWarnings(PHPMD.NPathComplexity)
*/
public function getPriceFormat()
{
$localeData = (new DataBundle())->get($this->_localeResolver->getLocale());
$format = $localeData['NumberElements']['latn']['patterns']['currencyFormat'] ?: explode(';', $localeData['NumberPatterns'][1])[0];
$decimalSymbol = $localeData['NumberElements']['latn']['symbols']['decimal'] ?: $localeData['NumberElements'][0];
$groupSymbol = $localeData['NumberElements']['latn']['symbols']['group'] ?: $localeData['NumberElements'][1];
$pos = strpos($format, ';');
if ($pos !== false) {
$format = substr($format, 0, $pos);
}
$format = preg_replace("/[^0\\#\\.,]/", "", $format);
$totalPrecision = 0;
$decimalPoint = strpos($format, '.');
if ($decimalPoint !== false) {
$totalPrecision = strlen($format) - (strrpos($format, '.') + 1);
} else {
$decimalPoint = strlen($format);
}
$requiredPrecision = $totalPrecision;
$t = substr($format, $decimalPoint);
$pos = strpos($t, '#');
if ($pos !== false) {
$requiredPrecision = strlen($t) - $pos - $totalPrecision;
}
if (strrpos($format, ',') !== false) {
$group = $decimalPoint - strrpos($format, ',') - 1;
} else {
$group = strrpos($format, '.');
}
$integerRequired = strpos($format, '.') - strpos($format, '0');
$result = ['pattern' => $this->_scopeResolver->getScope()->getCurrentCurrency()->getOutputFormat(), 'precision' => $totalPrecision, 'requiredPrecision' => $requiredPrecision, 'decimalSymbol' => $decimalSymbol, 'groupSymbol' => $groupSymbol, 'groupLength' => $group, 'integerRequired' => $integerRequired];
return $result;
}
示例10: aroundGetDataSet
/**
* @param \Magento\CatalogSearch\Model\Adapter\Mysql\Aggregation\DataProvider $subject
* @param callable $proceed
* @param BucketInterface $bucket
* @param Dimension[] $dimensions
*
* @return Select
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
*/
public function aroundGetDataSet(\Magento\CatalogSearch\Model\Adapter\Mysql\Aggregation\DataProvider $subject, \Closure $proceed, BucketInterface $bucket, array $dimensions)
{
if ($bucket->getField() == 'category_ids') {
$currentScope = $dimensions['scope']->getValue();
$currentScopeId = $this->scopeResolver->getScope($currentScope)->getId();
$currenCategory = $this->layer->getCurrentCategory();
$derivedTable = $this->getSelect();
$derivedTable->from(['main_table' => $this->resource->getTableName('catalog_category_product_index')], ['entity_id' => 'product_id', 'value' => 'category_id'])->where('main_table.store_id = ?', $currentScopeId);
if (!empty($currenCategory)) {
$derivedTable->join(['category' => $this->resource->getTableName('catalog_category_entity')], 'main_table.category_id = category.entity_id', [])->where('`category`.`path` LIKE ?', $currenCategory->getPath() . '%')->where('`category`.`level` > ?', $currenCategory->getLevel());
}
$select = $this->getSelect();
$select->from(['main_table' => $derivedTable]);
return $select;
}
return $proceed($bucket, $dimensions);
}
示例11: detectDesign
/**
* Detect and apply design for the area
*
* @param \Magento\Framework\App\RequestInterface $request
* @return void
*/
public function detectDesign($request = null)
{
if ($this->_code == self::AREA_FRONTEND) {
$isDesignException = $request && $this->_applyUserAgentDesignException($request);
if (!$isDesignException) {
$this->_design->loadChange($this->_scopeResolver->getScope()->getId())->changeDesign($this->_getDesign());
}
}
}
示例12: getTaxRateIds
/**
* @param PriceBox $subject
* @return string
*/
private function getTaxRateIds(PriceBox $subject)
{
$rateIds = [];
$customerSession = $this->customerSession;
$billingAddress = $customerSession->getDefaultTaxBillingAddress();
$shippingAddress = $customerSession->getDefaultTaxShippingAddress();
$customerTaxClassId = $customerSession->getCustomerTaxClassId();
if (!empty($billingAddress)) {
$billingAddress = new \Magento\Framework\DataObject($billingAddress);
}
if (!empty($shippingAddress)) {
$shippingAddress = new \Magento\Framework\DataObject($shippingAddress);
}
if (!empty($billingAddress) || !empty($shippingAddress)) {
$rateRequest = $this->getTaxCalculation()->getRateRequest($billingAddress, $shippingAddress, $customerTaxClassId, $this->scopeResolver->getScope()->getId(), $this->customerSession->getCustomerId());
$rateRequest->setProductClassId($subject->getSaleableItem()->getTaxClassId());
$rateIds = $this->getTaxCalculation()->getResource()->getRateIds($rateRequest);
}
return implode('_', $rateIds);
}
示例13: prepareDimensions
/**
* @param Dimension[] $dimensions
* @return string[]
*/
private function prepareDimensions(array $dimensions)
{
$preparedDimensions = [];
foreach ($dimensions as $dimension) {
if ('scope' === $dimension->getName()) {
continue;
}
$preparedDimensions[] = $this->conditionManager->generateCondition($dimension->getName(), '=', $this->dimensionScopeResolver->getScope($dimension->getValue())->getId());
}
return $preparedDimensions;
}
示例14: processRangeNumeric
/**
* @param FilterInterface $filter
* @param string $query
* @param Attribute $attribute
* @return string
*/
private function processRangeNumeric(FilterInterface $filter, $query, $attribute)
{
$tableSuffix = $attribute->getBackendType() === 'decimal' ? '_decimal' : '';
$table = $this->resource->getTableName("catalog_product_index_eav{$tableSuffix}");
$select = $this->connection->select();
$currentStoreId = $this->scopeResolver->getScope()->getId();
$select->from(['main_table' => $table], 'entity_id')->columns([$filter->getField() => 'main_table.value'])->where('main_table.attribute_id = ?', $attribute->getAttributeId())->where('main_table.store_id = ?', $currentStoreId)->having($query);
$resultQuery = 'search_index.entity_id IN (
select entity_id from ' . $this->conditionManager->wrapBrackets($select) . ' as filter
)';
return $resultQuery;
}
示例15: process
/**
* Creates block object based on data and add it to the layout
*
* @param Layout\Reader\Context $readerContext
* @param Context $generatorContext
* @return $this
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
*/
public function process(Layout\Reader\Context $readerContext, Layout\Generator\Context $generatorContext)
{
$scheduledStructure = $readerContext->getScheduledStructure();
$layout = $generatorContext->getLayout();
$structure = $generatorContext->getStructure();
/** @var $blocks \Magento\Framework\View\Element\AbstractBlock[] */
$blocks = [];
$blockActions = [];
// Instantiate blocks and collect all actions data
foreach ($scheduledStructure->getElements() as $elementName => $element) {
list($type, $data) = $element;
if ($type === self::TYPE) {
try {
$block = $this->generateBlock($scheduledStructure, $structure, $elementName);
$blocks[$elementName] = $block;
$layout->setBlock($elementName, $block);
if (!empty($data['actions'])) {
$blockActions[$elementName] = $data['actions'];
}
} catch (\Exception $e) {
$this->handleRenderException($e);
unset($blocks[$elementName]);
}
}
}
// Set layout instance to all generated block (trigger _prepareLayout method)
foreach ($blocks as $elementName => $block) {
try {
$block->setLayout($layout);
$this->eventManager->dispatch('core_layout_block_create_after', ['block' => $block]);
} catch (\Exception $e) {
$this->handleRenderException($e);
$layout->setBlock($elementName, $this->exceptionHandlerBlockFactory->create(['blockName' => $elementName]));
unset($blockActions[$elementName]);
}
$scheduledStructure->unsetElement($elementName);
}
// Run all actions after layout initialization
foreach ($blockActions as $elementName => $actions) {
try {
foreach ($actions as $action) {
list($methodName, $actionArguments, $configPath, $scopeType) = $action;
if (empty($configPath) || $this->scopeConfig->isSetFlag($configPath, $scopeType, $this->scopeResolver->getScope())) {
$this->generateAction($blocks[$elementName], $methodName, $actionArguments);
}
}
} catch (\Exception $e) {
$this->handleRenderException($e);
$layout->setBlock($elementName, $this->exceptionHandlerBlockFactory->create(['blockName' => $elementName]));
}
}
return $this;
}