/** * 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()]); }
/** * {@inheritdoc} */ public function getById($id) { if (isset($this->entitiesById[$id])) { return $this->entitiesById[$id]; } /** @var Website $website */ $website = $this->factory->create(); $website->load($id); if ($website->getId() === null) { throw new NoSuchEntityException(); } $this->entitiesById[$id] = $website; $this->entities[$website->getCode()] = $website; return $website; }
/** * @return $this */ protected function _prepareColumns() { $this->addColumn('entity_id', array('header' => __('ID'), 'type' => 'number', 'index' => 'entity_id', 'header_css_class' => 'col-id', 'column_css_class' => 'col-id')); $this->addColumn('name', array('header' => __('Name'), 'index' => 'name', 'class' => 'xxx')); $store = $this->_getStore(); if ($store->getId()) { $this->addColumn('custom_name', array('header' => __('Name in %1', $store->getName()), 'index' => 'custom_name', 'header_css_class' => 'col-name', 'column_css_class' => 'col-name')); } $this->addColumn('type', array('header' => __('Type'), 'index' => 'type_id', 'type' => 'options', 'options' => $this->_type->getOptionArray())); $sets = $this->_setsFactory->create()->setEntityTypeFilter($this->_productFactory->create()->getResource()->getTypeId())->load()->toOptionHash(); $this->addColumn('set_name', array('header' => __('Attribute Set'), 'index' => 'attribute_set_id', 'type' => 'options', 'options' => $sets, 'header_css_class' => 'col-attr-name', 'column_css_class' => 'col-attr-name')); $this->addColumn('sku', array('header' => __('SKU'), 'index' => 'sku')); $store = $this->_getStore(); $this->addColumn('price', array('header' => __('Price'), 'type' => 'price', 'currency_code' => $store->getBaseCurrency()->getCode(), 'index' => 'price', 'header_css_class' => 'col-price', 'column_css_class' => 'col-price')); if ($this->_catalogData->isModuleEnabled('Magento_CatalogInventory')) { $this->addColumn('qty', array('header' => __('Quantity'), 'type' => 'number', 'index' => 'qty')); } $this->addColumn('visibility', array('header' => __('Visibility'), 'index' => 'visibility', 'type' => 'options', 'options' => $this->_visibility->getOptionArray(), 'header_css_class' => 'col-visibility', 'column_css_class' => 'col-visibility')); $this->addColumn('status', array('header' => __('Status'), 'index' => 'status', 'type' => 'options', 'options' => $this->_status->getOptionArray())); if (!$this->_storeManager->isSingleStoreMode()) { $this->addColumn('websites', array('header' => __('Websites'), 'sortable' => false, 'index' => 'websites', 'type' => 'options', 'options' => $this->_websiteFactory->create()->getCollection()->toOptionHash(), 'header_css_class' => 'col-websites', 'column_css_class' => 'col-websites')); } $this->addColumn('edit', array('header' => __('Edit'), 'type' => 'action', 'getter' => 'getId', 'actions' => array(array('caption' => __('Edit'), 'url' => array('base' => '*/*/edit', 'params' => array('store' => $this->getRequest()->getParam('store'))), 'field' => 'id')), 'filter' => false, 'sortable' => false, 'index' => 'stores', 'header_css_class' => 'col-action', 'column_css_class' => 'col-action')); if ($this->_catalogData->isModuleEnabled('Magento_Rss')) { $this->addRssList('rss/catalog/notifystock', __('Notify Low Stock RSS')); } return parent::_prepareColumns(); }
/** * @return $this * @SuppressWarnings(PHPMD.ExcessiveMethodLength) */ protected function _prepareColumns() { $this->addColumn('entity_id', ['header' => __('ID'), 'type' => 'number', 'index' => 'entity_id', 'header_css_class' => 'col-id', 'column_css_class' => 'col-id']); $this->addColumn('name', ['header' => __('Name'), 'index' => 'name', 'class' => 'xxx']); $store = $this->_getStore(); if ($store->getId()) { $this->addColumn('custom_name', ['header' => __('Name in %1', $store->getName()), 'index' => 'custom_name', 'header_css_class' => 'col-name', 'column_css_class' => 'col-name']); } $this->addColumn('type', ['header' => __('Type'), 'index' => 'type_id', 'type' => 'options', 'options' => $this->_type->getOptionArray()]); $sets = $this->_setsFactory->create()->setEntityTypeFilter($this->_productFactory->create()->getResource()->getTypeId())->load()->toOptionHash(); $this->addColumn('set_name', ['header' => __('Product Template'), 'index' => 'attribute_set_id', 'type' => 'options', 'options' => $sets, 'header_css_class' => 'col-attr-name', 'column_css_class' => 'col-attr-name']); $this->addColumn('sku', ['header' => __('SKU'), 'index' => 'sku']); $store = $this->_getStore(); $this->addColumn('price', ['header' => __('Price'), 'type' => 'price', 'currency_code' => $store->getBaseCurrency()->getCode(), 'index' => 'price', 'header_css_class' => 'col-price', 'column_css_class' => 'col-price']); if ($this->moduleManager->isEnabled('Magento_CatalogInventory')) { $this->addColumn('qty', ['header' => __('Quantity'), 'type' => 'number', 'index' => 'qty']); } $this->addColumn('visibility', ['header' => __('Visibility'), 'index' => 'visibility', 'type' => 'options', 'options' => $this->_visibility->getOptionArray(), 'header_css_class' => 'col-visibility', 'column_css_class' => 'col-visibility']); $this->addColumn('status', ['header' => __('Status'), 'index' => 'status', 'type' => 'options', 'options' => $this->_status->getOptionArray()]); if (!$this->_storeManager->isSingleStoreMode()) { $this->addColumn('websites', ['header' => __('Websites'), 'sortable' => false, 'index' => 'websites', 'type' => 'options', 'options' => $this->_websiteFactory->create()->getCollection()->toOptionHash(), 'header_css_class' => 'col-websites', 'column_css_class' => 'col-websites']); } $this->addColumn('edit', ['header' => __('Edit'), 'type' => 'action', 'getter' => 'getId', 'actions' => [['caption' => __('Edit'), 'url' => ['base' => '*/*/edit', 'params' => ['store' => $this->getRequest()->getParam('store')]], 'field' => 'id']], 'filter' => false, 'sortable' => false, 'index' => 'stores', 'header_css_class' => 'col-action', 'column_css_class' => 'col-action']); $block = $this->getLayout()->getBlock('grid.bottom.links'); if ($block) { $this->setChild('grid.bottom.links', $block); } return parent::_prepareColumns(); }
/** * Retrieve list of store groups * * @return array */ protected function _getStoreGroups() { $websites = $this->_websiteFactory->create()->getCollection(); $allgroups = $this->_groupFactory->create()->getCollection(); $groups = []; foreach ($websites as $website) { $values = []; foreach ($allgroups as $group) { if ($group->getWebsiteId() == $website->getId()) { $values[] = ['label' => $group->getName(), 'value' => $group->getId()]; } } $groups[] = ['label' => $website->getName(), 'value' => $values]; } return $groups; }
/** * Read configuration by code * * @param string $code * @return array */ public function read($code = null) { $config = array_replace_recursive($this->_scopePool->getScope(ScopeConfigInterface::SCOPE_TYPE_DEFAULT)->getSource(), $this->_initialConfig->getData("websites|{$code}")); $website = $this->_websiteFactory->create(); $website->load($code); $collection = $this->_collectionFactory->create(['scope' => \Magento\Store\Model\ScopeInterface::SCOPE_WEBSITES, 'scopeId' => $website->getId()]); $dbWebsiteConfig = []; foreach ($collection as $configValue) { $dbWebsiteConfig[$configValue->getPath()] = $configValue->getValue(); } $dbWebsiteConfig = $this->_converter->convert($dbWebsiteConfig); if (count($dbWebsiteConfig)) { $config = array_replace_recursive($config, $dbWebsiteConfig); } return $config; }
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(); } } } } }
/** * @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(); }
/** * @return array */ public function getWebsiteIds() { $websiteIds = []; $collection = $this->websiteFactory->create()->getCollection(); foreach ($collection as $website) { $websiteIds[] = $website->getId(); } return $websiteIds; }
/** * @return $this * @throws \Magento\Framework\Exception\LocalizedException */ public function afterSave() { /** @var $collection \Magento\Config\Model\ResourceModel\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 ScopeConfigInterface::SCOPE_TYPE_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 parent::afterSave(); }
/** * Get current website name * * @return string */ public function getCurrentWebsiteName() { if ($this->getWebsiteId() !== null) { $website = $this->_websiteFactory->create(); $website->load($this->getWebsiteId()); if ($website->getId()) { return $website->getName(); } } }
/** * Add columns to grid * * @return $this */ protected function _prepareColumns() { if (!$this->isReadonly()) { $this->addColumn('in_products', ['type' => 'checkbox', 'name' => 'in_products', 'values' => $this->_getSelectedProducts(), 'align' => 'center', 'index' => 'entity_id', 'header_css_class' => 'col-select', 'column_css_class' => 'col-select']); } $this->addColumn('entity_id', ['header' => __('ID'), 'sortable' => true, 'index' => 'entity_id', 'header_css_class' => 'col-id', 'column_css_class' => 'col-id']); $this->addColumn('name', ['header' => __('Name'), 'index' => 'name', 'header_css_class' => 'col-name', 'column_css_class' => 'col-name']); $this->addColumn('sku', ['header' => __('SKU'), 'index' => 'sku', 'header_css_class' => 'col-sku', 'column_css_class' => 'col-sku']); $this->addColumn('visibility', ['header' => __('Visibility'), 'index' => 'visibility', 'type' => 'options', 'options' => $this->_visibility->getOptionArray(), 'header_css_class' => 'col-visibility', 'column_css_class' => 'col-visibility']); if (!$this->_storeManager->isSingleStoreMode()) { $this->addColumn('websites', ['header' => __('Websites'), 'sortable' => false, 'index' => 'websites', 'type' => 'options', 'options' => $this->_websiteFactory->create()->getCollection()->toOptionHash(), 'header_css_class' => 'col-websites', 'column_css_class' => 'col-websites']); } $this->addColumn('status', ['header' => __('Status'), 'index' => 'status', 'type' => 'options', 'options' => $this->_status->getOptionArray(), 'header_css_class' => 'col-status', 'column_css_class' => 'col-status', 'frame_callback' => array($this->getLayout()->createBlock('Magefan\\Blog\\Block\\Adminhtml\\Grid\\Column\\Statuses'), 'decorateStatus')]); return parent::_prepareColumns(); }
/** * @param $website */ public function _checkSendStatus($website) { $storeIds = $this->websiteFactory->create()->load($website->getId())->getStoreIds(); $campaigns = $this->_getEmailCampaigns($storeIds, \Dotdigitalgroup\Email\Model\Campaign::PROCESSING, true); foreach ($campaigns as $campaign) { $client = $this->helper->getWebsiteApiClient($website); $response = $client->getSendStatus($campaign->getSendId()); if (isset($response->message)) { //update the failed to send email message $this->campaignResourceModel->setMessage([$campaign->getSendId()], $response->message); } elseif ($response->status == 'Sent') { $this->campaignResourceModel->setSent($campaign->getSendId()); } } }
/** * Retrieve application website object * * @param null|bool|int|string|Website $websiteId * @return Website * @throws \Magento\Framework\Exception\State\InitException */ public function getWebsite($websiteId = null) { if ($websiteId === null || $websiteId === '') { $websiteId = $this->getStore()->getWebsiteId(); } elseif ($websiteId instanceof Website) { return $websiteId; } elseif ($websiteId === true) { return $this->_website; } if (empty($this->_websites[$websiteId])) { $website = $this->_websiteFactory->create(); // load method will load website by code if given ID is not a numeric value $website->load($websiteId); if (!$website->hasWebsiteId()) { throw new \Magento\Framework\Exception\State\InitException(__('Invalid website id/code requested.')); } $this->_websites[$website->getWebsiteId()] = $website; $this->_websites[$website->getCode()] = $website; } return $this->_websites[$websiteId]; }
/** * @param array $data * @param bool $processGroups * @return \Magento\Store\Model\Website */ public function createWebsite(array $data, $processGroups = true) { // Prepare and Validate Data $data = array_merge($this->defaultWebsiteData, $data); $this->validateNewWebsiteData($data); // Create Model $website = $this->websiteFactory->create(); /* @var \Magento\Store\Model\Website $website * */ $website->addData($data)->save(); // Create/Update Groups if ($processGroups && isset($data['_groups']) && is_array($data['_groups'])) { foreach ($data['_groups'] as $groupKey => $groupData) { $groupData['website_id'] = $website->getId(); $this->createGroup($groupData); try { $this->createGroup($groupData); } catch (AlreadyExistsException $e) { $this->updateGroup($groupData['name'], $groupData); } } } return $website; }
/** * Retrieve websites and default stores * Return array as key website_id, value store_id * * @return array */ public function getWebsiteStores() { /** @var \Magento\Store\Model\Website $website */ $website = $this->_websiteFactory->create(); return $this->getConnection()->fetchPairs($website->getDefaultStoresSelect(false)); }
/** * Can delete website * * @return bool */ public function isCanDelete() { if ($this->_isReadOnly || !$this->getId()) { return false; } if (is_null($this->_isCanDelete)) { $this->_isCanDelete = $this->_websiteFactory->create()->getCollection()->getSize() > 1 && !$this->getIsDefault(); } return $this->_isCanDelete; }
/** * Get callback url * * @param string $actionName * @return string */ protected function _getCallbackUrl($actionName) { if ($this->_requestHttp->getParam('website')) { /** @var $website \Magento\Store\Model\Website */ $website = $this->_websiteFactory->create()->load($this->_requestHttp->getParam('website')); $secure = $this->_scopeConfig->isSetFlag(\Magento\Store\Model\Store::XML_PATH_SECURE_IN_FRONTEND, \Magento\Store\Model\ScopeInterface::SCOPE_STORE, $website->getDefaultStore()); $path = $secure ? \Magento\Store\Model\Store::XML_PATH_SECURE_BASE_LINK_URL : \Magento\Store\Model\Store::XML_PATH_UNSECURE_BASE_LINK_URL; $websiteUrl = $this->_scopeConfig->getValue($path, \Magento\Store\Model\ScopeInterface::SCOPE_STORE, $website->getDefaultStore()); } else { $secure = $this->_scopeConfig->isSetFlag(\Magento\Store\Model\Store::XML_PATH_SECURE_IN_FRONTEND, \Magento\Store\Model\ScopeInterface::SCOPE_STORE); $websiteUrl = $this->storeManager->getStore()->getBaseUrl(\Magento\Framework\UrlInterface::URL_TYPE_LINK, $secure); } return $websiteUrl . 'paypal/' . $this->_callbackController . '/' . $actionName; }