/** * @return Collection|null */ public function getCollection() { if (is_null($this->_websiteCollection)) { $this->_websiteCollection = $this->_websitesFactory->create()->load(); } $this->_coreRegistry->register('website_collection', $this->_websiteCollection); return $this->_websiteCollection; }
/** * Clear expired persistent sessions * * @param \Magento\Cron\Model\Schedule $schedule * @return $this */ public function execute(\Magento\Cron\Model\Schedule $schedule) { $websiteIds = $this->_websiteCollectionFactory->create()->getAllIds(); if (!is_array($websiteIds)) { return $this; } foreach ($websiteIds as $websiteId) { $this->_sessionFactory->create()->deleteExpired($websiteId); } return $this; }
/** * Prepare product review grid * * @return void */ protected function _prepareColumns() { $this->addColumn('entity_id', ['header' => __('ID'), 'index' => 'entity_id', 'header_css_class' => 'col-id', 'column_css_class' => 'col-id']); $this->addColumn('name', ['header' => __('Name'), 'index' => 'name']); if ((int) $this->getRequest()->getParam('store', 0)) { $this->addColumn('custom_name', ['header' => __('Product Store Name'), 'index' => 'custom_name']); } $this->addColumn('sku', ['header' => __('SKU'), 'index' => 'sku']); $this->addColumn('price', ['header' => __('Price'), 'type' => 'currency', 'index' => 'price']); $this->addColumn('qty', ['header' => __('Quantity'), 'type' => 'number', 'index' => 'qty']); $this->addColumn('status', ['header' => __('Status'), 'index' => 'status', 'type' => 'options', 'source' => 'Magento\\Catalog\\Model\\Product\\Attribute\\Source\\Status', 'options' => $this->_status->getOptionArray()]); /** * Check is single store mode */ if (!$this->_storeManager->isSingleStoreMode()) { $this->addColumn('websites', ['header' => __('Websites'), 'sortable' => false, 'index' => 'websites', 'type' => 'options', 'options' => $this->_websitesFactory->create()->toOptionHash()]); } }
/** * @param \Magento\Catalog\Model\Product $product */ protected function _printAssignedWebsites(\Magento\Catalog\Model\Product $product) { if (!$this->_printWebsites) { return; } $collection = $this->_websitesFactory->create(); $collection->addIdFilter($product->getWebsiteIds()); $websiteNames = array(); /** @var \Magento\Store\Model\Website $website */ foreach ($collection as $website) { $websiteNames[] = $website->getName(); } echo 'Websites '; echo '[' . implode(',', $websiteNames) . ']'; echo "\t"; }
/** * Init store, group and website collections * * @return void * @SuppressWarnings(PHPMD.CyclomaticComplexity) */ protected function _initStores() { $this->_store = null; $this->_stores = []; $this->_groups = []; $this->_websites = []; $this->_website = null; /** @var $websiteCollection \Magento\Store\Model\Resource\Website\Collection */ $websiteCollection = $this->_websiteCollectionFactory->create(); $websiteCollection->setLoadDefault(true); /** @var $groupCollection \Magento\Store\Model\Resource\Group\Collection */ $groupCollection = $this->_groupCollectionFactory->create(); $groupCollection->setLoadDefault(true); /** @var $storeCollection \Magento\Store\Model\Resource\Store\Collection */ $storeCollection = $this->_storeCollectionFactory->create(); $storeCollection->setLoadDefault(true); $this->_hasSingleStore = false; if ($this->_isSingleStoreAllowed && $storeCollection->count() < 3) { $this->_hasSingleStore = true; $this->_store = $storeCollection->getLastItem(); } $websiteStores = []; $websiteGroups = []; $groupStores = []; foreach ($storeCollection as $store) { /** @var $store Store */ $this->_stores[$store->getId()] = $store; $this->_stores[$store->getCode()] = $store; $websiteStores[$store->getWebsiteId()][$store->getId()] = $store; $groupStores[$store->getGroupId()][$store->getId()] = $store; } foreach ($groupCollection as $group) { /* @var $group Group */ if (!isset($groupStores[$group->getId()])) { $groupStores[$group->getId()] = []; } $group->setStores($groupStores[$group->getId()]); $websiteGroups[$group->getWebsiteId()][$group->getId()] = $group; $this->_groups[$group->getId()] = $group; } foreach ($websiteCollection as $website) { /* @var $website Website */ if (!isset($websiteGroups[$website->getId()])) { $websiteGroups[$website->getId()] = []; } if (!isset($websiteStores[$website->getId()])) { $websiteStores[$website->getId()] = []; } if ($website->getIsDefault()) { $this->_website = $website; } $website->setGroups($websiteGroups[$website->getId()]); $website->setStores($websiteStores[$website->getId()]); $this->_websites[$website->getId()] = $website; $this->_websites[$website->getCode()] = $website; } }