Esempio n. 1
0
 /**
  * @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;
 }
Esempio n. 3
0
 /**
  * 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";
 }
Esempio n. 5
0
 protected function prepareMockForReinit()
 {
     $websiteId = 1;
     $websiteCode = 'website_code';
     $groupId = 1;
     $storeId = 1;
     $storeCode = 'store_code';
     $websiteCollection = $this->getMock('\\Magento\\Store\\Model\\Resource\\Website\\Collection', [], [], '', false, false);
     $websiteCollection->expects($this->any())->method('setLoadDefault')->with(true);
     $this->mockIterator($websiteCollection, [$this->_websiteMock]);
     $this->_websiteFactoryMock->expects($this->any())->method('create')->will($this->returnValue($this->_websiteMock));
     $this->_websiteMock->expects($this->any())->method('getCollection')->will($this->returnValue($websiteCollection));
     $groupCollection = $this->getMock('\\Magento\\Store\\Model\\Resource\\Group\\Collection', [], [], '', false, false);
     $groupCollection->expects($this->any())->method('setLoadDefault')->with(true);
     $this->mockIterator($groupCollection, [$this->_groupMock]);
     $this->_groupFactoryMock->expects($this->any())->method('create')->will($this->returnValue($this->_groupMock));
     $this->_groupMock->expects($this->any())->method('getCollection')->will($this->returnValue($groupCollection));
     $storeCollection = $this->getMock('\\Magento\\Store\\Model\\Resource\\Store\\Collection', [], [], '', false, false);
     $storeCollection->expects($this->any())->method('setLoadDefault')->with(true);
     $this->mockIterator($storeCollection, [$this->_storeMock]);
     $storeCollection->expects($this->any())->method('getIterator')->will($this->returnValue(new \ArrayIterator([$this->_storeMock])));
     $storeCollection->expects($this->any())->method('getLastItem')->will($this->returnValue($this->_storeMock));
     $this->_storeFactoryMock->expects($this->any())->method('create')->will($this->returnValue($this->_storeMock));
     $this->_storeMock->expects($this->any())->method('getCollection')->will($this->returnValue($storeCollection));
     $this->_websiteCollectionFactoryMock->expects($this->any())->method('create')->will($this->returnValue($websiteCollection));
     $this->_groupCollectionFactoryMock->expects($this->any())->method('create')->will($this->returnValue($groupCollection));
     $this->_storeCollectionFactoryMock->expects($this->any())->method('create')->will($this->returnValue($storeCollection));
     $this->_storeMock->expects($this->any())->method('getWebsiteId')->will($this->returnValue($websiteId));
     $this->_storeMock->expects($this->any())->method('getGroupId')->will($this->returnValue($groupId));
     $this->_storeMock->expects($this->any())->method('getId')->will($this->returnValue($storeId));
     $this->_storeMock->expects($this->any())->method('getCode')->will($this->returnValue($storeCode));
     $websiteCollection->expects($this->any())->method('getItemById')->will($this->returnValue($this->_websiteMock));
     $groupCollection->expects($this->any())->method('getItemById')->will($this->returnValue($this->_groupMock));
     $this->_groupMock->expects($this->any())->method('getWebsiteId')->will($this->returnValue($websiteId));
     $this->_groupMock->expects($this->any())->method('getId')->will($this->returnValue($groupId));
     $this->_websiteMock->expects($this->any())->method('getId')->will($this->returnValue($websiteId));
     $this->_websiteMock->expects($this->any())->method('getCode')->will($this->returnValue($websiteCode));
     $this->_websiteMock->expects($this->at(3))->method('__call')->will($this->returnValue(true));
 }
Esempio n. 6
0
 /**
  * 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;
     }
 }