本文整理匯總了PHP中Magento\Store\Model\StoreManagerInterface::setCurrentStore方法的典型用法代碼示例。如果您正苦於以下問題:PHP StoreManagerInterface::setCurrentStore方法的具體用法?PHP StoreManagerInterface::setCurrentStore怎麽用?PHP StoreManagerInterface::setCurrentStore使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類Magento\Store\Model\StoreManagerInterface
的用法示例。
在下文中一共展示了StoreManagerInterface::setCurrentStore方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: getCatalogPrice
/**
* {@inheritdoc}
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
*/
public function getCatalogPrice(\Magento\Catalog\Model\Product $product, \Magento\Store\Api\Data\StoreInterface $store = null, $inclTax = false)
{
// Workaround to avoid loading stock status by admin's website
if ($store instanceof \Magento\Store\Api\Data\StoreInterface) {
$currentStore = $this->storeManager->getStore();
$this->storeManager->setCurrentStore($store->getId());
}
$subProducts = $product->getTypeInstance()->getAssociatedProducts($product);
if ($store instanceof \Magento\Store\Api\Data\StoreInterface) {
$this->storeManager->setCurrentStore($currentStore->getId());
}
if (!$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: executeInternal
/**
* Search for attributes by part of attribute's label in admin store
*
* @return void
*/
public function executeInternal()
{
$this->storeManager->setCurrentStore(\Magento\Store\Model\Store::ADMIN_CODE);
$collection = $this->collectionFactory->create();
$collection->addFieldToFilter('main_table.attribute_id', $this->getRequest()->getParam('attributes'));
$attributes = [];
foreach ($collection->getItems() as $attribute) {
$attributes[] = ['id' => $attribute->getId(), 'label' => $attribute->getFrontendLabel(), 'code' => $attribute->getAttributeCode(), 'options' => $attribute->getSource()->getAllOptions(false)];
}
$this->getResponse()->representJson($this->jsonHelper->jsonEncode($attributes));
}
示例3: 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;
}
示例4: 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;
}
示例5: 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;
}
示例6: 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;
}
示例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: addOrder
/**
* Add one order to customer.
*
* @param $customer
* @param $itemsData
*/
public function addOrder($customer, $itemsData)
{
/* create order for Russian store/stock */
$this->_manStore->setCurrentStore(self::STORE_ID_RUS);
$store = $this->_manStore->getStore();
/** @var \Magento\Quote\Model\Quote $quote */
$quote = $this->_manObj->create(\Magento\Quote\Model\Quote::class);
$quote->setStore($store);
$quote->assignCustomer($customer);
$quote->setInventoryProcessed(false);
//not effect inventory
/** Populate orders with data. */
$this->_populateQuoteItems($quote);
$this->_populateQuoteAddrShipping($quote, $customer);
$this->_populateQuoteAddrBilling($quote, $customer);
$this->_populateQuoteShippingMethod($quote);
$this->_populateQuotePaymentMethod($quote);
/* save quote then reload it by ID to create IDs for items (see MOBI-434, $_items, $_data['items'], $_data['items_collection']) */
$quote->collectTotals();
$quote->save();
$id = $quote->getId();
$quote = $this->_manObj->create(\Magento\Quote\Model\Quote::class);
$quote->load($id);
$quoteItems = $quote->getItemsCollection();
// Create Order From Quote
/** @var \Magento\Sales\Api\Data\OrderInterface $order */
$order = $this->_manQuote->submit($quote);
$items = $order->getItems();
$item = reset($items);
$item->setBaseOriginalPrice(8);
$item->save();
$order->save();
/* register PV */
$this->_manEvent->dispatch('checkout_submit_all_after', ['order' => $order, 'quote' => $quote]);
/* prepare invoice */
$invoice = $this->_manInvoice->prepareInvoice($order);
$invoice->register();
$invoice->save();
// $invoiceId = $invoice->getEntityId();
/* update date paid in PV register */
// $orderId = $order->getEntityId();
// $bind = [
// \Praxigento\Pv\Data\Entity\Sale::ATTR_DATE_PAID => self::DATE_PAID
// ];
// $this->_repoPvSale->updateById($orderId, $bind);
/* transfer PV to customer account */
// $invoice->load($invoiceId);
// $order->load($orderId);
$order->setState(\Magento\Sales\Model\Order::STATE_PROCESSING);
$this->_manEvent->dispatch('sales_order_invoice_pay', ['order' => $order, 'invoice' => $invoice]);
}
示例9: stopEnvironmentEmulation
/**
* Stop environment emulation
*
* Function restores initial store environment
*
* @return \Magento\Store\Model\App\Emulation
*/
public function stopEnvironmentEmulation()
{
if ($this->initialEnvironmentInfo === null) {
return $this;
}
$this->_restoreInitialInlineTranslation($this->initialEnvironmentInfo->getInitialTranslateInline());
$initialDesign = $this->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($this->initialEnvironmentInfo->getInitialLocaleCode(), $initialDesign['area']);
$this->initialEnvironmentInfo = null;
return $this;
}
示例10: 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];
try {
/** @var \Magento\Store\Api\Data\StoreInterface $store */
$store = $this->storeManager->getStore($storeCode);
} catch (NoSuchEntityException $e) {
return $pathInfo;
}
if ($store->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;
}
示例11: getPdf
/**
* Return PDF document
*
* @param array $creditmemos
* @return \Zend_Pdf
*/
public function getPdf($creditmemos = array())
{
$this->_beforeGetPdf();
$this->_initRenderer('creditmemo');
$pdf = new \Zend_Pdf();
$this->_setPdf($pdf);
$style = new \Zend_Pdf_Style();
$this->_setFontBold($style, 10);
foreach ($creditmemos as $creditmemo) {
if ($creditmemo->getStoreId()) {
$this->_localeResolver->emulate($creditmemo->getStoreId());
$this->_storeManager->setCurrentStore($creditmemo->getStoreId());
}
$page = $this->newPage();
$order = $creditmemo->getOrder();
/* Add image */
$this->insertLogo($page, $creditmemo->getStore());
/* Add address */
$this->insertAddress($page, $creditmemo->getStore());
/* Add head */
$this->insertOrder($page, $order, $this->_scopeConfig->isSetFlag(self::XML_PATH_SALES_PDF_CREDITMEMO_PUT_ORDER_ID, \Magento\Store\Model\ScopeInterface::SCOPE_STORE, $order->getStoreId()));
/* Add document text and number */
$this->insertDocumentNumber($page, __('Credit Memo # ') . $creditmemo->getIncrementId());
/* Add table head */
$this->_drawHeader($page);
/* Add body */
foreach ($creditmemo->getAllItems() as $item) {
if ($item->getOrderItem()->getParentItem()) {
continue;
}
/* Draw item */
$this->_drawItem($item, $page, $order);
$page = end($pdf->pages);
}
/* Add totals */
$this->insertTotals($page, $creditmemo);
}
$this->_afterGetPdf();
if ($creditmemo->getStoreId()) {
$this->_localeResolver->revert();
}
return $pdf;
}
示例12: _reinitStores
/**
* Initialize currently ran store
*
* @param \Magento\Store\Model\StoreManagerInterface $storage
* @param array $arguments
* @return void
* @throws \Magento\Framework\Exception\State\InitException
*/
protected function _reinitStores(\Magento\Store\Model\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 == ($storage->getWebsite(true) === null)) {
$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\Exception\State\InitException(__('Store Manager has not been initialized properly'));
}
$currentStore = $storage->getStore()->getCode();
if (!empty($currentStore)) {
$this->_checkCookieStore($storage, $scopeType);
$this->_checkRequestStore($storage, $scopeType);
}
}
示例13: execute
/**
* Get attributes
*
* @return void
*/
public function execute()
{
$this->storeManager->setCurrentStore(\Magento\Store\Model\Store::ADMIN_CODE);
$attributes = $this->attributesList->getAttributes($this->getRequest()->getParam('attributes'));
$this->getResponse()->representJson($this->jsonHelper->jsonEncode($attributes));
}
示例14: executeInternal
/**
* Search for attributes by part of attribute's label in admin store
*
* @return void
*/
public function executeInternal()
{
$this->storeManager->setCurrentStore(\Magento\Store\Model\Store::ADMIN_CODE);
$this->getResponse()->representJson($this->jsonHelper->jsonEncode($this->attributeList->getSuggestedAttributes($this->getRequest()->getParam('label_part'))));
}
示例15: execute
/**
* Category save
*
* @return \Magento\Framework\Controller\ResultInterface
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
* @SuppressWarnings(PHPMD.NPathComplexity)
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
*/
public function execute()
{
/** @var \Magento\Backend\Model\View\Result\Redirect $resultRedirect */
$resultRedirect = $this->resultRedirectFactory->create();
$category = $this->_initCategory();
if (!$category) {
return $resultRedirect->setPath('catalog/*/', ['_current' => true, 'id' => null]);
}
$data['general'] = $this->getRequest()->getPostValue();
$categoryPostData = $data['general'];
$isNewCategory = !isset($categoryPostData['entity_id']);
$categoryPostData = $this->stringToBoolConverting($categoryPostData);
$categoryPostData = $this->imagePreprocessing($categoryPostData);
$categoryPostData = $this->dateTimePreprocessing($category, $categoryPostData);
$storeId = isset($categoryPostData['store_id']) ? $categoryPostData['store_id'] : null;
$store = $this->storeManager->getStore($storeId);
$this->storeManager->setCurrentStore($store->getCode());
$parentId = isset($categoryPostData['parent']) ? $categoryPostData['parent'] : null;
if ($categoryPostData) {
$category->addData($this->_filterCategoryPostData($categoryPostData));
if ($isNewCategory) {
$parentCategory = $this->getParentCategory($parentId, $storeId);
$category->setPath($parentCategory->getPath());
$category->setParentId($parentCategory->getId());
}
/**
* Process "Use Config Settings" checkboxes
*/
$useConfig = [];
if (isset($categoryPostData['use_config']) && !empty($categoryPostData['use_config'])) {
foreach ($categoryPostData['use_config'] as $attributeCode => $attributeValue) {
if ($attributeValue) {
$useConfig[] = $attributeCode;
$category->setData($attributeCode, null);
}
}
}
$category->setAttributeSetId($category->getDefaultAttributeSetId());
if (isset($categoryPostData['category_products']) && is_string($categoryPostData['category_products']) && !$category->getProductsReadonly()) {
$products = json_decode($categoryPostData['category_products'], true);
$category->setPostedProducts($products);
}
$this->_eventManager->dispatch('catalog_category_prepare_save', ['category' => $category, 'request' => $this->getRequest()]);
/**
* Check "Use Default Value" checkboxes values
*/
if (isset($categoryPostData['use_default']) && !empty($categoryPostData['use_default'])) {
foreach ($categoryPostData['use_default'] as $attributeCode => $attributeValue) {
if ($attributeValue) {
$category->setData($attributeCode, null);
}
}
}
/**
* Proceed with $_POST['use_config']
* set into category model for processing through validation
*/
$category->setData('use_post_data_config', $useConfig);
try {
$categoryResource = $category->getResource();
if ($category->hasCustomDesignTo()) {
$categoryResource->getAttribute('custom_design_from')->setMaxValue($category->getCustomDesignTo());
}
$validate = $category->validate();
if ($validate !== true) {
foreach ($validate as $code => $error) {
if ($error === true) {
$attribute = $categoryResource->getAttribute($code)->getFrontend()->getLabel();
throw new \Magento\Framework\Exception\LocalizedException(__('Attribute "%1" is required.', $attribute));
} else {
throw new \Exception($error);
}
}
}
$category->unsetData('use_post_data_config');
$category->save();
$this->messageManager->addSuccess(__('You saved the category.'));
} catch (\Magento\Framework\Exception\AlreadyExistsException $e) {
$this->messageManager->addError($e->getMessage());
$this->_objectManager->get(\Psr\Log\LoggerInterface::class)->critical($e);
$this->_getSession()->setCategoryData($categoryPostData);
} catch (\Magento\Framework\Exception\LocalizedException $e) {
$this->messageManager->addError($e->getMessage());
$this->_objectManager->get(\Psr\Log\LoggerInterface::class)->critical($e);
$this->_getSession()->setCategoryData($categoryPostData);
} catch (\Exception $e) {
$this->messageManager->addError(__('Something went wrong while saving the category.'));
$this->_objectManager->get(\Psr\Log\LoggerInterface::class)->critical($e);
$this->_getSession()->setCategoryData($categoryPostData);
}
}
$hasError = (bool) $this->messageManager->getMessages()->getCountByType(\Magento\Framework\Message\MessageInterface::TYPE_ERROR);
//.........這裏部分代碼省略.........