Exemple #1
0
 /**
  * afterUpdateMview with disabled PageCache module
  */
 public function testAfterUpdateMviewPageCacheDisabled()
 {
     $this->moduleManager->expects($this->once())->method('isEnabled')->with($this->equalTo('Magento_PageCache'))->will($this->returnValue(false));
     $this->eventManagerMock->expects($this->never())->method('dispatch');
     $actualResult = $this->plugin->afterUpdateMview($this->subjectMock);
     $this->assertNull($actualResult);
 }
Exemple #2
0
 /**
  * @return $this
  */
 protected function _prepareCollection()
 {
     if (!$this->_moduleManager->isEnabled('Magento_Reports')) {
         return $this;
     }
     $collection = $this->_collectionFactory->create()->addItemCountExpr()->joinCustomerName('customer')->orderByCreatedAt();
     if ($this->getParam('store') || $this->getParam('website') || $this->getParam('group')) {
         if ($this->getParam('store')) {
             $collection->addAttributeToFilter('store_id', $this->getParam('store'));
         } else {
             if ($this->getParam('website')) {
                 $storeIds = $this->_storeManager->getWebsite($this->getParam('website'))->getStoreIds();
                 $collection->addAttributeToFilter('store_id', array('in' => $storeIds));
             } else {
                 if ($this->getParam('group')) {
                     $storeIds = $this->_storeManager->getGroup($this->getParam('group'))->getStoreIds();
                     $collection->addAttributeToFilter('store_id', array('in' => $storeIds));
                 }
             }
         }
         $collection->addRevenueToSelect();
     } else {
         $collection->addRevenueToSelect(true);
     }
     $this->setCollection($collection);
     return parent::_prepareCollection();
 }
Exemple #3
0
 /**
  * @covers \Magento\Framework\App\Helper\AbstractHelper::isModuleEnabled
  * @covers \Magento\Framework\App\Helper\AbstractHelper::isModuleOutputEnabled
  * @param string|null $moduleName
  * @param string $requestedName
  * @param bool $result
  * @dataProvider isModuleEnabledDataProvider
  */
 public function testIsModuleEnabled($moduleName, $requestedName, $result)
 {
     $this->moduleManagerMock->expects($this->once())->method('isEnabled')->with($this->equalTo($requestedName))->will($this->returnValue($result));
     $this->moduleManagerMock->expects($this->once())->method('isOutputEnabled')->with($this->equalTo($requestedName))->will($this->returnValue($result));
     $this->assertSame($result, $this->helper->isModuleEnabled($moduleName));
     $this->assertSame($result, $this->helper->isModuleOutputEnabled($moduleName));
 }
 /**
  * After generate Xml
  *
  * @param \Magento\Framework\View\LayoutInterface $subject
  * @param \Magento\Framework\View\LayoutInterface $result
  * @return \Magento\Framework\View\LayoutInterface
  */
 public function afterGenerateXml(\Magento\Framework\View\LayoutInterface $subject, $result)
 {
     if ($this->moduleManager->isEnabled('Magento_PageCache') && $this->cacheConfig->isEnabled() && !$this->request->isAjax() && $subject->isCacheable()) {
         $this->checkoutSession->clearStorage();
     }
     return $result;
 }
Exemple #5
0
 /**
  * @return $this|void
  */
 protected function _prepareLayout()
 {
     if (!$this->_moduleManager->isEnabled('Magento_Reports')) {
         return $this;
     }
     $isFilter = $this->getRequest()->getParam('store') || $this->getRequest()->getParam('website') || $this->getRequest()->getParam('group');
     $period = $this->getRequest()->getParam('period', '24h');
     /* @var $collection \Magento\Reports\Model\Resource\Order\Collection */
     $collection = $this->_collectionFactory->create()->addCreateAtPeriodFilter($period)->calculateTotals($isFilter);
     if ($this->getRequest()->getParam('store')) {
         $collection->addFieldToFilter('store_id', $this->getRequest()->getParam('store'));
     } else {
         if ($this->getRequest()->getParam('website')) {
             $storeIds = $this->_storeManager->getWebsite($this->getRequest()->getParam('website'))->getStoreIds();
             $collection->addFieldToFilter('store_id', ['in' => $storeIds]);
         } else {
             if ($this->getRequest()->getParam('group')) {
                 $storeIds = $this->_storeManager->getGroup($this->getRequest()->getParam('group'))->getStoreIds();
                 $collection->addFieldToFilter('store_id', ['in' => $storeIds]);
             } elseif (!$collection->isLive()) {
                 $collection->addFieldToFilter('store_id', ['eq' => $this->_storeManager->getStore(\Magento\Store\Model\Store::ADMIN_CODE)->getId()]);
             }
         }
     }
     $collection->load();
     $totals = $collection->getFirstItem();
     $this->addTotal(__('Revenue'), $totals->getRevenue());
     $this->addTotal(__('Tax'), $totals->getTax());
     $this->addTotal(__('Shipping'), $totals->getShipping());
     $this->addTotal(__('Quantity'), $totals->getQuantity() * 1, true);
 }
Exemple #6
0
 /**
  * Render block HTML
  *
  * @return string
  */
 protected function _toHtml()
 {
     if ($this->_moduleManager->isOutputEnabled('Magento_Checkout')) {
         return '';
     }
     return parent::_toHtml();
 }
 /**
  * @param Observer $observer
  * @return void
  * @SuppressWarnings(PHPMD.CyclomaticComplexity)
  */
 public function execute(Observer $observer)
 {
     if ($this->moduleManager->isEnabled('Magento_PageCache') && $this->cacheConfig->isEnabled() && $this->taxHelper->isCatalogPriceDisplayAffectedByTax()) {
         /** @var \Magento\Customer\Model\Data\Customer $customer */
         $customer = $observer->getData('customer');
         $customerGroupId = $customer->getGroupId();
         $customerGroup = $this->groupRepository->getById($customerGroupId);
         $customerTaxClassId = $customerGroup->getTaxClassId();
         $this->customerSession->setCustomerTaxClassId($customerTaxClassId);
         /** @var \Magento\Customer\Api\Data\AddressInterface[] $addresses */
         $addresses = $customer->getAddresses();
         if (isset($addresses)) {
             $defaultShippingFound = false;
             $defaultBillingFound = false;
             foreach ($addresses as $address) {
                 if ($address->isDefaultBilling()) {
                     $defaultBillingFound = true;
                     $this->customerSession->setDefaultTaxBillingAddress(['country_id' => $address->getCountryId(), 'region_id' => $address->getRegion() ? $address->getRegion()->getRegionId() : null, 'postcode' => $address->getPostcode()]);
                 }
                 if ($address->isDefaultShipping()) {
                     $defaultShippingFound = true;
                     $this->customerSession->setDefaultTaxShippingAddress(['country_id' => $address->getCountryId(), 'region_id' => $address->getRegion() ? $address->getRegion()->getRegionId() : null, 'postcode' => $address->getPostcode()]);
                 }
                 if ($defaultShippingFound && $defaultBillingFound) {
                     break;
                 }
             }
         }
     }
 }
Exemple #8
0
 public function testAroundDispatchCached()
 {
     $this->_cacheMock->expects($this->once())->method('load')->with('db_is_up_to_date')->will($this->returnValue(true));
     $this->moduleManager->expects($this->never())->method('isDbSchemaUpToDate');
     $this->moduleManager->expects($this->never())->method('isDbDataUpToDate');
     $this->assertEquals('Expected', $this->_model->aroundDispatch($this->subjectMock, $this->closureMock, $this->requestMock));
 }
Exemple #9
0
 /**
  * @return $this|void
  */
 protected function _prepareLayout()
 {
     if (!$this->_moduleManager->isEnabled('Magento_Reports')) {
         return $this;
     }
     $isFilter = $this->getRequest()->getParam('store') || $this->getRequest()->getParam('website') || $this->getRequest()->getParam('group');
     $collection = $this->_collectionFactory->create()->calculateSales($isFilter);
     if ($this->getRequest()->getParam('store')) {
         $collection->addFieldToFilter('store_id', $this->getRequest()->getParam('store'));
     } else {
         if ($this->getRequest()->getParam('website')) {
             $storeIds = $this->_storeManager->getWebsite($this->getRequest()->getParam('website'))->getStoreIds();
             $collection->addFieldToFilter('store_id', array('in' => $storeIds));
         } else {
             if ($this->getRequest()->getParam('group')) {
                 $storeIds = $this->_storeManager->getGroup($this->getRequest()->getParam('group'))->getStoreIds();
                 $collection->addFieldToFilter('store_id', array('in' => $storeIds));
             }
         }
     }
     $collection->load();
     $sales = $collection->getFirstItem();
     $this->addTotal(__('Lifetime Sales'), $sales->getLifetime());
     $this->addTotal(__('Average Orders'), $sales->getAverage());
 }
Exemple #10
0
 /**
  * Render block HTML
  *
  * @return string
  */
 protected function _toHtml()
 {
     if (!$this->_checkoutHelper->canOnepageCheckout() || !$this->_moduleManager->isOutputEnabled('Magento_Checkout')) {
         return '';
     }
     return parent::_toHtml();
 }
Exemple #11
0
 /**
  * Remove grouped product from list of visible product types
  *
  * @param \Magento\Catalog\Model\Product\Type $subject
  * @param array $result
  * @return array
  *
  * @SuppressWarnings(PHPMD.UnusedFormalParameter)
  */
 public function afterGetOptionArray(\Magento\Catalog\Model\Product\Type $subject, array $result)
 {
     if (!$this->moduleManager->isOutputEnabled('Magento_ConfigurableProduct')) {
         unset($result[Configurable::TYPE_CODE]);
     }
     return $result;
 }
 /**
  * Retrieve stock option array
  *
  * @return array
  */
 public function getStockOption()
 {
     if ($this->moduleManager->isEnabled('Magento_CatalogInventory')) {
         return $this->stock->toOptionArray();
     }
     return [];
 }
Exemple #13
0
 /**
  * Test method afterGenerateXml with disabled module PageCache
  */
 public function testAfterGenerateXmlPageCacheDisabled()
 {
     $expectedResult = $this->getMock('Magento\\Framework\\View\\Layout', [], [], '', false);
     $this->moduleManagerMock->expects($this->once())->method('isEnabled')->with($this->equalTo('Magento_PageCache'))->will($this->returnValue(false));
     $this->requestMock->expects($this->never())->method('isAjax')->will($this->returnValue(false));
     $actualResult = $this->plugin->afterGenerateXml($this->layoutMock, $expectedResult);
     $this->assertEquals($expectedResult, $actualResult);
 }
Exemple #14
0
 /**
  * @param \Magento\Framework\Event $event
  * @return void
  */
 public function observe($event)
 {
     if (!$this->moduleManager->isOutputEnabled('Magento_LayeredNavigation')) {
         return;
     }
     /** @var \Magento\Catalog\Block\Adminhtml\Product\Attribute\Grid $grid */
     $grid = $event->getGrid();
     $grid->addColumnAfter('is_filterable', array('header' => __('Use in Layered Navigation'), 'sortable' => true, 'index' => 'is_filterable', 'type' => 'options', 'options' => array('1' => __('Filterable (with results)'), '2' => __('Filterable (no results)'), '0' => __('No')), 'align' => 'center'), 'is_searchable');
 }
 public function testConvertWithDisabledModules()
 {
     $testDom = $this->filePath . 'import.xml';
     $dom = new \DOMDocument();
     $dom->load($testDom);
     $notExpectedArray = (include $this->filePath . 'import.php');
     $this->moduleManager->expects($this->any())->method('isOutputEnabled')->willReturn(false);
     $this->assertNotEquals($notExpectedArray, $this->model->convert($dom));
 }
Exemple #16
0
 /**
  * After generate Xml
  *
  * @param \Magento\Framework\View\LayoutInterface $subject
  * @param \Magento\Framework\View\LayoutInterface $result
  * @return \Magento\Framework\View\LayoutInterface
  */
 public function afterGenerateXml(\Magento\Framework\View\LayoutInterface $subject, $result)
 {
     if ($this->moduleManager->isEnabled('Magento_PageCache') && $this->cacheConfig->isEnabled() && !$this->request->isAjax() && $subject->isCacheable()) {
         $this->eventManager->dispatch('depersonalize_clear_session');
         session_write_close();
         $this->messageSession->clearStorage();
     }
     return $result;
 }
 /**
  * @dataProvider dataAddFields
  */
 public function testAddFields($expected)
 {
     $this->moduleManagerMock->expects($this->once())->method('isOutputEnabled')->willReturn($expected['isOutputEnabled']);
     $this->eventObserverMock->expects($this->exactly($expected['methods_count']))->method('getForm')->willReturn($this->formMock);
     $element = $this->getMock('Magento\\Framework\\Data\\Form\\Element\\AbstractElement', [], [], '', false);
     $this->formMock->expects($this->exactly($expected['methods_count']))->method('getElement')->with('base_fieldset')->willReturn($element);
     $element->expects($this->exactly($expected['addField_count']))->method('addField');
     $this->yesNoMock->expects($this->exactly($expected['yesno_count']))->method('toOptionArray');
     $this->observerMock->execute($this->eventObserverMock);
 }
 /**
  * Get Magefan Modules Info
  *
  * @return $this
  */
 protected function getMagefanModules()
 {
     $modules = array();
     foreach ($this->_moduleList->getAll() as $moduleName => $module) {
         if (strpos($moduleName, 'Magefan_') !== false && $this->_moduleManager->isEnabled($moduleName)) {
             $modules[$moduleName] = $module;
         }
     }
     return $modules;
 }
Exemple #19
0
 /**
  * Retrieve files
  *
  * Filter out theme files that belong to inactive modules or ones explicitly configured to not produce any output
  *
  * @param ThemeInterface $theme
  * @param string $filePath
  * @return array|\Magento\Framework\View\File[]
  */
 public function getFiles(ThemeInterface $theme, $filePath)
 {
     $result = array();
     foreach ($this->subject->getFiles($theme, $filePath) as $file) {
         if ($this->moduleManager->isOutputEnabled($file->getModule())) {
             $result[] = $file;
         }
     }
     return $result;
 }
 /**
  * @dataProvider dataAddSwatch
  */
 public function testAddSwatchAttributeType($exp)
 {
     $this->moduleManagerMock->expects($this->once())->method('isOutputEnabled')->willReturn($exp['isOutputEnabled']);
     $eventMock = $this->getMock('\\Magento\\Framework\\Event', ['getResponse'], [], '', false);
     $this->eventObserverMock->expects($this->exactly($exp['methods_count']))->method('getEvent')->willReturn($eventMock);
     $response = $this->getMock('\\Magento\\Framework\\DataObject', ['getTypes'], [], '', false);
     $eventMock->expects($this->exactly($exp['methods_count']))->method('getResponse')->willReturn($response);
     $response->expects($this->exactly($exp['methods_count']))->method('getTypes')->willReturn($exp['outputArray']);
     $this->observerMock->execute($this->eventObserverMock);
 }
Exemple #21
0
 public function testGetCustomerMissingCustomer()
 {
     $moduleManager = $this->objectManager->get('Magento\\Framework\\Module\\Manager');
     if ($moduleManager->isEnabled('Magento_PageCache')) {
         $customerDataBuilder = $this->objectManager->create('Magento\\Customer\\Service\\V1\\Data\\CustomerBuilder');
         $customerData = $customerDataBuilder->setGroupId($this->_customerSession->getCustomerGroupId())->create();
         $this->assertEquals($customerData, $this->_block->getCustomer());
     } else {
         $this->assertNull($this->_block->getCustomer());
     }
 }
Exemple #22
0
 /**
  * Test method afterGenerateXml
  */
 public function testAfterGenerateXml()
 {
     $expectedResult = $this->getMock('Magento\\Framework\\View\\Layout', array(), array(), '', false);
     $this->moduleManagerMock->expects($this->once())->method('isEnabled')->with($this->equalTo('Magento_PageCache'))->will($this->returnValue(true));
     $this->cacheConfigMock->expects($this->once())->method('isEnabled')->will($this->returnValue(true));
     $this->requestMock->expects($this->once($this->once()))->method('isAjax')->will($this->returnValue(false));
     $this->layoutMock->expects($this->once())->method('isCacheable')->will($this->returnValue(true));
     $this->checkoutSessionMock->expects($this->once())->method('clearStorage')->will($this->returnValue($expectedResult));
     $actualResult = $this->plugin->afterGenerateXml($this->layoutMock, $expectedResult);
     $this->assertEquals($expectedResult, $actualResult);
 }
Exemple #23
0
 /**
  * @param \Magento\Catalog\Block\Adminhtml\Product\Edit\Tabs $subject
  * @param \Magento\Eav\Model\Resource\Entity\Attribute\Group\Collection $result
  *
  * @return \Magento\Eav\Model\Resource\Entity\Attribute\Group\Collection
  * @SuppressWarnings(PHPMD.UnusedFormalParameter)
  */
 public function afterGetGroupCollection(\Magento\Catalog\Block\Adminhtml\Product\Edit\Tabs $subject, $result)
 {
     if (!$this->_moduleManager->isOutputEnabled('Magento_RecurringPayment')) {
         foreach ($result as $key => $group) {
             if ($group->getAttributeGroupCode() === 'recurring-payment') {
                 $result->removeItemByKey($key);
             }
         }
     }
     return $result;
 }
Exemple #24
0
 /**
  * Check a configuration element visibility
  *
  * @param \Magento\Config\Model\Config\Structure\AbstractElement $element The config composite element
  * @param string                                                 $scope   The element scope
  *
  * @return bool
  */
 public function isVisible(\Magento\Config\Model\Config\Structure\AbstractElement $element, $scope)
 {
     if ($element->getAttribute('if_module_enabled') && !$this->moduleManager->isOutputEnabled($element->getAttribute('if_module_enabled'))) {
         return false;
     }
     $showInScope = [ContainerScopeInterface::SCOPE_DEFAULT => $element->getAttribute('showInDefault'), ContainerScopeInterface::SCOPE_CONTAINERS => $element->getAttribute('showInContainer'), ContainerScopeInterface::SCOPE_STORE_CONTAINERS => $element->getAttribute('showInStore')];
     if ($this->storeManager->isSingleStoreMode()) {
         $result = !$element->getAttribute('hide_in_single_store_mode') && array_sum($showInScope);
         return $result;
     }
     return !empty($showInScope[$scope]);
 }
 /**
  * @param \Magento\Framework\Event\Observer $observer
  * @return void
  */
 public function execute(EventObserver $observer)
 {
     if (!$this->moduleManager->isOutputEnabled('Magento_Swatches')) {
         return;
     }
     /** @var \Magento\Framework\Data\Form $form */
     $form = $observer->getForm();
     $fieldset = $form->getElement('base_fieldset');
     $yesnoSource = $this->yesNo->toOptionArray();
     $fieldset->addField('update_product_preview_image', 'select', ['name' => 'update_product_preview_image', 'label' => __('Update Product Preview Image'), 'title' => __('Update Product Preview Image'), 'note' => __('Filtering by this attribute will update the product image on catalog page'), 'values' => $yesnoSource], 'is_filterable');
     $fieldset->addField('use_product_image_for_swatch', 'select', ['name' => 'use_product_image_for_swatch', 'label' => __('Use Product Image for Swatch if Possible'), 'title' => __('Use Product Image for Swatch if Possible'), 'note' => __('Allows use fallback logic for replacing swatch image with product swatch or base image'), 'values' => $yesnoSource], 'is_filterable');
 }
 /**
  * @param \Magento\Framework\Event\Observer $observer
  * @return void
  */
 public function execute(EventObserver $observer)
 {
     if (!$this->moduleManager->isOutputEnabled('Magento_Swatches')) {
         return;
     }
     /** @var \Magento\Framework\DataObject $response */
     $response = $observer->getEvent()->getResponse();
     $types = $response->getTypes();
     $types[] = ['value' => \Magento\Swatches\Model\Swatch::SWATCH_TYPE_VISUAL_ATTRIBUTE_FRONTEND_INPUT, 'label' => __('Visual Swatch'), 'hide_fields' => ['is_unique', 'is_required', 'frontend_class', '_scope', '_default_value', '_front_fieldset']];
     $types[] = ['value' => \Magento\Swatches\Model\Swatch::SWATCH_TYPE_TEXTUAL_ATTRIBUTE_FRONTEND_INPUT, 'label' => __('Text Swatch'), 'hide_fields' => ['is_unique', 'is_required', 'frontend_class', '_scope', '_default_value', '_front_fieldset']];
     $response->setTypes($types);
 }
 /**
  * @param array $requestResult
  * @param bool $moduleManagerResult
  * @param bool $cacheConfigResult
  * @param bool $layoutResult
  * @param bool $can Depersonalize
  * @dataProvider checkIfDepersonalizeDataProvider
  */
 public function testCheckIfDepersonalize(array $requestResult, $moduleManagerResult, $cacheConfigResult, $layoutResult, $canDepersonalize)
 {
     $this->requestMock->expects($this->any())->method('isAjax')->willReturn($requestResult['ajax']);
     $this->requestMock->expects($this->any())->method('isGet')->willReturn($requestResult['get']);
     $this->requestMock->expects($this->any())->method('isHead')->willReturn($requestResult['head']);
     $this->moduleManagerMock->expects($this->any())->method('isEnabled')->with('Magento_PageCache')->willReturn($moduleManagerResult);
     $this->cacheConfigMock->expects($this->any())->method('isEnabled')->willReturn($cacheConfigResult);
     $layoutMock = $this->getMockForAbstractClass('Magento\\Framework\\View\\LayoutInterface', [], '', false);
     $layoutMock->expects($this->any())->method('isCacheable')->willReturn($layoutResult);
     $object = new DepersonalizeChecker($this->requestMock, $this->moduleManagerMock, $this->cacheConfigMock);
     $this->assertEquals($canDepersonalize, $object->checkIfDepersonalize($layoutMock));
 }
 /**
  * @param \Magento\Framework\Event\Observer $observer
  * @return void
  */
 public function execute(\Magento\Framework\Event\Observer $observer)
 {
     if (!$this->moduleManager->isOutputEnabled('Magento_LayeredNavigation')) {
         return;
     }
     /** @var \Magento\Framework\Data\Form\AbstractForm $form */
     $form = $observer->getForm();
     $fieldset = $form->getElement('front_fieldset');
     $fieldset->addField('is_filterable', 'select', ['name' => 'is_filterable', 'label' => __("Use in Layered Navigation"), 'title' => __('Can be used only with catalog input type Dropdown, Multiple Select and Price'), 'note' => __('Can be used only with catalog input type Dropdown, Multiple Select and Price.'), 'values' => [['value' => '0', 'label' => __('No')], ['value' => '1', 'label' => __('Filterable (with results)')], ['value' => '2', 'label' => __('Filterable (no results)')]]]);
     $fieldset->addField('is_filterable_in_search', 'select', ['name' => 'is_filterable_in_search', 'label' => __("Use in Search Results Layered Navigation"), 'title' => __('Can be used only with catalog input type Dropdown, Multiple Select and Price'), 'note' => __('Can be used only with catalog input type Dropdown, Multiple Select and Price.'), 'values' => $this->optionList->toOptionArray()]);
     $fieldset->addField('position', 'text', ['name' => 'position', 'label' => __('Position'), 'title' => __('Position in Layered Navigation'), 'note' => __('Position of attribute in layered navigation block.'), 'class' => 'validate-digits']);
 }
Exemple #29
0
 /**
  * Check if we can show this block.
  * According to @see \Magento\LayeredNavigationStaging\Block\Navigation::canShowBlock
  * We should not show the block if staging is enabled and if we are currently previewing the results.
  *
  * @return bool
  */
 public function canShowBlock()
 {
     if ($this->moduleManager->isEnabled('Magento_Staging')) {
         try {
             $versionManager = $this->objectManager->get('\\Magento\\Staging\\Model\\VersionManager');
             return parent::canShowBlock() && !$versionManager->isPreviewVersion();
         } catch (\Exception $exception) {
             return parent::canShowBlock();
         }
     }
     return parent::canShowBlock();
 }
Exemple #30
0
 /**
  * @return Grid
  */
 protected function _prepareCollection()
 {
     $productId = $this->getRequest()->getParam('id');
     $websiteId = 0;
     if ($store = $this->getRequest()->getParam('store')) {
         $websiteId = $this->_storeManager->getStore($store)->getWebsiteId();
     }
     if ($this->moduleManager->isEnabled('Magento_ProductAlert')) {
         $collection = $this->_priceFactory->create()->getCustomerCollection()->join($productId, $websiteId);
         $this->setCollection($collection);
     }
     return parent::_prepareCollection();
 }