Skip to content

Commit

Permalink
2.4 develop (#143)
Browse files Browse the repository at this point in the history
  • Loading branch information
chuccv authored May 4, 2024
2 parents e172378 + efd5d44 commit 8a5c7c3
Show file tree
Hide file tree
Showing 10 changed files with 265 additions and 29 deletions.
24 changes: 24 additions & 0 deletions Helper/Data.php
Original file line number Diff line number Diff line change
Expand Up @@ -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]);
}
}
43 changes: 43 additions & 0 deletions Model/Config/Source/CanonicalFor.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<?php
/**
* 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
*/

namespace Mageplaza\Seo\Model\Config\Source;

use Magento\Framework\Option\ArrayInterface;

/**
* Class CanonicalFor
* @package Mageplaza\Seo\Model\Config\Source
*/
class CanonicalFor implements ArrayInterface
{
/**
* @return array
*/
public function toOptionArray()
{
return [
['label' => __('--Please select--'), 'value' => '0'],
['label' => __('Category'), 'value' => '1'],
['label' => __('Product'), 'value' => '2']
];
}
}
20 changes: 16 additions & 4 deletions Plugin/Helper/CanUseCanonicalTagForCategories.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -30,6 +31,13 @@
*/
class CanUseCanonicalTagForCategories
{
/**
* Store manager
*
* @var StoreManagerInterface
*/
protected $_storeManager;

/**
* @var HelperData
*/
Expand All @@ -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;
}

/**
Expand All @@ -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;
Expand Down
22 changes: 17 additions & 5 deletions Plugin/Helper/CanUseCanonicalTagForProducts.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

/**
Expand All @@ -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;
}

/**
Expand All @@ -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;
Expand Down
16 changes: 15 additions & 1 deletion Plugin/SeoRender.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}
}

Expand Down Expand Up @@ -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
*
Expand Down
109 changes: 109 additions & 0 deletions Setup/Patch/Data/UpdateDateTimeValue.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
<?php
/**
* 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_StoreLocator
* @copyright Copyright (c) Mageplaza (https://www.mageplaza.com/)
* @license https://www.mageplaza.com/LICENSE.txt
*/

namespace Mageplaza\Seo\Setup\Patch\Data;

use Magento\Framework\Setup\ModuleDataSetupInterface;
use Magento\Framework\Setup\Patch\DataPatchInterface;
use Magento\Framework\Setup\Patch\PatchRevertableInterface;
use Mageplaza\Core\Helper\AbstractData as CoreHelper;
use Mageplaza\Seo\Helper\Data;

/**
* Class UpdateDateTimeValue
* @package Mageplaza\Seo\Setup\Patch\Data
*/
class UpdateDateTimeValue implements DataPatchInterface, PatchRevertableInterface
{
/**
* @var ModuleDataSetupInterface $moduleDataSetup
*/
private $moduleDataSetup;

/**
* @var CoreHelper
*/
private $_helperData;

/**
* InstallAttributeData constructor.
*
* @param ModuleDataSetupInterface $moduleDataSetup
* @param Data $helperData
*/
public function __construct(
ModuleDataSetupInterface $moduleDataSetup,
Data $helperData
) {
$this->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 [];
}
}
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
Loading

0 comments on commit 8a5c7c3

Please sign in to comment.