本文整理汇总了PHP中Magento\Framework\StoreManagerInterface::setCurrentStore方法的典型用法代码示例。如果您正苦于以下问题:PHP StoreManagerInterface::setCurrentStore方法的具体用法?PHP StoreManagerInterface::setCurrentStore怎么用?PHP StoreManagerInterface::setCurrentStore使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Magento\Framework\StoreManagerInterface
的用法示例。
在下文中一共展示了StoreManagerInterface::setCurrentStore方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getCatalogPrice
/**
* Minimal price for "regular" user
*
* @param \Magento\Catalog\Model\Product $product
* @param null|\Magento\Store\Model\Store $store Store view
* @param bool $inclTax
* @return null|float
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
*/
public function getCatalogPrice(\Magento\Catalog\Model\Product $product, $store = null, $inclTax = false)
{
// Workaround to avoid loading stock status by admin's website
if ($store instanceof \Magento\Store\Model\Store) {
$oldStore = $this->storeManager->getStore();
$this->storeManager->setCurrentStore($store);
}
$subProducts = $product->getTypeInstance()->getAssociatedProducts($product);
if ($store instanceof \Magento\Store\Model\Store) {
$this->storeManager->setCurrentStore($oldStore);
}
if (!count($subProducts)) {
return null;
}
$minPrice = null;
foreach ($subProducts as $subProduct) {
$subProduct->setWebsiteId($product->getWebsiteId())->setCustomerGroupId($product->getCustomerGroupId());
if ($subProduct->isSalable()) {
if ($this->commonPriceModel->getCatalogPrice($subProduct) < $minPrice || $minPrice === null) {
$minPrice = $this->commonPriceModel->getCatalogPrice($subProduct);
$product->setTaxClassId($subProduct->getTaxClassId());
}
}
}
return $minPrice;
}
示例2: getCatalogPrice
/**
* Minimal price for "regular" user
*
* @param \Magento\Catalog\Model\Product $product
* @param null|\Magento\Store\Model\Store $store Store view
* @param bool $inclTax
* @return null|float
*/
public function getCatalogPrice(\Magento\Catalog\Model\Product $product, $store = null, $inclTax = false)
{
if ($store instanceof \Magento\Store\Model\Store) {
$oldStore = $this->storeManager->getStore();
$this->storeManager->setCurrentStore($store);
}
$this->coreRegistry->unregister('rule_data');
$this->coreRegistry->register('rule_data', new \Magento\Framework\Object(array('store_id' => $product->getStoreId(), 'website_id' => $product->getWebsiteId(), 'customer_group_id' => $product->getCustomerGroupId())));
$minPrice = $product->getPriceModel()->getTotalPrices($product, 'min', $inclTax);
if ($store instanceof \Magento\Store\Model\Store) {
$this->storeManager->setCurrentStore($oldStore);
}
return $minPrice;
}
示例3: process
/**
* Process path info
*
* @param string $pathInfo
* @return string
* @throws NoSuchEntityException
*/
public function process($pathInfo)
{
$pathParts = $this->stripPathBeforeStorecode($pathInfo);
$storeCode = $pathParts[0];
$stores = $this->storeManager->getStores(false, true);
if (isset($stores[$storeCode])) {
$this->storeManager->setCurrentStore($storeCode);
$path = '/' . (isset($pathParts[1]) ? $pathParts[1] : '');
} else {
$this->storeManager->setCurrentStore(\Magento\Store\Model\Store::DEFAULT_CODE);
$path = '/' . implode('/', $pathParts);
}
return $path;
}
示例4: process
/**
* Process path info
*
* @param \Magento\Framework\App\RequestInterface $request
* @param string $pathInfo
* @return string
*/
public function process(\Magento\Framework\App\RequestInterface $request, $pathInfo)
{
$pathParts = explode('/', ltrim($pathInfo, '/'), 2);
$storeCode = $pathParts[0];
$stores = $this->_storeManager->getStores(false, true);
if (isset($stores[$storeCode]) && $stores[$storeCode]->isUseStoreInUrl()) {
if (!$request->isDirectAccessFrontendName($storeCode)) {
$this->_storeManager->setCurrentStore($storeCode);
$pathInfo = '/' . (isset($pathParts[1]) ? $pathParts[1] : '');
return $pathInfo;
} elseif (!empty($storeCode)) {
$request->setActionName('noroute');
return $pathInfo;
}
return $pathInfo;
}
return $pathInfo;
}
示例5: stopEnvironmentEmulation
/**
* Stop environment emulation
*
* Function restores initial store environment
*
* @param \Magento\Framework\Object $initialEnvironmentInfo information about environment of the initial store
* @return \Magento\Core\Model\App\Emulation
*/
public function stopEnvironmentEmulation(\Magento\Framework\Object $initialEnvironmentInfo)
{
$this->_restoreInitialInlineTranslation($initialEnvironmentInfo->getInitialTranslateInline());
$initialDesign = $initialEnvironmentInfo->getInitialDesign();
$this->_restoreInitialDesign($initialDesign);
// Current store needs to be changed right before locale change and after design change
$this->_storeManager->setCurrentStore($initialDesign['store']);
$this->_restoreInitialLocale($initialEnvironmentInfo->getInitialLocaleCode(), $initialDesign['area']);
return $this;
}
示例6: getPdf
/**
* Return PDF document
*
* @param array $invoices
* @return \Zend_Pdf
*/
public function getPdf($invoices = array())
{
$this->_beforeGetPdf();
$this->_initRenderer('invoice');
$pdf = new \Zend_Pdf();
$this->_setPdf($pdf);
$style = new \Zend_Pdf_Style();
$this->_setFontBold($style, 10);
foreach ($invoices as $invoice) {
if ($invoice->getStoreId()) {
$this->_localeResolver->emulate($invoice->getStoreId());
$this->_storeManager->setCurrentStore($invoice->getStoreId());
}
$page = $this->newPage();
$order = $invoice->getOrder();
/* Add image */
$this->insertLogo($page, $invoice->getStore());
/* Add address */
$this->insertAddress($page, $invoice->getStore());
/* Add head */
$this->insertOrder($page, $order, $this->_scopeConfig->isSetFlag(self::XML_PATH_SALES_PDF_INVOICE_PUT_ORDER_ID, \Magento\Store\Model\ScopeInterface::SCOPE_STORE, $order->getStoreId()));
/* Add document text and number */
$this->insertDocumentNumber($page, __('Invoice # ') . $invoice->getIncrementId());
/* Add table */
$this->_drawHeader($page);
/* Add body */
foreach ($invoice->getAllItems() as $item) {
if ($item->getOrderItem()->getParentItem()) {
continue;
}
/* Draw item */
$this->_drawItem($item, $page, $order);
$page = end($pdf->pages);
}
/* Add totals */
$this->insertTotals($page, $invoice);
if ($invoice->getStoreId()) {
$this->_localeResolver->revert();
}
}
$this->_afterGetPdf();
return $pdf;
}
示例7: getPdf
/**
* Format pdf file
*
* @param null $shipment
* @return \Zend_Pdf
*/
public function getPdf($shipment = null)
{
$this->_beforeGetPdf();
$this->_initRenderer('shipment');
$pdf = new \Zend_Pdf();
$this->_setPdf($pdf);
$page = $this->newPage();
if ($shipment->getStoreId()) {
$this->_localeResolver->emulate($shipment->getStoreId());
$this->_storeManager->setCurrentStore($shipment->getStoreId());
}
$this->_setFontRegular($page);
$this->_drawHeaderBlock($page);
$this->y = 740;
$this->_drawPackageBlock($page);
$page->setFillColor(new \Zend_Pdf_Color_GrayScale(0));
$this->_afterGetPdf();
if ($shipment->getStoreId()) {
$this->_localeResolver->revert();
}
return $pdf;
}
示例8: _reinitStores
/**
* Initialize currently ran store
*
* @param \Magento\Framework\StoreManagerInterface $storage
* @param array $arguments
* @return void
* @throws \Magento\Framework\App\InitException
*/
protected function _reinitStores(\Magento\Framework\StoreManagerInterface $storage, $arguments)
{
Profiler::start('init_stores');
$storage->reinitStores();
Profiler::stop('init_stores');
$scopeCode = $arguments['scopeCode'];
$scopeType = $arguments['scopeType'] ?: ScopeInterface::SCOPE_STORE;
if (empty($scopeCode) && false == is_null($storage->getWebsite(true))) {
$scopeCode = $storage->getWebsite(true)->getCode();
$scopeType = ScopeInterface::SCOPE_WEBSITE;
}
switch ($scopeType) {
case ScopeInterface::SCOPE_STORE:
$storage->setCurrentStore($scopeCode);
break;
case ScopeInterface::SCOPE_GROUP:
$storage->setCurrentStore($this->_getStoreByGroup($storage, $scopeCode));
break;
case ScopeInterface::SCOPE_WEBSITE:
$storage->setCurrentStore($this->_getStoreByWebsite($storage, $scopeCode));
break;
default:
throw new \Magento\Framework\App\InitException('Store Manager has not been initialized properly');
}
$currentStore = $storage->getStore()->getCode();
if (!empty($currentStore)) {
$this->_checkCookieStore($storage, $scopeType);
$this->_checkRequestStore($storage, $scopeType);
}
}
示例9: execute
/**
* Search for attributes by part of attribute's label in admin store
*
* @return void
*/
public function execute()
{
$this->storeManager->setCurrentStore(\Magento\Store\Model\Store::ADMIN_CODE);
$this->getResponse()->representJson($this->coreHelper->jsonEncode($this->attributeList->getSuggestedAttributes($this->getRequest()->getParam('label_part'))));
}