From 3cef0d8c8a6fbed43abef6481d45f0a89d178a57 Mon Sep 17 00:00:00 2001 From: onesh Date: Tue, 19 Mar 2024 11:03:53 +0700 Subject: [PATCH 1/7] Update: change system config canonical field --- Helper/Data.php | 24 +++++++++++ Model/Config/Source/CanonicalFor.php | 43 +++++++++++++++++++ .../CanUseCanonicalTagForCategories.php | 20 +++++++-- .../Helper/CanUseCanonicalTagForProducts.php | 22 +++++++--- etc/adminhtml/system.xml | 16 +++---- etc/config.xml | 3 +- 6 files changed, 107 insertions(+), 21 deletions(-) create mode 100644 Model/Config/Source/CanonicalFor.php diff --git a/Helper/Data.php b/Helper/Data.php index 5265a77..634832c 100755 --- a/Helper/Data.php +++ b/Helper/Data.php @@ -226,4 +226,28 @@ public function getQtySale($product) return 0; } } + + /** + * @param $storeId + * @return bool + */ + public function canUseCanonicalForCategory($storeId) + { + $value = $this->getDuplicateConfig('canonical_tag', $storeId); + $value = $value ? explode(',', $value) : 0; + + return in_array(1, is_array($value) ? $value : [$value]); + } + + /** + * @param $storeId + * @return bool + */ + public function canUseCanonicalForProduct($storeId) + { + $value = $this->getDuplicateConfig('canonical_tag', $storeId); + $value = $value ? explode(',', $value) : 0; + + return in_array(2, is_array($value) ? $value : [$value]); + } } diff --git a/Model/Config/Source/CanonicalFor.php b/Model/Config/Source/CanonicalFor.php new file mode 100644 index 0000000..4980873 --- /dev/null +++ b/Model/Config/Source/CanonicalFor.php @@ -0,0 +1,43 @@ + __('--Please select--'), 'value' => '0'], + ['label' => __('Category'), 'value' => '1'], + ['label' => __('Product'), 'value' => '2'] + ]; + } +} diff --git a/Plugin/Helper/CanUseCanonicalTagForCategories.php b/Plugin/Helper/CanUseCanonicalTagForCategories.php index f347105..62c1f96 100755 --- a/Plugin/Helper/CanUseCanonicalTagForCategories.php +++ b/Plugin/Helper/CanUseCanonicalTagForCategories.php @@ -21,6 +21,7 @@ namespace Mageplaza\Seo\Plugin\Helper; +use Magento\Store\Model\StoreManagerInterface; use Magento\Catalog\Helper\Category; use Mageplaza\Seo\Helper\Data as HelperData; @@ -30,6 +31,13 @@ */ class CanUseCanonicalTagForCategories { + /** + * Store manager + * + * @var StoreManagerInterface + */ + protected $_storeManager; + /** * @var HelperData */ @@ -38,11 +46,15 @@ class CanUseCanonicalTagForCategories /** * CanUseCanonicalTagForCategories constructor. * + * @param StoreManagerInterface $storeManager * @param HelperData $helper */ - public function __construct(HelperData $helper) - { - $this->_helper = $helper; + public function __construct( + StoreManagerInterface $storeManager, + HelperData $helper + ) { + $this->_storeManager = $storeManager; + $this->_helper = $helper; } /** @@ -54,7 +66,7 @@ public function __construct(HelperData $helper) public function afterCanUseCanonicalTag(Category $category, $result) { if ($this->_helper->isEnabled()) { - return $this->_helper->getDuplicateConfig('category_canonical_tag'); + return $this->_helper->canUseCanonicalForCategory($this->_storeManager->getStore()->getId()); } return $result; diff --git a/Plugin/Helper/CanUseCanonicalTagForProducts.php b/Plugin/Helper/CanUseCanonicalTagForProducts.php index a02bff1..eee6d7f 100755 --- a/Plugin/Helper/CanUseCanonicalTagForProducts.php +++ b/Plugin/Helper/CanUseCanonicalTagForProducts.php @@ -22,6 +22,7 @@ namespace Mageplaza\Seo\Plugin\Helper; use Magento\Catalog\Helper\Product; +use Magento\Store\Model\StoreManagerInterface; use Mageplaza\Seo\Helper\Data as HelperData; /** @@ -30,19 +31,30 @@ */ class CanUseCanonicalTagForProducts { + /** + * Store manager + * + * @var StoreManagerInterface + */ + protected $_storeManager; + /** * @var HelperData */ protected $_helper; /** - * CanUseCanonicalTagForProducts constructor. + * CanUseCanonicalTagForProduct constructor. * + * @param StoreManagerInterface $storeManager * @param HelperData $helper */ - public function __construct(HelperData $helper) - { - $this->_helper = $helper; + public function __construct( + StoreManagerInterface $storeManager, + HelperData $helper + ) { + $this->_storeManager = $storeManager; + $this->_helper = $helper; } /** @@ -54,7 +66,7 @@ public function __construct(HelperData $helper) public function afterCanUseCanonicalTag(Product $product, $result) { if ($this->_helper->isEnabled()) { - return $this->_helper->getDuplicateConfig('product_canonical_tag'); + return $this->_helper->canUseCanonicalForProduct($this->_storeManager->getStore()->getId()); } return $result; diff --git a/etc/adminhtml/system.xml b/etc/adminhtml/system.xml index c0b2d66..b47b4e5 100755 --- a/etc/adminhtml/system.xml +++ b/etc/adminhtml/system.xml @@ -42,22 +42,18 @@ ]]> - + Magento\Config\Model\Config\Source\Yesno - - - Magento\Config\Model\Config\Source\Yesno - Avoid duplicate content. - - - - Magento\Config\Model\Config\Source\Yesno - Avoid duplicate content. + + + Mageplaza\Seo\Model\Config\Source\CanonicalFor + Using canonical URLs will avoid duplicating content between product and category pages, + avoiding low quality ratings and reduced rankings on search engines. diff --git a/etc/config.xml b/etc/config.xml index 594f562..fbfd32b 100755 --- a/etc/config.xml +++ b/etc/config.xml @@ -44,8 +44,7 @@ - 1 - 1 + From a83f970f3738d05160e13a4b064dc8193f374055 Mon Sep 17 00:00:00 2001 From: onesh Date: Tue, 19 Mar 2024 11:10:01 +0700 Subject: [PATCH 2/7] Update: add canRestore for system config field --- etc/adminhtml/system.xml | 18 +++++++++--------- etc/config.xml | 3 ++- 2 files changed, 11 insertions(+), 10 deletions(-) diff --git a/etc/adminhtml/system.xml b/etc/adminhtml/system.xml index b47b4e5..efc57df 100755 --- a/etc/adminhtml/system.xml +++ b/etc/adminhtml/system.xml @@ -58,12 +58,12 @@ - + Magento\Config\Model\Config\Source\Yesno Learn more ]]> - + Mageplaza\Seo\Model\Config\Source\Attribute @@ -71,14 +71,14 @@ required-entry - + 1 Mageplaza\Seo\Model\Config\Source\PriceValidUntil - + 1 @@ -87,7 +87,7 @@ Mageplaza\Seo\Block\Adminhtml\System\Config\Date required-entry - + 1 @@ -95,7 +95,7 @@ Mageplaza\Seo\Model\Config\Source\ModelField here ]]> - + 1 @@ -104,7 +104,7 @@ required-entry Recommend field: sku, barcode - + Magento\Config\Model\Config\Source\Yesno here ]]> @@ -112,7 +112,7 @@ - + Magento\Config\Model\Config\Source\Yesno here ]]> @@ -123,7 +123,7 @@ 1 - + Mageplaza\Seo\Model\Config\Source\BusinessType diff --git a/etc/config.xml b/etc/config.xml index fbfd32b..594f562 100755 --- a/etc/config.xml +++ b/etc/config.xml @@ -44,7 +44,8 @@ - + 1 + 1 From 69ba64f75a6e814444d6a28502ee9daabc5d956e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Huy=20Ph=C3=BAc?= Date: Wed, 20 Mar 2024 18:22:37 +0700 Subject: [PATCH 3/7] fix: fix bug Meta Title --- Plugin/SeoRender.php | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/Plugin/SeoRender.php b/Plugin/SeoRender.php index 257231d..3bf9b6f 100755 --- a/Plugin/SeoRender.php +++ b/Plugin/SeoRender.php @@ -512,7 +512,11 @@ public function showProductStructuredData() $productStructuredData['brand']['name'] = (($brandAttribute === 'quantity_and_stock_status' && $brandValue >= 0) || $brandValue) ? $brandValue : 'Brand'; if ($brandAttribute === 'meta_title') { - $productStructuredData['brand']['name'] = $product->getMetaTitle(); + if ($this->getMetaTitle()) { + $productStructuredData['brand']['name'] = $this->getMetaTitle(); + } else { + $productStructuredData['brand']['name'] = $product->getMetaTitle(); + } } } @@ -584,6 +588,16 @@ public function getProduct() return $this->registry->registry('current_product'); } + /** + * Get meta title + * + * @return mixed + */ + public function getMetaTitle() + { + return $this->registry->registry('meta_title'); + } + /** * Get Url * From a08d7be89a216ca34635788e23b3b941ae3bd4b7 Mon Sep 17 00:00:00 2001 From: onesh Date: Thu, 21 Mar 2024 16:00:50 +0700 Subject: [PATCH 4/7] Fix: default value field config system --- etc/config.xml | 3 +++ view/adminhtml/web/css/source/_module.less | 23 ++++++++++++++++++++++ 2 files changed, 26 insertions(+) create mode 100644 view/adminhtml/web/css/source/_module.less diff --git a/etc/config.xml b/etc/config.xml index 594f562..8008015 100755 --- a/etc/config.xml +++ b/etc/config.xml @@ -30,6 +30,9 @@ 1 + + 0 + 0 manufacturer diff --git a/view/adminhtml/web/css/source/_module.less b/view/adminhtml/web/css/source/_module.less new file mode 100644 index 0000000..4937200 --- /dev/null +++ b/view/adminhtml/web/css/source/_module.less @@ -0,0 +1,23 @@ +/** + * Mageplaza + * + * NOTICE OF LICENSE + * + * This source file is subject to the Mageplaza.com license that is + * available through the world-wide-web at this URL: + * https://www.mageplaza.com/LICENSE.txt + * + * DISCLAIMER + * + * Do not edit or add to this file if you wish to upgrade this extension to newer + * version in the future. + * + * @category Mageplaza + * @package Mageplaza_Seo + * @copyright Copyright (c) Mageplaza (https://www.mageplaza.com/) + * @license https://www.mageplaza.com/LICENSE.txt + */ + +#seo_duplicate_canonical_tag { + height: 120px !important; +} From 3db2ec8943b85a3625ff7da219fadabb7efcd8bb Mon Sep 17 00:00:00 2001 From: onesh Date: Thu, 25 Apr 2024 14:38:16 +0700 Subject: [PATCH 5/7] Fix: default value date field system config --- Setup/Patch/Data/UpdateDateTimeValue.php | 109 +++++++++++++++++++++++ 1 file changed, 109 insertions(+) create mode 100755 Setup/Patch/Data/UpdateDateTimeValue.php diff --git a/Setup/Patch/Data/UpdateDateTimeValue.php b/Setup/Patch/Data/UpdateDateTimeValue.php new file mode 100755 index 0000000..14b5aac --- /dev/null +++ b/Setup/Patch/Data/UpdateDateTimeValue.php @@ -0,0 +1,109 @@ +moduleDataSetup = $moduleDataSetup; + $this->_helperData = $helperData; + } + + /** + * @return void + */ + public function apply() + { + $setup = $this->moduleDataSetup; + + $path = Data::CONFIG_MODULE_PATH . '/richsnippets/price_valid_until_custom'; + $table = $setup->getTable('core_config_data'); + $adapter = $setup->getConnection(); + $select = $adapter->select() + ->from($table, 'value') + ->where('path = :path_custom'); + $binds = ['path_custom' => $path]; + + if (!$adapter->fetchOne($select, $binds)) { + $data = [ + 'scope' => 'default', + 'scope_id' => 0, + 'path' => $path, + 'value' => 'NULL', + ]; + $setup->getConnection()->insertOnDuplicate($setup->getTable('core_config_data'), $data, ['value']); + } + } + + /** + * @inheritdoc + */ + public static function getDependencies() + { + return []; + } + + /** + * @inheritdoc + */ + public function getAliases() + { + return []; + } + + /** + * @inheritdoc + */ + public function revert() + { + return []; + } +} From 4e309060a59712f88bb2ced1c575fa65c7933f0a Mon Sep 17 00:00:00 2001 From: onesh Date: Fri, 26 Apr 2024 10:17:02 +0700 Subject: [PATCH 6/7] Fix: default value date field system config --- etc/adminhtml/system.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/etc/adminhtml/system.xml b/etc/adminhtml/system.xml index efc57df..0ed2566 100755 --- a/etc/adminhtml/system.xml +++ b/etc/adminhtml/system.xml @@ -78,7 +78,7 @@ Mageplaza\Seo\Model\Config\Source\PriceValidUntil - + 1 From efd5d440f2f9b879a7c6081d1ef4220e856244ca Mon Sep 17 00:00:00 2001 From: chuccv Date: Sat, 4 May 2024 13:39:03 +0700 Subject: [PATCH 7/7] Release: v4.4.0 --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 02864c7..57f128d 100644 --- a/composer.json +++ b/composer.json @@ -5,7 +5,7 @@ "mageplaza/module-core": "^1.5.6" }, "type": "magento2-module", - "version": "4.3.1", + "version": "4.4.0", "license": "proprietary", "keywords": [ "magento 2",