Beispiel #1
1
 /**
  * Read configuration by code
  *
  * @param string $code
  * @return array
  */
 public function read($code = null)
 {
     if ($this->_appState->isInstalled()) {
         if (empty($code)) {
             $store = $this->_storeManager->getStore();
         } elseif ($code == \Magento\Framework\App\ScopeInterface::SCOPE_DEFAULT) {
             $store = $this->_storeManager->getDefaultStoreView();
         } else {
             $store = $this->_storeFactory->create();
             $store->load($code);
         }
         if (!$store->getCode()) {
             throw NoSuchEntityException::singleField('storeCode', $code);
         }
         $websiteConfig = $this->_scopePool->getScope(\Magento\Store\Model\ScopeInterface::SCOPE_WEBSITE, $store->getWebsite()->getCode())->getSource();
         $config = array_replace_recursive($websiteConfig, $this->_initialConfig->getData("stores|{$code}"));
         $collection = $this->_collectionFactory->create(array('scope' => \Magento\Store\Model\ScopeInterface::SCOPE_STORES, 'scopeId' => $store->getId()));
         $dbStoreConfig = array();
         foreach ($collection as $item) {
             $dbStoreConfig[$item->getPath()] = $item->getValue();
         }
         $config = $this->_converter->convert($dbStoreConfig, $config);
     } else {
         $websiteConfig = $this->_scopePool->getScope(\Magento\Store\Model\ScopeInterface::SCOPE_WEBSITE, \Magento\Framework\App\ScopeInterface::SCOPE_DEFAULT)->getSource();
         $config = $this->_converter->convert($websiteConfig, $this->_initialConfig->getData("stores|{$code}"));
     }
     return $config;
 }
Beispiel #2
0
 /**
  * Prepare group specific fieldset
  *
  * @param \Magento\Framework\Data\Form $form
  * @return void
  * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
  */
 protected function _prepareStoreFieldset(\Magento\Framework\Data\Form $form)
 {
     $groupModel = $this->_coreRegistry->registry('store_data');
     $postData = $this->_coreRegistry->registry('store_post_data');
     if ($postData) {
         $groupModel->setData($postData['group']);
     }
     $fieldset = $form->addFieldset('group_fieldset', ['legend' => __('Store Information')]);
     $storeAction = $this->_coreRegistry->registry('store_action');
     if ($storeAction == 'edit' || $storeAction == 'add') {
         $websites = $this->_websiteFactory->create()->getCollection()->toOptionArray();
         $fieldset->addField('group_website_id', 'select', ['name' => 'group[website_id]', 'label' => __('Web Site'), 'value' => $groupModel->getWebsiteId(), 'values' => $websites, 'required' => true, 'disabled' => $groupModel->isReadOnly()]);
         if ($groupModel->getId() && $groupModel->getWebsite()->getDefaultGroupId() == $groupModel->getId()) {
             if ($groupModel->getWebsite()->getIsDefault() || $groupModel->getWebsite()->getGroupsCount() == 1) {
                 $form->getElement('group_website_id')->setDisabled(true);
                 $fieldset->addField('group_hidden_website_id', 'hidden', ['name' => 'group[website_id]', 'no_span' => true, 'value' => $groupModel->getWebsiteId()]);
             } else {
                 $fieldset->addField('group_original_website_id', 'hidden', ['name' => 'group[original_website_id]', 'no_span' => true, 'value' => $groupModel->getWebsiteId()]);
             }
         }
     }
     $fieldset->addField('group_name', 'text', ['name' => 'group[name]', 'label' => __('Name'), 'value' => $groupModel->getName(), 'required' => true, 'disabled' => $groupModel->isReadOnly()]);
     $categories = $this->_category->toOptionArray();
     $fieldset->addField('group_root_category_id', 'select', ['name' => 'group[root_category_id]', 'label' => __('Root Category'), 'value' => $groupModel->getRootCategoryId(), 'values' => $categories, 'required' => true, 'disabled' => $groupModel->isReadOnly()]);
     if ($this->_coreRegistry->registry('store_action') == 'edit') {
         $storeActive = 1;
         $stores = $this->_storeFactory->create()->getCollection()->addGroupFilter($groupModel->getId())->addStatusFilter($storeActive)->toOptionArray();
         $fieldset->addField('group_default_store_id', 'select', ['name' => 'group[default_store_id]', 'label' => __('Default Store View'), 'value' => $groupModel->getDefaultStoreId(), 'values' => $stores, 'required' => false, 'disabled' => $groupModel->isReadOnly()]);
     }
     $fieldset->addField('group_group_id', 'hidden', ['name' => 'group[group_id]', 'no_span' => true, 'value' => $groupModel->getId()]);
 }
 /**
  * Build product based on user request
  *
  * @param RequestInterface $request
  * @return \Magento\Catalog\Model\Product
  */
 public function build(RequestInterface $request)
 {
     $productId = (int) $request->getParam('id');
     /** @var $product \Magento\Catalog\Model\Product */
     $product = $this->productFactory->create();
     $product->setStoreId($request->getParam('store', 0));
     $store = $this->storeFactory->create();
     $store->load($request->getParam('store', 0));
     $typeId = $request->getParam('type');
     if (!$productId && $typeId) {
         $product->setTypeId($typeId);
     }
     $product->setData('_edit_mode', true);
     if ($productId) {
         try {
             $product->load($productId);
         } catch (\Exception $e) {
             $product->setTypeId(\Magento\Catalog\Model\Product\Type::DEFAULT_TYPE);
             $this->logger->critical($e);
         }
     }
     $setId = (int) $request->getParam('set');
     if ($setId) {
         $product->setAttributeSetId($setId);
     }
     $this->registry->register('product', $product);
     $this->registry->register('current_product', $product);
     $this->registry->register('current_store', $store);
     $this->wysiwygConfig->setStoreId($request->getParam('store'));
     return $product;
 }
 /**
  * @param \Magento\Store\Model\StoreFactory $storeFactory
  * @param \Magento\Store\Model\WebsiteFactory $websiteFactory
  * @param \Magento\Store\Model\GroupFactory $groupFactory
  */
 public function __construct(\Magento\Store\Model\StoreFactory $storeFactory, \Magento\Store\Model\WebsiteFactory $websiteFactory, \Magento\Store\Model\GroupFactory $groupFactory)
 {
     $this->_store = $storeFactory->create();
     $this->_store->setId(\Magento\Store\Model\Store::DISTRO_STORE_ID);
     $this->_store->setCode(\Magento\Store\Model\Store::DEFAULT_CODE);
     $this->_website = $websiteFactory->create();
     $this->_group = $groupFactory->create();
 }
Beispiel #5
0
 /**
  * @return mixed
  */
 public function getStores()
 {
     $stores = $this->getData('stores');
     if ($stores === null) {
         $stores = $this->_storeFactory->create()->getResourceCollection()->setLoadDefault(false)->load();
         $this->setData('stores', $stores);
     }
     return $stores;
 }
 /**
  * {@inheritdoc}
  */
 public function getById($id)
 {
     if (isset($this->entitiesById[$id])) {
         return $this->entitiesById[$id];
     }
     $store = $this->storeFactory->create();
     $store->load($id);
     if ($store->getId() === null) {
         throw new NoSuchEntityException(__('Requested store is not found'));
     }
     $this->entitiesById[$id] = $store;
     $this->entities[$store->getCode()] = $store;
     return $store;
 }
Beispiel #7
0
 protected function setUp()
 {
     $this->objectManager = new ObjectManager($this);
     $this->loggerMock = $this->getMock(LoggerInterface::class);
     $this->productFactoryMock = $this->getMock(ProductFactory::class, ['create'], [], '', false);
     $this->registryMock = $this->getMock(Registry::class, [], [], '', false);
     $this->wysiwygConfigMock = $this->getMock(WysiwygConfig::class, ['setStoreId'], [], '', false);
     $this->requestMock = $this->getMock(Http::class, [], [], '', false);
     $methods = ['setStoreId', 'setData', 'load', '__wakeup', 'setAttributeSetId', 'setTypeId'];
     $this->productMock = $this->getMock('Magento\\Catalog\\Model\\Product', $methods, [], '', false);
     $this->storeFactoryMock = $this->getMockBuilder(StoreFactory::class)->setMethods(['create'])->disableOriginalConstructor()->getMock();
     $this->storeMock = $this->getMockBuilder(StoreInterface::class)->setMethods(['load'])->getMockForAbstractClass();
     $this->storeFactoryMock->expects($this->any())->method('create')->willReturn($this->storeMock);
     $this->builder = $this->objectManager->getObject(Builder::class, ['productFactory' => $this->productFactoryMock, 'logger' => $this->loggerMock, 'registry' => $this->registryMock, 'wysiwygConfig' => $this->wysiwygConfigMock, 'storeFactory' => $this->storeFactoryMock]);
 }
Beispiel #8
0
 /**
  * Get scope for the url instance
  *
  * @return \Magento\Store\Model\Store
  */
 protected function _getScope()
 {
     if (!$this->_scope) {
         $this->_scope = $this->_storeFactory->create(['url' => $this, 'data' => ['code' => 'admin', 'force_disable_rewrites' => false, 'disable_store_in_url' => true]]);
     }
     return $this->_scope;
 }
 public function indexAction()
 {
     if (Praxigento_LoginAs_Config::cfgGeneralEnabled()) {
         /** define operator name */
         /** @var $session Mage_Admin_Model_Session */
         $session = $this->backendAuthSession;
         if ($session->isLoggedIn()) {
             /** @var $user Mage_Admin_Model_User */
             $user = $session->getUser();
             $operator = $user->getName() . ' (' . $user->getEmail() . ')';
             /** if there is customer data in request */
             if (!is_null($this->getRequest()->getParams())) {
                 $params = $this->getRequest()->getParams();
                 if (!is_null($params[Praxigento_LoginAs_Config::REQ_PARAM_LAS_ID])) {
                     /** extract customer ID from request and load customer data */
                     $customerId = $params[Praxigento_LoginAs_Config::REQ_PARAM_LAS_ID];
                     /** @var $customer Mage_Customer_Model_Customer */
                     $customer = $this->customerCustomerFactory->create()->load($customerId);
                     if ($customer->getId() == $customerId) {
                         $customerName = $customer->getName();
                         /** define URL to login to customer's website */
                         $wsId = $customer->getData('website_id');
                         if (is_null($wsId)) {
                             $wsId = $this->storeManager->getStore()->getWebsiteId();
                         }
                         /** @var $website Mage_Core_Model_Website */
                         $website = $this->storeWebsiteFactory->create()->load($wsId);
                         $defStoreId = $website->getDefaultStore()->getId();
                         $baseTarget = $this->scopeConfig->getValue(\Magento\Framework\UrlInterface::XML_PATH_SECURE_URL, \Magento\Store\Model\ScopeInterface::SCOPE_STORE, $defStoreId);
                         $baseSource = $this->scopeConfig->getValue(\Magento\Framework\UrlInterface::XML_PATH_SECURE_URL, \Magento\Store\Model\ScopeInterface::SCOPE_STORE);
                         /** compose redirection URL and replace current base by target base */
                         $urlModel = $this->framework->create();
                         $store = $this->storeStoreFactory->create()->load($defStoreId);
                         $urlModel->setStore($store);
                         $url = $urlModel->getUrl(Praxigento_LoginAs_Config::XMLCFG_ROUTER_FRONT . Praxigento_LoginAs_Config::ROUTE_CUSTOMER_LOGINAS);
                         $url = str_replace($baseSource, $baseTarget, $url);
                         /** compose authentication package */
                         /** @var $authPack Praxigento_LoginAs_Model_Package */
                         $authPack = $this->loginAsPackage;
                         $authPack->setAdminName($operator);
                         $authPack->setCustomerId($customerId);
                         $authPack->setCustomerName($customerName);
                         $authPack->setRedirectUrl($url);
                         $validatorData = $session->getValidatorData();
                         $ip = $validatorData['remote_addr'];
                         $authPack->setIp($ip);
                         /** save login data to file */
                         $authPack->saveAsFile();
                         /** log event */
                         $log = Praxigento_LoginAs_Model_Logger::getLogger($this);
                         $log->trace("Operator '{$operator}' is redirected to front from ip '{$ip}' to login" . " as customer '{$customerName}' ({$customerId}).");
                     }
                     $bu = var_export($this->getLayout()->getUpdate()->getHandles(), true);
                     /** load layout and render blocks */
                     $this->loadLayout()->renderLayout();
                 }
             }
         }
     }
 }
Beispiel #10
0
 /**
  * Retrieve application store object
  *
  * @param null|string|bool|int|Store $storeId
  * @return Store
  * @throws \Magento\Framework\Exception\State\InitException
  * @SuppressWarnings(PHPMD.CyclomaticComplexity)
  * @SuppressWarnings(PHPMD.NPathComplexity)
  */
 public function getStore($storeId = null)
 {
     if ($this->_appState->getUpdateMode()) {
         return $this->_getDefaultStore();
     }
     if ($storeId === true && $this->hasSingleStore()) {
         return $this->_store;
     }
     if (!isset($storeId) || '' === $storeId || $storeId === true) {
         $storeId = $this->_currentStore;
     }
     if ($storeId instanceof Store) {
         return $storeId;
     }
     if (empty($this->_stores[$storeId])) {
         $store = $this->_storeFactory->create();
         if (is_numeric($storeId)) {
             $store->load($storeId);
         } elseif (is_string($storeId)) {
             $store->load($storeId, 'code');
         }
         if (!$store->getCode()) {
             throw new \Magento\Framework\Exception\State\InitException(__('Store Manager has been initialized not properly'));
         }
         $this->_stores[$store->getStoreId()] = $store;
         $this->_stores[$store->getCode()] = $store;
     }
     return $this->_stores[$storeId];
 }
Beispiel #11
0
 /**
  * @return $this
  * @throws \Magento\Framework\Exception\LocalizedException
  */
 public function afterSave()
 {
     /** @var $collection \Magento\Config\Model\Resource\Config\Data\Collection */
     $collection = $this->_configsFactory->create();
     $collection->addPathFilter('currency/options');
     $values = explode(',', $this->getValue());
     $exceptions = [];
     foreach ($collection as $data) {
         $match = false;
         $scopeName = __('Default scope');
         if (preg_match('/(base|default)$/', $data->getPath(), $match)) {
             if (!in_array($data->getValue(), $values)) {
                 $currencyName = $this->_localeCurrency->getCurrency($data->getValue())->getName();
                 if ($match[1] == 'base') {
                     $fieldName = __('Base currency');
                 } else {
                     $fieldName = __('Display default currency');
                 }
                 switch ($data->getScope()) {
                     case \Magento\Framework\App\ScopeInterface::SCOPE_DEFAULT:
                         $scopeName = __('Default scope');
                         break;
                     case \Magento\Store\Model\ScopeInterface::SCOPE_WEBSITE:
                         /** @var $website \Magento\Store\Model\Website */
                         $website = $this->_websiteFactory->create();
                         $websiteName = $website->load($data->getScopeId())->getName();
                         $scopeName = __('website(%1) scope', $websiteName);
                         break;
                     case \Magento\Store\Model\ScopeInterface::SCOPE_STORE:
                         /** @var $store \Magento\Store\Model\Store */
                         $store = $this->_storeFactory->create();
                         $storeName = $store->load($data->getScopeId())->getName();
                         $scopeName = __('store(%1) scope', $storeName);
                         break;
                 }
                 $exceptions[] = __('Currency "%1" is used as %2 in %3.', $currencyName, $fieldName, $scopeName);
             }
         }
     }
     if ($exceptions) {
         throw new \Magento\Framework\Exception\LocalizedException(__(join("\n", $exceptions)));
     }
     return $this;
 }
Beispiel #12
0
 /**
  * Get current store view name
  *
  * @return string
  */
 public function getCurrentStoreName()
 {
     if ($this->getStoreId() !== null) {
         $store = $this->_storeFactory->create();
         $store->load($this->getStoreId());
         if ($store->getId()) {
             return $store->getName();
         }
     }
 }
Beispiel #13
0
 /**
  * @return $this
  */
 protected function _loadData()
 {
     if ($this->_loaded) {
         return $this;
     }
     $websiteId = $this->_storeManager->getStore()->getWebsiteId();
     $storeCollection = $this->_storeFactory->create()->getCollection()->addWebsiteFilter($websiteId);
     $groupCollection = $this->_storeGroupFactory->create()->getCollection()->addWebsiteFilter($websiteId);
     foreach ($groupCollection as $group) {
         $this->_groups[$group->getId()] = $group;
     }
     foreach ($storeCollection as $store) {
         if (!$store->getIsActive()) {
             continue;
         }
         $store->setLocaleCode($this->_scopeConfig->getValue(Data::XML_PATH_DEFAULT_LOCALE, \Magento\Store\Model\ScopeInterface::SCOPE_STORE, $store->getId()));
         $this->_stores[$store->getGroupId()][$store->getId()] = $store;
     }
     $this->_loaded = true;
     return $this;
 }
Beispiel #14
0
 protected function loadMocks()
 {
     $storeMock = $this->getMockBuilder('Magento\\Store\\Model\\Store')->disableOriginalConstructor()->setMethods(['getLocaleCode', 'isActive', 'getId', 'getGroupId', 'getCollection'])->getMock();
     $groupMock = $this->getMockBuilder('Magento\\Store\\Model\\Group')->disableOriginalConstructor()->setMethods([])->getMock();
     /** @var AbstractCollection|\PHPUnit_Framework_MockObject_MockObject */
     $storeCollectionMock = $this->getMockBuilder('Magento\\Framework\\Model\\ResourceModel\\Db\\Collection\\AbstractCollection')->disableOriginalConstructor()->setMethods(['addWebsiteFilter', 'load'])->getMockForAbstractClass();
     /** @var AbstractCollection|\PHPUnit_Framework_MockObject_MockObject */
     $groupCollectionMock = $this->getMockBuilder('Magento\\Framework\\Model\\ResourceModel\\Db\\Collection\\AbstractCollection')->disableOriginalConstructor()->setMethods(['addWebsiteFilter', 'load'])->getMockForAbstractClass();
     $this->storeManagerMock->expects($this->any())->method('getStore')->willReturn($storeMock);
     $this->storeFactoryMock->expects($this->any())->method('create')->willReturn($storeMock);
     $this->storeGroupFactoryMock->expects($this->any())->method('create')->willReturn($groupMock);
     $storeMock->expects($this->any())->method('getCollection')->willReturn($storeCollectionMock);
     $groupMock->expects($this->any())->method('getCollection')->willReturn($groupCollectionMock);
     $groupMock->expects($this->any())->method('getId')->willReturn(1);
     $storeMock->expects($this->any())->method('isActive')->willReturn(true);
     $storeMock->expects($this->atLeastOnce())->method('getLocaleCode')->willReturn('en_US');
     $storeMock->expects($this->any())->method('getGroupId')->willReturn(1);
     $storeMock->expects($this->any())->method('setLocaleCode');
     $storeMock->expects($this->any())->method('getId')->willReturn(1);
     $storeCollectionMock->expects($this->any())->method('addWebsiteFilter')->willReturn([$storeMock]);
     $groupCollectionMock->expects($this->any())->method('addWebsiteFilter')->willReturn([$groupMock]);
 }
 /**
  * @param array $data
  * @return \Magento\Store\Model\Store
  */
 public function createStore(array $data)
 {
     // Prepare & Validate Data
     $data = array_merge($this->defaultStoreData, $data);
     $this->validateNewStoreData($data);
     // Create Model
     $store = $this->storeFactory->create();
     /** @var \Magento\Store\Model\Store $store */
     $store->addData($data)->save();
     // Default Store
     if (isset($data['_is_default']) && $data['_is_default']) {
         $store->getGroup()->setDefaultStoreId($store->getId())->save();
     }
     return $store;
 }
Beispiel #16
0
 /**
  * {@inheritdoc}
  */
 public function update($productSku, GalleryEntry $entry, $storeId = 0)
 {
     $store = $this->storeFactory->create()->load($storeId);
     if ($store->getId() != $storeId) {
         throw new NoSuchEntityException('There is no store with provided ID.');
     }
     $product = $this->productLoader->load($productSku);
     /** @var $productMediaGallery \Magento\Catalog\Model\Product\Attribute\Backend\Media */
     $productMediaGallery = $this->getGalleryAttributeBackend($product);
     $filePath = $this->entryResolver->getEntryFilePathById($product, $entry->getId());
     if (is_null($filePath)) {
         throw new NoSuchEntityException('There is no image with provided ID.');
     }
     $productMediaGallery->updateImage($product, $filePath, array('label' => $entry->getLabel(), 'position' => $entry->getPosition(), 'disabled' => $entry->isDisabled()));
     $productMediaGallery->clearMediaAttribute($product, array_keys($product->getMediaAttributes()));
     $productMediaGallery->setMediaAttribute($product, $entry->getTypes(), $filePath);
     $product->setStoreId($storeId);
     $product->save();
     return true;
 }
Beispiel #17
0
 /**
  * Retrieve new (not loaded) Store collection object with website filter
  *
  * @return \Magento\Store\Model\Resource\Store\Collection
  */
 public function getStoreCollection()
 {
     return $this->_storeFactory->create()->getCollection()->addWebsiteFilter($this->getId());
 }