本文整理汇总了PHP中Magento\Framework\StoreManagerInterface类的典型用法代码示例。如果您正苦于以下问题:PHP StoreManagerInterface类的具体用法?PHP StoreManagerInterface怎么用?PHP StoreManagerInterface使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了StoreManagerInterface类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: __construct
/**
* @param \Magento\Customer\Model\Config\Share $configShare
* @param \Magento\Framework\StoreManagerInterface $storeManager
* @param string $namespace
* @param array $data
*/
public function __construct(\Magento\Customer\Model\Config\Share $configShare, \Magento\Framework\StoreManagerInterface $storeManager, $namespace = 'customer', array $data = array())
{
if ($configShare->isWebsiteScope()) {
$namespace .= '_' . $storeManager->getWebsite()->getCode();
}
parent::__construct($namespace, $data);
}
示例2: aroundDispatch
/**
* @param \Magento\Framework\App\Action\Action $subject
* @param callable $proceed
* @param \Magento\Framework\App\RequestInterface $request
* @return mixed
*/
public function aroundDispatch(\Magento\Framework\App\Action\Action $subject, \Closure $proceed, \Magento\Framework\App\RequestInterface $request)
{
$defaultStore = $this->storeManager->getWebsite()->getDefaultStore();
$this->httpContext->setValue(\Magento\Core\Helper\Data::CONTEXT_CURRENCY, $this->session->getCurrencyCode(), $defaultStore->getDefaultCurrency()->getCode());
$this->httpContext->setValue(\Magento\Core\Helper\Data::CONTEXT_STORE, $this->httpRequest->getParam('___store', $defaultStore->getStoreCodeFromCookie()), $this->storeManager->getWebsite()->getDefaultStore()->getCode());
return $proceed($request);
}
示例3: aroundDispatch
/**
* @param \Magento\Framework\App\Action\Action $subject
* @param callable $proceed
* @param \Magento\Framework\App\RequestInterface $request
*
* @return \Magento\Framework\App\ResponseInterface
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
* @throws \Magento\Framework\App\InitException
*/
public function aroundDispatch(\Magento\Framework\App\Action\Action $subject, \Closure $proceed, \Magento\Framework\App\RequestInterface $request)
{
if (!$this->_storeManager->getStore()->getIsActive()) {
throw new \Magento\Framework\App\InitException('Current store is not active.');
}
return $proceed($request);
}
示例4: 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;
}
示例5: setAddress
/**
* {@inheritdoc}
*/
public function setAddress($cartId, $addressData)
{
/** @var \Magento\Sales\Model\Quote $quote */
$quote = $this->quoteLoader->load($cartId, $this->storeManager->getStore()->getId());
if ($quote->isVirtual()) {
throw new NoSuchEntityException('Cart contains virtual product(s) only. Shipping address is not applicable');
}
/** @var \Magento\Sales\Model\Quote\Address $address */
$address = $this->quoteAddressFactory->create();
$this->addressValidator->validate($addressData);
if ($addressData->getId()) {
$address->load($addressData->getId());
}
$address = $this->addressConverter->convertDataObjectToModel($addressData, $address);
$address->setSameAsBilling(0);
$quote->setShippingAddress($address);
$quote->setDataChanges(true);
try {
$quote->save();
} catch (\Exception $e) {
$this->logger->logException($e);
throw new InputException('Unable to save address. Please, check input data.');
}
return $quote->getShippingAddress()->getId();
}
示例6: testProcessWithoutStoreCode
public function testProcessWithoutStoreCode()
{
$path = 'rest/V1/customerAccounts/createCustomer';
$result = $this->pathProcessor->process($path);
$this->assertEquals('/V1/customerAccounts/createCustomer', $result);
$this->assertEquals('default', $this->storeManager->getStore()->getCode());
}
示例7: getAddress
/**
* {@inheritdoc}
*/
public function getAddress($cartId)
{
$storeId = $this->storeManager->getStore()->getId();
/** @var \Magento\Sales\Model\Quote\Address $address */
$address = $this->quoteLoader->load($cartId, $storeId)->getBillingAddress();
return $this->addressConverter->convertModelToDataObject($address);
}
示例8: testSetNotIntStoreId
public function testSetNotIntStoreId()
{
$this->_storeManagerInterface->expects($this->once())->method('getStore');
$store = $this->_model->setStoreId('test');
$storeId = $store->getStoreId();
$this->assertEquals(0, $storeId);
}
示例9: set
/**
* {@inheritdoc}
*/
public function set(\Magento\Checkout\Service\V1\Data\Cart\PaymentMethod $method, $cartId)
{
$quote = $this->quoteLoader->load($cartId, $this->storeManager->getStore()->getId());
$payment = $this->paymentMethodBuilder->build($method, $quote);
if ($quote->isVirtual()) {
// check if billing address is set
if (is_null($quote->getBillingAddress()->getCountryId())) {
throw new InvalidTransitionException('Billing address is not set');
}
$quote->getBillingAddress()->setPaymentMethod($payment->getMethod());
} else {
// check if shipping address is set
if (is_null($quote->getShippingAddress()->getCountryId())) {
throw new InvalidTransitionException('Shipping address is not set');
}
$quote->getShippingAddress()->setPaymentMethod($payment->getMethod());
}
if (!$quote->isVirtual() && $quote->getShippingAddress()) {
$quote->getShippingAddress()->setCollectShippingRates(true);
}
if (!$this->zeroTotalValidator->isApplicable($payment->getMethodInstance(), $quote)) {
throw new InvalidTransitionException('The requested Payment Method is not available.');
}
$quote->setTotalsCollectedFlag(false)->collectTotals()->save();
return $quote->getPayment()->getId();
}
示例10: run
/**
* Run action
*
* @return void
*/
public function run()
{
$this->_lastRecord = $this->_timestamp($this->_round($this->getLastRecordDate()));
foreach ($this->_storeManager->getStores(false) as $store) {
$this->_process($store->getId());
}
}
示例11: execute
/**
* Display search result
*
* @return void
*/
public function execute()
{
/* @var $query \Magento\CatalogSearch\Model\Query */
$query = $this->_objectManager->get('Magento\\CatalogSearch\\Helper\\Data')->getQuery();
$query->setStoreId($this->_storeManager->getStore()->getId());
if ($query->getQueryText() != '') {
if ($this->_objectManager->get('Magento\\CatalogSearch\\Helper\\Data')->isMinQueryLength()) {
$query->setId(0)->setIsActive(1)->setIsProcessed(1);
} else {
if ($query->getId()) {
$query->setPopularity($query->getPopularity() + 1);
} else {
$query->setPopularity(1);
}
if ($query->getRedirect()) {
$query->save();
$this->getResponse()->setRedirect($query->getRedirect());
return;
} else {
$query->prepare();
}
}
$this->_objectManager->get('Magento\\CatalogSearch\\Helper\\Data')->checkNotes();
$this->_view->loadLayout();
$this->_view->getLayout()->initMessages();
$this->_view->renderLayout();
if (!$this->_objectManager->get('Magento\\CatalogSearch\\Helper\\Data')->isMinQueryLength()) {
$query->save();
}
} else {
$this->getResponse()->setRedirect($this->_redirect->getRedirectUrl());
}
}
示例12: setMethod
/**
* {@inheritdoc}
*/
public function setMethod($cartId, $carrierCode, $methodCode)
{
/** @var \Magento\Sales\Model\Quote $quote */
$quote = $this->quoteLoader->load($cartId, $this->storeManager->getStore()->getId());
if (0 == $quote->getItemsCount()) {
throw new InputException('Shipping method is not applicable for empty cart');
}
if ($quote->isVirtual()) {
throw new NoSuchEntityException('Cart contains virtual product(s) only. Shipping method is not applicable.');
}
$shippingAddress = $quote->getShippingAddress();
if (!$shippingAddress->getCountryId()) {
throw new StateException('Shipping address is not set');
}
$billingAddress = $quote->getBillingAddress();
if (!$billingAddress->getCountryId()) {
throw new StateException('Billing address is not set');
}
$shippingAddress->setShippingMethod($carrierCode . '_' . $methodCode);
if (!$shippingAddress->requestShippingRates()) {
throw new NoSuchEntityException('Carrier with such method not found: ' . $carrierCode . ', ' . $methodCode);
}
try {
$quote->collectTotals()->save();
} catch (\Exception $e) {
throw new CouldNotSaveException('Cannot set shipping method. ' . $e->getMessage());
}
return true;
}
示例13: dispatch
/**
* Set new customer group to all his quotes
*
* @param \Magento\Framework\Event\Observer $observer
* @return void
*/
public function dispatch(\Magento\Framework\Event\Observer $observer)
{
/** @var CustomerData $customerDataObject */
$customerDataObject = $observer->getEvent()->getCustomerDataObject();
/** @var CustomerData $origCustomerDataObject */
$origCustomerDataObject = $observer->getEvent()->getOrigCustomerDataObject();
if ($customerDataObject->getGroupId() !== $origCustomerDataObject->getGroupId()) {
/**
* It is needed to process customer's quotes for all websites
* if customer accounts are shared between all of them
*/
/** @var $websites \Magento\Store\Model\Website[] */
$websites = $this->_config->isWebsiteScope() ? array($this->_storeManager->getWebsite($customerDataObject->getWebsiteId())) : $this->_storeManager->getWebsites();
foreach ($websites as $website) {
$quote = $this->_quoteFactory->create();
$quote->setWebsite($website);
$quote->loadByCustomer($customerDataObject->getId());
if ($quote->getId()) {
$quote->setCustomerGroupId($customerDataObject->getGroupId());
$quote->collectTotals();
$quote->save();
}
}
}
}
示例14: _getConfigUrl
/**
* Get url for config settings where base url option can be changed
*
* @return string
*/
protected function _getConfigUrl()
{
$output = '';
$defaultUnsecure = $this->_config->getValue(\Magento\Store\Model\Store::XML_PATH_UNSECURE_BASE_URL, 'default');
$defaultSecure = $this->_config->getValue(\Magento\Store\Model\Store::XML_PATH_SECURE_BASE_URL, 'default');
if ($defaultSecure == \Magento\Store\Model\Store::BASE_URL_PLACEHOLDER || $defaultUnsecure == \Magento\Store\Model\Store::BASE_URL_PLACEHOLDER) {
$output = $this->_urlBuilder->getUrl('adminhtml/system_config/edit', array('section' => 'web'));
} else {
/** @var $dataCollection \Magento\Core\Model\Resource\Config\Data\Collection */
$dataCollection = $this->_configValueFactory->create()->getCollection();
$dataCollection->addValueFilter(\Magento\Store\Model\Store::BASE_URL_PLACEHOLDER);
/** @var $data \Magento\Framework\App\Config\ValueInterface */
foreach ($dataCollection as $data) {
if ($data->getScope() == 'stores') {
$code = $this->_storeManager->getStore($data->getScopeId())->getCode();
$output = $this->_urlBuilder->getUrl('adminhtml/system_config/edit', array('section' => 'web', 'store' => $code));
break;
} elseif ($data->getScope() == 'websites') {
$code = $this->_storeManager->getWebsite($data->getScopeId())->getCode();
$output = $this->_urlBuilder->getUrl('adminhtml/system_config/edit', array('section' => 'web', 'website' => $code));
break;
}
}
}
return $output;
}
示例15: _beforeSave
/**
* Prepare data before save
*
* @param \Magento\Framework\Object $object
* @return $this
*/
protected function _beforeSave($object)
{
if (!$object->getData($this->getAttribute()->getAttributeCode())) {
$object->setData($this->getAttribute()->getAttributeCode(), $this->_storeManager->getStore()->getId());
}
return $this;
}