public function testGetCount()
 {
     $websitesMock = $this->getMock('\\Magento\\Store\\Model\\ResourceModel\\Website\\Collection', [], [], '', false);
     $this->websitesFactoryMock->expects($this->once())->method('create')->willReturn($websitesMock);
     $websitesMock->expects($this->once())->method('getSize')->willReturn('expected');
     $this->assertEquals('expected', $this->model->getCount());
 }
예제 #2
0
 /**
  * @return Collection|null
  */
 public function getCollection()
 {
     if ($this->_websiteCollection === null) {
         $this->_websiteCollection = $this->_websitesFactory->create()->load();
     }
     $this->_coreRegistry->register('website_collection', $this->_websiteCollection);
     return $this->_websiteCollection;
 }
예제 #3
0
 /**
  * @expectedException \DomainException
  * @expectedExceptionMessage Default website is not defined
  */
 public function testGetDefaultIsZero()
 {
     $collectionMock = $this->getMockBuilder('Magento\\Store\\Model\\ResourceModel\\Website\\Collection')->disableOriginalConstructor()->setMethods([])->getMock();
     $this->websiteCollectionFactoryMock->expects($this->any())->method('create')->willReturn($collectionMock);
     $collectionMock->expects($this->any())->method('addFieldToFilter');
     $collectionMock->expects($this->any())->method('getItems')->willReturn([]);
     $this->model->getDefault();
 }
 /**
  * Clear expired persistent sessions
  *
  * @param \Magento\Cron\Model\Schedule $schedule
  * @return $this
  * @SuppressWarnings(PHPMD.UnusedFormalParameter)
  */
 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;
 }
 /**
  * {@inheritdoc}
  */
 public function getDefault()
 {
     if (!$this->default) {
         foreach ($this->entities as $entity) {
             if ($entity->getIsDefault()) {
                 $this->default = $entity;
                 return $this->default;
             }
         }
         if (!$this->allLoaded) {
             /** @var \Magento\Store\Model\ResourceModel\Website\Collection $collection */
             $collection = $this->websiteCollectionFactory->create();
             $collection->addFieldToFilter('is_default', 1);
             $items = $collection->getItems();
             if (count($items) > 1) {
                 throw new \DomainException(__('More than one default website is defined'));
             }
             if (count($items) === 0) {
                 throw new \DomainException(__('Default website is not defined'));
             }
             $this->default = $collection->getFirstItem();
             $this->entities[$this->default->getCode()] = $this->default;
             $this->entitiesById[$this->default->getId()] = $this->default;
         } else {
             throw new \DomainException(__('Default website is not defined'));
         }
     }
     return $this->default;
 }
예제 #6
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()]);
     }
 }
 /**
  * {@inheritdoc}
  */
 public function getCount()
 {
     $websites = $this->websitesFactory->create();
     /** @var \Magento\Store\Model\ResourceModel\Website\Collection $websites */
     return $websites->getSize();
 }