diff --git a/Block/Adminhtml/Category/Tab/FeaturedProducts.php b/Block/Adminhtml/Category/Tab/FeaturedProducts.php index 974b161..9f8007a 100644 --- a/Block/Adminhtml/Category/Tab/FeaturedProducts.php +++ b/Block/Adminhtml/Category/Tab/FeaturedProducts.php @@ -32,8 +32,7 @@ public function __construct( \Magento\Framework\Registry $coreRegistry, \Magento\Framework\Json\DecoderInterface $jsonDecoder, array $data = [] - ) - { + ) { $this->categoryRepository = $categoryRepository; $this->productFactory = $productFactory; $this->coreRegistry = $coreRegistry; @@ -52,7 +51,7 @@ protected function _construct() public function getCategory() { $category = $this->coreRegistry->registry('category'); - if(!$category){ + if (!$category) { $category = $this->categoryRepository->get( $this->getRequest()->getParam('id', 2), $this->getRequest()->getParam('store', 0) @@ -162,8 +161,8 @@ protected function _getSelectedFeaturedProducts() $featuredProducts = $this->getCategory()->getFeaturedProducts(); } - if ($featuredProducts){ - if(is_string($featuredProducts)) { + if ($featuredProducts) { + if (is_string($featuredProducts)) { $featuredProducts = $this->jsonDecoder->decode($featuredProducts); } diff --git a/Block/Navigation.php b/Block/Navigation.php index 242709f..d656480 100644 --- a/Block/Navigation.php +++ b/Block/Navigation.php @@ -4,6 +4,9 @@ class Navigation extends \Magento\Framework\View\Element\Template implements \Magento\Framework\DataObject\IdentityInterface { + const CACHE_KEY_PREFIX = 'NAVIGATION_'; + const CACHE_GROUP = \MageSuite\Navigation\Model\Cache\Type::TYPE_IDENTIFIER; + const ONE_DAY = 86400; /** @@ -20,15 +23,22 @@ class Navigation extends \Magento\Framework\View\Element\Template implements \Ma * @var \Magento\Store\Model\StoreManagerInterface */ protected $storeManager; + /** * @var \Magento\Framework\Serialize\SerializerInterface */ protected $serializer; + /** * @var \Magento\Customer\Model\Session */ protected $session; + /** + * @var \Magento\Framework\Cache\LockGuardedCacheLoader + */ + protected $lockGuardedCacheLoader; + public function __construct( \Magento\Framework\View\Element\Template\Context $context, \Magento\Framework\App\Http\Context $httpContext, @@ -37,8 +47,7 @@ public function __construct( \Magento\Framework\Serialize\SerializerInterface $serializer, \Magento\Customer\Model\Session $session, array $data = [] - ) - { + ) { parent::__construct($context, $data); $this->httpContext = $httpContext; @@ -46,29 +55,33 @@ public function __construct( $this->storeManager = $storeManager; $this->serializer = $serializer; $this->session = $session; + $this->lockGuardedCacheLoader = $context->getLockGuardedCacheLoader(); } - + /** * @return \MageSuite\Navigation\Model\Navigation\Item[] * @throws \Magento\Framework\Exception\NoSuchEntityException */ - public function getItems() { + public function getItems() + { $rootCategoryId = $this->storeManager->getStore()->getRootCategoryId(); $buildedNavigation = $this->navigationBuilder->build($rootCategoryId, $this->getNavigationType()); - $cacheTags = $this->getNavigationTags($buildedNavigation); - - $this->_cache->save($this->serializer->serialize($cacheTags), 'navigation_'.$rootCategoryId.'_'.$this->getNavigationType(), $cacheTags); - return $buildedNavigation; } + public function getCacheTags() + { + return [\MageSuite\Navigation\Model\Cache\Type::CACHE_TAG]; + } + /** * @return string */ - public function getNavigationType() { - if($this->getType() == \MageSuite\Navigation\Service\Navigation\Builder::TYPE_MOBILE) { + public function getNavigationType() + { + if ($this->getType() == \MageSuite\Navigation\Service\Navigation\Builder::TYPE_MOBILE) { return \MageSuite\Navigation\Service\Navigation\Builder::TYPE_MOBILE; } @@ -90,7 +103,10 @@ public function getCacheKeyInfo() ]; } - public function getMobileNavigationEndpointUrl() { + + + public function getMobileNavigationEndpointUrl() + { return $this->getUrl('navigation/mobile/index'); } @@ -106,37 +122,74 @@ public function getCacheLifetime() * @return string[] * @throws \Magento\Framework\Exception\NoSuchEntityException */ - public function getIdentities(){ - $rootCategoryId = $this->storeManager->getStore()->getRootCategoryId(); - - $cachedTags = $this->_cache->load('navigation_'.$rootCategoryId.'_'.$this->getNavigationType()); + public function getIdentities() + { + return [\MageSuite\Navigation\Model\Cache\Type::CACHE_TAG]; + } - if($cachedTags) { - return $this->serializer->unserialize($cachedTags); + /** + * Following methods had to be overriden to modify values for + * CACHE_KEY_PREFIX and CACHE_GROUP constants + */ + public function getCacheKey() + { + if ($this->hasData('cache_key')) { + return self::CACHE_KEY_PREFIX . $this->getData('cache_key'); } - $navigationItems = $this->getItems(); + $key = $this->getCacheKeyInfo(); + $key = array_values($key); + $key = implode('|', $key); + $key = hash('sha1', $key); - return $this->getNavigationTags($navigationItems); + return self::CACHE_KEY_PREFIX . $key; } - /** - * @param \MageSuite\Navigation\Model\Navigation\Item[] $navigationItems - */ - protected function getNavigationTags(array $navigationItems, $aggregatedTags = [\Magento\Catalog\Model\Category::CACHE_TAG]) + protected function _loadCache() { - if(empty($navigationItems)) { - return $aggregatedTags; - } + $collectAction = function () { + if ($this->hasData('translate_inline')) { + $this->inlineTranslation->suspend($this->getData('translate_inline')); + } + + $this->_beforeToHtml(); + return $this->_toHtml(); + }; - foreach($navigationItems as $navigationItem) { - if($navigationItem->hasSubItems()) { - $aggregatedTags = array_merge($aggregatedTags, $this->getNavigationTags($navigationItem->getSubItems(), $aggregatedTags)); + if ($this->getCacheLifetime() === null || !$this->_cacheState->isEnabled(self::CACHE_GROUP)) { + $html = $collectAction(); + if ($this->hasData('translate_inline')) { + $this->inlineTranslation->resume(); } + return $html; + } + $loadAction = function () { + return $this->_cache->load($this->getCacheKey()); + }; + + $saveAction = function ($data) { + $this->_saveCache($data); + if ($this->hasData('translate_inline')) { + $this->inlineTranslation->resume(); + } + }; + + return (string)$this->lockGuardedCacheLoader->lockedLoadData( + $this->getCacheKey(), + $loadAction, + $collectAction, + $saveAction + ); + } - $aggregatedTags = array_merge($aggregatedTags, $navigationItem->getIdentities()); + protected function _saveCache($data) + { + if (!$this->getCacheLifetime() || !$this->_cacheState->isEnabled(self::CACHE_GROUP)) { + return false; } + $cacheKey = $this->getCacheKey(); - return array_unique($aggregatedTags); + $this->_cache->save($data, $cacheKey, array_unique($this->getCacheTags()), $this->getCacheLifetime()); + return $this; } -} \ No newline at end of file +} diff --git a/Block/Navigation/ActiveCategory.php b/Block/Navigation/ActiveCategory.php index 44779ed..5590154 100644 --- a/Block/Navigation/ActiveCategory.php +++ b/Block/Navigation/ActiveCategory.php @@ -10,13 +10,12 @@ public function __construct( \Magento\Backend\Block\Template\Context $context, \Magento\Framework\Registry $registry, array $data = [] - ) - { + ) { $this->registry = $registry; parent::__construct($context, $data); } - + public function getActiveCategoryPath() { /** @var \Magento\Catalog\Model\Category $currentCategory */ @@ -28,11 +27,11 @@ public function getActiveCategoryPath() $categoryPath = $currentCategory->getPath(); - return $this->removeRootCategoryFromPath($categoryPath);; + return $this->removeRootCategoryFromPath($categoryPath); } private function removeRootCategoryFromPath($categoryPath) { return substr($categoryPath, strpos($categoryPath, '/') + 1); } -} \ No newline at end of file +} diff --git a/Controller/Adminhtml/Category/FeaturedProducts.php b/Controller/Adminhtml/Category/FeaturedProducts.php index d214b15..0d67cd3 100644 --- a/Controller/Adminhtml/Category/FeaturedProducts.php +++ b/Controller/Adminhtml/Category/FeaturedProducts.php @@ -10,4 +10,4 @@ abstract class FeaturedProducts extends \Magento\Backend\App\Action * @see _isAllowed() */ const ADMIN_RESOURCE = 'MageSuite_Navigation::item_list'; -} \ No newline at end of file +} diff --git a/Controller/Adminhtml/Category/FeaturedProducts/Grid.php b/Controller/Adminhtml/Category/FeaturedProducts/Grid.php index 835c2eb..90cf0c5 100644 --- a/Controller/Adminhtml/Category/FeaturedProducts/Grid.php +++ b/Controller/Adminhtml/Category/FeaturedProducts/Grid.php @@ -18,8 +18,7 @@ public function __construct( \Magento\Backend\App\Action\Context $context, \Magento\Framework\Controller\Result\RawFactory $resultRawFactory, \Magento\Framework\View\LayoutFactory $layoutFactory - ) - { + ) { parent::__construct($context); $this->resultRawFactory = $resultRawFactory; $this->layoutFactory = $layoutFactory; @@ -36,6 +35,4 @@ public function execute() )->toHtml() ); } - - -} \ No newline at end of file +} diff --git a/Controller/Mobile/Index.php b/Controller/Mobile/Index.php index 9efc7c2..7c13c24 100644 --- a/Controller/Mobile/Index.php +++ b/Controller/Mobile/Index.php @@ -14,4 +14,4 @@ public function execute() { return $this->resultFactory->create(\Magento\Framework\Controller\ResultFactory::TYPE_LAYOUT); } -} \ No newline at end of file +} diff --git a/Migration/AddIncludeInMobileDefaultValue.php b/Migration/AddIncludeInMobileDefaultValue.php index 744cc11..0a587fd 100644 --- a/Migration/AddIncludeInMobileDefaultValue.php +++ b/Migration/AddIncludeInMobileDefaultValue.php @@ -30,7 +30,7 @@ public function __construct( \Magento\Store\Model\StoreManagerInterface $storeManager, \Magento\Framework\EntityManager\MetadataPool $metadataPool, \Psr\Log\LoggerInterface $logger - ){ + ) { $this->connection = $resourceConnection->getConnection(); $this->storeManager = $storeManager; $this->logger = $logger; @@ -49,7 +49,7 @@ public function execute($includeInMobileAttributeId, $includeInDesktopAttributeI $storeIds = array_keys($stores); sort($storeIds); - foreach($storeIds as $storeId){ + foreach ($storeIds as $storeId) { $query = "INSERT IGNORE INTO $categoryEntityIntTable (attribute_id, store_id, $linkField, value) SELECT $includeInMobileAttributeId AS attribute_id, @@ -60,12 +60,12 @@ public function execute($includeInMobileAttributeId, $includeInDesktopAttributeI LEFT JOIN $categoryEntityIntTable AS category_int ON category.$linkField = category_int.$linkField WHERE category_int.attribute_id = $includeInDesktopAttributeId AND store_id = $storeId;"; - try{ + try { $this->connection->query($query); - }catch (Exception $e){ + } catch (Exception $e) { $message = sprintf('Error during AddIncludeInMobileDefaultValue::execute(): %s, storeId: %s', $e->getMessage(), $storeId); $this->logger->warning($message); } } } -} \ No newline at end of file +} diff --git a/Model/Cache/Type.php b/Model/Cache/Type.php new file mode 100644 index 0000000..1685dc8 --- /dev/null +++ b/Model/Cache/Type.php @@ -0,0 +1,48 @@ +get(self::TYPE_IDENTIFIER), self::CACHE_TAG); + $this->eventManager = $eventManager; + $this->cacheContext = $cacheContext; + } + + public function clean($mode = \Zend_Cache::CLEANING_MODE_ALL, array $tags = []) + { + if($mode == \Zend_Cache::CLEANING_MODE_ALL) { + $this->clearFullPageCache(); + } + + return parent::clean($mode, $tags); + } + + public function clearFullPageCache(): void + { + $this->cacheContext->registerTags([self::CACHE_TAG]); + $this->eventManager->dispatch('clean_cache_by_tags', ['object' => $this->cacheContext]); + } +} diff --git a/Model/Navigation/FeaturedProducts.php b/Model/Navigation/FeaturedProducts.php index bf3723c..e7b6b39 100644 --- a/Model/Navigation/FeaturedProducts.php +++ b/Model/Navigation/FeaturedProducts.php @@ -22,21 +22,22 @@ class FeaturedProducts public function __construct( \Magento\Catalog\Model\Category $category, \MageSuite\Navigation\Model\Navigation\ResourceModel\FeaturedProducts $resourceModel - ) - { + ) { $this->category = $category; $this->resourceModel = $resourceModel; } - public function getHeader() { + public function getHeader() + { return $this->category->getFeaturedProductsHeader(); } - public function getProducts() { - if(!$this->products) { + public function getProducts() + { + if (!$this->products) { $this->products = $this->resourceModel->getProducts($this->category); } return $this->products; } -} \ No newline at end of file +} diff --git a/Model/Navigation/Item.php b/Model/Navigation/Item.php index 05d944c..8531be9 100644 --- a/Model/Navigation/Item.php +++ b/Model/Navigation/Item.php @@ -52,8 +52,7 @@ public function __construct( \MageSuite\Category\Helper\Category $categoryHelper, \MageSuite\CategoryIcon\Helper\CategoryIcon $categoryIconHelper, array $data = [] - ) - { + ) { parent::__construct($data); $this->category = $category; @@ -67,14 +66,16 @@ public function __construct( /** * @return int */ - public function getId() { + public function getId() + { return $this->category->getId(); } /** * @param $label string */ - public function setLabel($label) { + public function setLabel($label) + { $this->setData('label', $label); } @@ -83,7 +84,7 @@ public function setLabel($label) { */ public function getLabel() { - if($this->hasData('label')){ + if ($this->hasData('label')) { return $this->getData('label'); } @@ -103,7 +104,7 @@ public function setIdentifier($identifier) */ public function getIdentifier() { - if($this->hasData('identifier')){ + if ($this->hasData('identifier')) { return $this->getData('identifier'); } @@ -113,7 +114,8 @@ public function getIdentifier() /** * @return int */ - public function getParentId() { + public function getParentId() + { return $this->category->getParentId(); } @@ -121,10 +123,11 @@ public function getParentId() { * @return string * @throws \Magento\Framework\Exception\NoSuchEntityException */ - public function getUrl() { + public function getUrl() + { $customUrl = $this->category->getCategoryCustomUrl(); - if(!$customUrl){ + if (!$customUrl) { return $this->category->getUrl(); } @@ -134,15 +137,17 @@ public function getUrl() { /** * @return int */ - public function getProductCount() { + public function getProductCount() + { return $this->categoryHelper->getProductCount($this->category); } /** * @return FeaturedProducts */ - public function getFeaturedProducts() { - if(!$this->featuredProducts) { + public function getFeaturedProducts() + { + if (!$this->featuredProducts) { $this->featuredProducts = $this->featuredProductsFactory->create(['category' => $this->category]); } @@ -152,8 +157,9 @@ public function getFeaturedProducts() { /** * @return \MageSuite\Navigation\Model\Navigation\ImageTeaser */ - public function getImageTeaser() { - if(!$this->imageTeaser) { + public function getImageTeaser() + { + if (!$this->imageTeaser) { $this->imageTeaser = $this->imageTeaserFactory->create(['category' => $this->category]); } @@ -163,22 +169,25 @@ public function getImageTeaser() { /** * @return bool */ - public function hasFeaturedProducts() { + public function hasFeaturedProducts() + { return !empty($this->getFeaturedProducts()->getProducts()); } /** * @return bool */ - public function hasSubItems() { + public function hasSubItems() + { return !empty($this->getSubItems()); } /** * @return bool */ - public function hasImageTeaser() { - if($this->category->getLevel() > 2) { + public function hasImageTeaser() + { + if ($this->category->getLevel() > 2) { return false; } @@ -188,15 +197,18 @@ public function hasImageTeaser() { /** * @return bool */ - public function hasCustomUrl() { + public function hasCustomUrl() + { return !empty($this->category->getCategoryCustomUrl()); } - public function getIdentities() { + public function getIdentities() + { return $this->category->getIdentities(); } - public function getCategoryIcon() { + public function getCategoryIcon() + { return $this->categoryIconHelper->getUrl($this->category); } } diff --git a/Model/Navigation/ResourceModel/FeaturedProducts.php b/Model/Navigation/ResourceModel/FeaturedProducts.php index 94de74d..2345368 100644 --- a/Model/Navigation/ResourceModel/FeaturedProducts.php +++ b/Model/Navigation/ResourceModel/FeaturedProducts.php @@ -30,8 +30,7 @@ public function __construct( \Magento\Catalog\Model\ResourceModel\Category $categoryResource, \Magento\Framework\Json\DecoderInterface $jsonDecoder, \Magento\Catalog\Model\Config $catalogConfig - ) - { + ) { $this->productsCollectionFactory = $productsCollectionFactory; $this->categoryResource = $categoryResource; $this->jsonDecoder = $jsonDecoder; @@ -62,10 +61,10 @@ protected function getFeaturedProductsIds($category) ->getAttributeRawValue($category->getId(), 'featured_products', 0); } - if (!$featuredProducts OR $featuredProducts == '{}') { + if (!$featuredProducts or $featuredProducts == '{}') { return []; } return array_keys($this->jsonDecoder->decode($featuredProducts)); } -} \ No newline at end of file +} diff --git a/Plugin/Service/Navigation/Builder/SortItemsAlphabetically.php b/Plugin/Service/Navigation/Builder/SortItemsAlphabetically.php index 57300d8..b10dffe 100644 --- a/Plugin/Service/Navigation/Builder/SortItemsAlphabetically.php +++ b/Plugin/Service/Navigation/Builder/SortItemsAlphabetically.php @@ -55,4 +55,4 @@ protected function sortItems($subItems) return $subItems; } -} \ No newline at end of file +} diff --git a/Service/Category/CustomUrlGenerator.php b/Service/Category/CustomUrlGenerator.php index 918de0b..fba24aa 100644 --- a/Service/Category/CustomUrlGenerator.php +++ b/Service/Category/CustomUrlGenerator.php @@ -14,8 +14,9 @@ public function __construct(\Magento\Store\Model\StoreManagerInterface $storeMan $this->storeManager = $storeManager; } - public function generate($url) { - if(strpos($url, 'http') !== false){ + public function generate($url) + { + if (strpos($url, 'http') !== false) { return $url; } @@ -23,4 +24,4 @@ public function generate($url) { return $baseUrl . ltrim($url, '/'); } -} \ No newline at end of file +} diff --git a/Service/Mapper/CategoryMapper.php b/Service/Mapper/CategoryMapper.php index 1b907ae..1d2b795 100644 --- a/Service/Mapper/CategoryMapper.php +++ b/Service/Mapper/CategoryMapper.php @@ -32,8 +32,7 @@ public function __construct( \Magento\Store\Model\StoreManagerInterface $storeManager, \MageSuite\Navigation\Service\Category\CustomUrlGenerator $customUrlGenerator, \MageSuite\Media\Service\SrcSetResolver $srcSetResolver - - ){ + ) { $this->mediaResolver = $mediaResolver; $this->storeManager = $storeManager; $this->customUrlGenerator = $customUrlGenerator; @@ -42,7 +41,7 @@ public function __construct( public function mapCategory($category) { - if(!$category->getImageTeaser()){ + if (!$category->getImageTeaser()) { return []; } @@ -74,7 +73,7 @@ public function getImageUrl() { $rawImageUrl = $this->getRawImageUrl(); - if(empty($rawImageUrl)){ + if (empty($rawImageUrl)) { return null; } @@ -85,7 +84,7 @@ public function getImageUrl() public function getRawImageUrl() { - if(!empty($this->rawImageUrl)){ + if (!empty($this->rawImageUrl)) { $this->rawImageUrl; } diff --git a/Service/Navigation/Builder.php b/Service/Navigation/Builder.php index 5ff36e6..b8012c9 100644 --- a/Service/Navigation/Builder.php +++ b/Service/Navigation/Builder.php @@ -20,8 +20,7 @@ class Builder implements BuilderInterface public function __construct( \Magento\Catalog\Api\CategoryRepositoryInterface $categoryRepository, \MageSuite\Navigation\Model\Navigation\ItemFactory $itemFactory - ) - { + ) { $this->itemFactory = $itemFactory; $this->categoryRepository = $categoryRepository; } diff --git a/Service/Navigation/BuilderInterface.php b/Service/Navigation/BuilderInterface.php index feb840c..9598368 100644 --- a/Service/Navigation/BuilderInterface.php +++ b/Service/Navigation/BuilderInterface.php @@ -10,4 +10,4 @@ interface BuilderInterface * @return \MageSuite\Navigation\Model\Navigation\Item[] */ public function build($rootCategoryId); -} \ No newline at end of file +} diff --git a/Setup/InstallData.php b/Setup/InstallData.php index c6d6e20..a3824ab 100644 --- a/Setup/InstallData.php +++ b/Setup/InstallData.php @@ -22,8 +22,7 @@ class InstallData implements \Magento\Framework\Setup\InstallDataInterface public function __construct( \Magento\Eav\Setup\EavSetupFactory $eavSetupFactory, \Magento\Framework\Setup\ModuleDataSetupInterface $moduleDataSetupInterface - ) - { + ) { $this->eavSetupFactory = $eavSetupFactory; $this->moduleDataSetupInterface = $moduleDataSetupInterface; @@ -33,8 +32,7 @@ public function __construct( public function install( \Magento\Framework\Setup\ModuleDataSetupInterface $setup, \Magento\Framework\Setup\ModuleContextInterface $context - ) - { + ) { if (!$this->eavSetup->getAttributeId(\Magento\Catalog\Model\Category::ENTITY, 'category_custom_url')) { $this->eavSetup->addAttribute( \Magento\Catalog\Model\Category::ENTITY, @@ -78,7 +76,7 @@ public function install( 'image_teaser_button_link' => ['label' => 'Button Link', 'type' => 'varchar', 'input' => 'text', 'sort_order' => 60] ]; - foreach($attributes AS $attributeCode => $attribute){ + foreach ($attributes as $attributeCode => $attribute) { if (!$this->eavSetup->getAttributeId(\Magento\Catalog\Model\Category::ENTITY, $attributeCode)) { $this->eavSetup->addAttribute( \Magento\Catalog\Model\Category::ENTITY, @@ -131,4 +129,4 @@ public function install( ); } } -} \ No newline at end of file +} diff --git a/Setup/UpgradeData.php b/Setup/UpgradeData.php index 73126bc..422de0b 100644 --- a/Setup/UpgradeData.php +++ b/Setup/UpgradeData.php @@ -34,8 +34,7 @@ public function __construct( \Magento\Framework\Setup\ModuleDataSetupInterface $moduleDataSetupInterface, \Magento\Eav\Model\Config $eavConfig, \MageSuite\Navigation\Migration\AddIncludeInMobileDefaultValue $addIncludeInMobileDefaultValue - ) - { + ) { $this->eavSetupFactory = $eavSetupFactory; $this->moduleDataSetupInterface = $moduleDataSetupInterface; $this->eavSetup = $this->eavSetupFactory->create(['setup' => $this->moduleDataSetupInterface]); @@ -89,7 +88,7 @@ protected function addDefaultValueToIncludeInMobileNavAttribute() $includeInMobileAttributeId = $this->eavSetup->getAttributeId(\Magento\Catalog\Model\Category::ENTITY, 'include_in_mobile_navigation'); $includeInDesktopAttributeId = $this->eavSetup->getAttributeId(\Magento\Catalog\Model\Category::ENTITY, 'include_in_menu'); - if(!$includeInMobileAttributeId or !$includeInDesktopAttributeId){ + if (!$includeInMobileAttributeId or !$includeInDesktopAttributeId) { return false; } @@ -100,18 +99,18 @@ protected function migrateNavigationImageTeaserToNewVersion() { $entityType = $this->eavSetup->getEntityTypeId('catalog_category'); - $this->eavSetup->updateAttribute($entityType,'image_teaser_headline','frontend_label','Slogan'); - $this->eavSetup->updateAttribute($entityType,'image_teaser_headline','attribute_code','image_teaser_slogan'); + $this->eavSetup->updateAttribute($entityType, 'image_teaser_headline', 'frontend_label', 'Slogan'); + $this->eavSetup->updateAttribute($entityType, 'image_teaser_headline', 'attribute_code', 'image_teaser_slogan'); - $this->eavSetup->removeAttribute(\Magento\Catalog\Model\Category::ENTITY,'image_teaser_subheadline'); + $this->eavSetup->removeAttribute(\Magento\Catalog\Model\Category::ENTITY, 'image_teaser_subheadline'); - $this->eavSetup->updateAttribute($entityType,'image_teaser_paragraph','frontend_label','Description'); - $this->eavSetup->updateAttribute($entityType,'image_teaser_paragraph','attribute_code','image_teaser_description'); + $this->eavSetup->updateAttribute($entityType, 'image_teaser_paragraph', 'frontend_label', 'Description'); + $this->eavSetup->updateAttribute($entityType, 'image_teaser_paragraph', 'attribute_code', 'image_teaser_description'); - $this->eavSetup->updateAttribute($entityType,'image_teaser_button_label','frontend_label','CTA Label'); - $this->eavSetup->updateAttribute($entityType,'image_teaser_button_label','attribute_code','image_teaser_cta_label'); + $this->eavSetup->updateAttribute($entityType, 'image_teaser_button_label', 'frontend_label', 'CTA Label'); + $this->eavSetup->updateAttribute($entityType, 'image_teaser_button_label', 'attribute_code', 'image_teaser_cta_label'); - $this->eavSetup->updateAttribute($entityType,'image_teaser_button_link','frontend_label','CTA target link'); - $this->eavSetup->updateAttribute($entityType,'image_teaser_button_link','attribute_code','image_teaser_cta_link'); + $this->eavSetup->updateAttribute($entityType, 'image_teaser_button_link', 'frontend_label', 'CTA target link'); + $this->eavSetup->updateAttribute($entityType, 'image_teaser_button_link', 'attribute_code', 'image_teaser_cta_link'); } } diff --git a/Test/Integration/Service/Navigation/BuilderTest.php b/Test/Integration/Service/Navigation/BuilderTest.php index 1fcaa21..b39df66 100644 --- a/Test/Integration/Service/Navigation/BuilderTest.php +++ b/Test/Integration/Service/Navigation/BuilderTest.php @@ -21,7 +21,8 @@ class BuilderTest extends \PHPUnit\Framework\TestCase protected $builder; - public function setUp(): void { + public function setUp(): void + { $this->objectManager = \Magento\TestFramework\ObjectManager::getInstance(); $this->builder = $this->objectManager->get(\MageSuite\Navigation\Service\Navigation\Builder::class); } @@ -34,7 +35,8 @@ public function setUp(): void { * @magentoDataFixture loadCategoriesNotIncludedInMenu * @magentoCache all disabled */ - public function testItReturnsNavigationCorrectStructure() { + public function testItReturnsNavigationCorrectStructure() + { $navigation = $this->builder->build(self::ROOT_CATEGORY_ID); $this->assertCount(7, $navigation); $this->assertCount(1, $navigation[0]->getSubItems()); @@ -57,7 +59,8 @@ public function testItReturnsNavigationCorrectStructure() { * @magentoDataFixture Magento/Catalog/_files/categories.php * @magentoDataFixture loadCategoriesNotIncludedInMenu */ - public function testItReturnsOnlyItemsForMobileNavigation() { + public function testItReturnsOnlyItemsForMobileNavigation() + { $navigation = $this->builder->build( self::ROOT_CATEGORY_ID, \MageSuite\Navigation\Service\Navigation\Builder::TYPE_MOBILE @@ -90,7 +93,8 @@ public function testItReturnsNavigationCorrectSorting() * @magentoDataFixture Magento/Catalog/_files/categories.php * @magentoDataFixture loadCategoriesWithCustomAttributes */ - public function testItReturnsCategoriesWithCorrectAttributes() { + public function testItReturnsCategoriesWithCorrectAttributes() + { $result = $this->builder->build(self::ROOT_CATEGORY_ID); $this->assertCount(10, $result); $this->assertEquals('http://localhost/index.php/testurl.html', $result[8]->getUrl()); @@ -111,7 +115,8 @@ public function testItReturnsCategoriesWithCorrectAttributes() { * @magentoDataFixture Magento/Catalog/_files/categories.php * @magentoDataFixture loadCategoriesWithCustomAttributes */ - public function testItReturnsNavigationWithImageTeaser() { + public function testItReturnsNavigationWithImageTeaser() + { $result = $this->builder->build(2); $navigationItem = $result[9]; $this->assertEquals(15, $navigationItem->getId()); @@ -131,7 +136,8 @@ public function testItReturnsNavigationWithImageTeaser() { $this->assertFalse($navigationItem->hasImageTeaser()); } - public static function loadCategoriesNotIncludedInMenu() { + public static function loadCategoriesNotIncludedInMenu() + { include self::FIXTURE_DIRECTORY.'categories_not_included_in_menu.php'; /** @var \Magento\Framework\App\CacheInterface $cache */ @@ -141,7 +147,8 @@ public static function loadCategoriesNotIncludedInMenu() { $cache->remove(\MageSuite\Category\Model\ResourceModel\Category::CACHE_TAG); } - public static function loadCategoriesWithCustomAttributes() { + public static function loadCategoriesWithCustomAttributes() + { include self::FIXTURE_DIRECTORY.'categories_with_custom_attributes.php'; /** @var \Magento\Framework\App\CacheInterface $cache */ @@ -151,7 +158,8 @@ public static function loadCategoriesWithCustomAttributes() { $cache->remove(\MageSuite\Category\Model\ResourceModel\Category::CACHE_TAG); } - public static function loadCategoriesWithProducts() { + public static function loadCategoriesWithProducts() + { include self::FIXTURE_DIRECTORY.'categories_sorted_with_products.php'; /** @var \Magento\Framework\App\CacheInterface $cache */ diff --git a/etc/cache.xml b/etc/cache.xml new file mode 100644 index 0000000..89aea77 --- /dev/null +++ b/etc/cache.xml @@ -0,0 +1,7 @@ + + + + + Shop navigation contents cache + + diff --git a/registration.php b/registration.php index a8e477d..b77a06b 100644 --- a/registration.php +++ b/registration.php @@ -3,4 +3,4 @@ \Magento\Framework\Component\ComponentRegistrar::MODULE, 'MageSuite_Navigation', __DIR__ -); \ No newline at end of file +);