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/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 * 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 []; + } +} 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", diff --git a/etc/adminhtml/system.xml b/etc/adminhtml/system.xml index c0b2d66..0ed2566 100755 --- a/etc/adminhtml/system.xml +++ b/etc/adminhtml/system.xml @@ -42,32 +42,28 @@ ]]> - + 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. - + Magento\Config\Model\Config\Source\Yesno Learn more ]]> - + Mageplaza\Seo\Model\Config\Source\Attribute @@ -75,7 +71,7 @@ required-entry - + 1 @@ -91,7 +87,7 @@ Mageplaza\Seo\Block\Adminhtml\System\Config\Date required-entry - + 1 @@ -99,7 +95,7 @@ Mageplaza\Seo\Model\Config\Source\ModelField here ]]> - + 1 @@ -108,7 +104,7 @@ required-entry Recommend field: sku, barcode - + Magento\Config\Model\Config\Source\Yesno here ]]> @@ -116,7 +112,7 @@ - + Magento\Config\Model\Config\Source\Yesno here ]]> @@ -127,7 +123,7 @@ 1 - + Mageplaza\Seo\Model\Config\Source\BusinessType 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; +}