Skip to content

Commit

Permalink
2.4 develop (#140)
Browse files Browse the repository at this point in the history
  • Loading branch information
chuccv authored Nov 29, 2023
2 parents 3ab679b + 83a3407 commit ecc59a8
Show file tree
Hide file tree
Showing 5 changed files with 135 additions and 92 deletions.
52 changes: 52 additions & 0 deletions Model/Config/Backend/ValidUrl.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
<?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_Webhook
* @copyright Copyright (c) Mageplaza (https://www.mageplaza.com/)
* @license https://www.mageplaza.com/LICENSE.txt
*/

namespace Mageplaza\Seo\Model\Config\Backend;

use Magento\Framework\App\Config\Value;
use Magento\Framework\Exception\ValidatorException;

/**
* Class ValidUrl
* @package Mageplaza\Seo\Model\Config\Backend
*/
class ValidUrl extends Value
{
/**
* @return Value|void
* @throws ValidatorException
*/
public function beforeSave()
{
if (!empty($this->getValue())) {
$valueArray = array_map('trim', explode(
"\n",
$this->getValue()
?? ''));
foreach ($valueArray as $value) {
if (!filter_var($value, FILTER_VALIDATE_URL)) {
throw new ValidatorException(__('Invalid url format.'));
}
}
}
parent::beforeSave();
}
}
125 changes: 65 additions & 60 deletions Plugin/SeoRender.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,9 @@
class SeoRender
{
const GOOLE_SITE_VERIFICATION = 'google-site-verification';
const MSVALIDATE_01 = 'msvalidate.01';
const P_DOMAIN_VERIFY = 'p:domain_verify';
const YANDEX_VERIFICATION = 'yandex-verification';
const MSVALIDATE_01 = 'msvalidate.01';
const P_DOMAIN_VERIFY = 'p:domain_verify';
const YANDEX_VERIFICATION = 'yandex-verification';

/**
* @var PageConfig
Expand Down Expand Up @@ -177,17 +177,17 @@ class SeoRender
/**
* @var SourceItems
*/
protected $sourceItemsBySku;
protected $sourceItemsBySku;

/**
* @var AssignedStock
*/
protected $assignedStock;
protected $assignedStock;

/**
* @var SalableQuantity
*/
protected $salableQuantity;
protected $salableQuantity;

/**
* @var ImageHelper
Expand Down Expand Up @@ -224,31 +224,31 @@ class SeoRender
* @param ImageHelper $imageHelper
*/
public function __construct(
PageConfig $pageConfig,
Http $request,
HelperData $helpData,
StockItemRepository $stockItemRepository,
Registry $registry,
ReviewFactory $reviewFactory,
StoreManagerInterface $storeManager,
UrlInterface $urlBuilder,
ProductFactory $productFactory,
ManagerInterface $messageManager,
PageConfig $pageConfig,
Http $request,
HelperData $helpData,
StockItemRepository $stockItemRepository,
Registry $registry,
ReviewFactory $reviewFactory,
StoreManagerInterface $storeManager,
UrlInterface $urlBuilder,
ProductFactory $productFactory,
ManagerInterface $messageManager,
StockRegistryInterface $stockState,
SearchHelper $searchHelper,
PriceHelper $priceHelper,
Manager $eventManager,
DateTime $dateTime,
TimezoneInterface $timeZoneInterface,
ReviewCollection $reviewCollection,
ModuleManager $moduleManager,
RatingFactory $ratingFactory,
ReviewResourceModel $reviewResourceModel,
CollectionFactory $collectionFactory,
SourceItems $sourceItemsBySku,
AssignedStock $assignedStock,
SalableQuantity $salableQuantity,
ImageHelper $imageHelper
SearchHelper $searchHelper,
PriceHelper $priceHelper,
Manager $eventManager,
DateTime $dateTime,
TimezoneInterface $timeZoneInterface,
ReviewCollection $reviewCollection,
ModuleManager $moduleManager,
RatingFactory $ratingFactory,
ReviewResourceModel $reviewResourceModel,
CollectionFactory $collectionFactory,
SourceItems $sourceItemsBySku,
AssignedStock $assignedStock,
SalableQuantity $salableQuantity,
ImageHelper $imageHelper
) {
$this->pageConfig = $pageConfig;
$this->request = $request;
Expand Down Expand Up @@ -377,9 +377,9 @@ public function showProductStructuredData()
->getColumnValues('attribute_code');
$productId = $currentProduct->getId() ?: $this->request->getParam('id');

$product = $this->productFactory->create()->load($productId);
$availability = $product->isAvailable() ? 'InStock' : 'OutOfStock';
$stockItem = $this->stockState->getStockItem(
$product = $this->productFactory->create()->load($productId);
$availability = $product->isAvailable() ? 'InStock' : 'OutOfStock';
$stockItem = $this->stockState->getStockItem(
$product->getId(),
$product->getStore()->getWebsiteId()
);
Expand Down Expand Up @@ -410,7 +410,7 @@ public function showProductStructuredData()

}

$stockItem = (int)$stockQty;
$stockItem = (int) $stockQty;
}

$priceValidUntil = $currentProduct->getSpecialToDate();
Expand All @@ -430,10 +430,10 @@ public function showProductStructuredData()
}
$modelName = $this->helperData->getRichsnippetsConfig('model_name');

if($currentProduct->getImage()) {
if ($currentProduct->getImage()) {
$imageUrl = $this->getUrl('pub/media/catalog') . 'product' . $currentProduct->getImage();
}else {
$imageUrl = $this->imageHelper->init($currentProduct,'product_base_image')->getUrl();
} else {
$imageUrl = $this->imageHelper->init($currentProduct, 'product_base_image')->getUrl();
}

$productStructuredData = [
Expand Down Expand Up @@ -588,7 +588,7 @@ public function getProduct()
* Get Url
*
* @param string $route
* @param array $params
* @param array $params
*
* @return string
*/
Expand All @@ -598,9 +598,9 @@ public function getUrl($route = '', $params = [])
}

/**
* @param string $productType
* @param string $productType
* @param Product $currentProduct
* @param array $productStructuredData
* @param array $productStructuredData
*
* @return mixed
* @throws NoSuchEntityException
Expand Down Expand Up @@ -638,7 +638,7 @@ public function addProductStructuredDataByType($productType, $currentProduct, $p
* Add Grouped Product Structured Data
*
* @param Product $currentProduct
* @param array $productStructuredData
* @param array $productStructuredData
*
* @return array
* @throws NoSuchEntityException
Expand All @@ -652,11 +652,11 @@ public function getGroupedProductStructuredData($currentProduct, $productStructu
$childProductCollection = $typeInstance->getAssociatedProducts($currentProduct);
foreach ($childProductCollection as $child) {

if($child->getImage()) {
if ($child->getImage()) {
$imageUrl = $this->_storeManager->getStore()->getBaseUrl(UrlInterface::URL_TYPE_MEDIA)
. 'catalog/product' . $child->getImage();
}else {
$imageUrl = $this->imageHelper->init($child,'product_base_image')->getUrl();
} else {
$imageUrl = $this->imageHelper->init($child, 'product_base_image')->getUrl();
}

$offerData[] = [
Expand Down Expand Up @@ -685,7 +685,7 @@ public function getGroupedProductStructuredData($currentProduct, $productStructu
* Add Bundle Product Structured Data
*
* @param Product $currentProduct
* @param array $productStructuredData
* @param array $productStructuredData
*
* @return array
* @throws NoSuchEntityException
Expand All @@ -710,11 +710,11 @@ public function getBundleProductStructuredData($currentProduct, $productStructur
$currentProduct
);
foreach ($childProductCollection as $child) {
if($child->getImage()) {
if ($child->getImage()) {
$imageUrl = $this->_storeManager->getStore()->getBaseUrl(UrlInterface::URL_TYPE_MEDIA)
. 'catalog/product' . $child->getImage();
}else {
$imageUrl = $this->imageHelper->init($child,'product_base_image')->getUrl();
} else {
$imageUrl = $this->imageHelper->init($child, 'product_base_image')->getUrl();
}
$offerData[] = [
'@type' => 'Offer',
Expand All @@ -736,7 +736,7 @@ public function getBundleProductStructuredData($currentProduct, $productStructur
* Add Downloadable Product Structured Data
*
* @param Product $currentProduct
* @param array $productStructuredData
* @param array $productStructuredData
*
* @return array
*/
Expand Down Expand Up @@ -771,6 +771,7 @@ public function getDownloadableProductStructuredData($currentProduct, $productSt
*
* @param $currentProduct
* @param $productStructuredData
*
* @return array
* @throws NoSuchEntityException
*/
Expand All @@ -784,11 +785,11 @@ public function getConfigurableProductStructuredData($currentProduct, $productSt
$allChildPrices = [];
foreach ($childProductCollection as $child) {

if($child->getImage()) {
$imageUrl = $this->_storeManager->getStore()->getBaseUrl(UrlInterface::URL_TYPE_MEDIA)
if ($child->getImage()) {
$imageUrl = $this->_storeManager->getStore()->getBaseUrl(UrlInterface::URL_TYPE_MEDIA)
. 'catalog/product' . $child->getImage();
}else {
$imageUrl = $this->imageHelper->init($child,'product_base_image')->getUrl();
} else {
$imageUrl = $this->imageHelper->init($child, 'product_base_image')->getUrl();
}
$childPrice = $this->_priceHelper->currency($child->getPrice(), false);
$allChildPrices[] = $childPrice;
Expand Down Expand Up @@ -828,7 +829,7 @@ public function getReviewCount()
/** @var Rating $ratingSummary */
foreach ($ratingSummaries as $ratingSummary) {
if ($ratingSummary->getStoreId() === $this->_storeManager->getStore()->getId()) {
return (int)$this->reviewResourceModel->getTotalReviews(
return (int) $this->reviewResourceModel->getTotalReviews(
$this->getProduct()->getId(),
true,
$ratingSummary->getStoreId()
Expand Down Expand Up @@ -980,6 +981,7 @@ protected function getBussinessImageUrlConfig()
$this->helperData->getInfoConfig('image_url')
));
}

return [];
}

Expand All @@ -995,20 +997,23 @@ public function getSocialProfiles()
$socialNetwork = [
'facebook',
'twitter',
'google',
'instagram',
'youtube',
'linkedin',
'myspace',
'pinterest',
'soundcloud',
'tumblr'
'tiktok',
'linkedin'
];
foreach ($socialNetwork as $value) {
if ($profile = $this->helperData->getSocialProfiles($value)) {
$lines[] = $profile;
}
}
if ($this->helperData->getSocialProfiles('custom_link')) {
$valueArray = array_map('trim', explode(
"\n",
$this->helperData->getSocialProfiles('custom_link')
?? ''));
$lines = array_merge($lines, $valueArray);
}

return $lines;
}
Expand Down
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
"name": "mageplaza/magento-2-seo-extension",
"description": "Magento 2 SEO extension",
"require": {
"mageplaza/module-core": "^1.5.3"
"mageplaza/module-core": "^1.5.5"
},
"type": "magento2-module",
"version": "4.2.3",
"version": "4.3.0",
"license": "proprietary",
"keywords": [
"magento 2",
Expand Down
38 changes: 13 additions & 25 deletions etc/adminhtml/system.xml
Original file line number Diff line number Diff line change
Expand Up @@ -270,45 +270,33 @@
<validate>validate-url</validate>
<comment><![CDATA[Google will only show verified profiles. <a href="https://developers.google.com/search/docs/data-types/social-profile-links">Learn more</a>]]></comment>
</field>
<field id="google" translate="label" type="text" sortOrder="30" showInDefault="1" showInWebsite="1" showInStore="1">
<label>Google+</label>
<validate>validate-url</validate>
<comment><![CDATA[Google will only show verified profiles. <a href="https://developers.google.com/search/docs/data-types/social-profile-links">Learn more</a>]]></comment>
</field>
<field id="instagram" translate="label" type="text" sortOrder="40" showInDefault="1" showInWebsite="1" showInStore="1">
<field id="instagram" translate="label" type="text" sortOrder="30" showInDefault="1" showInWebsite="1" showInStore="1">
<label>Instagram</label>
<validate>validate-url</validate>
<comment><![CDATA[Google will only show verified profiles. <a href="https://developers.google.com/search/docs/data-types/social-profile-links">Learn more</a>]]></comment>
</field>
<field id="youtube" translate="label" type="text" sortOrder="50" showInDefault="1" showInWebsite="1" showInStore="1">
<field id="youtube" translate="label" type="text" sortOrder="40" showInDefault="1" showInWebsite="1" showInStore="1">
<label>YouTube</label>
<validate>validate-url</validate>
<comment><![CDATA[Google will only show verified profiles. <a href="https://developers.google.com/search/docs/data-types/social-profile-links">Learn more</a>]]></comment>
</field>
<field id="linkedin" translate="label" type="text" sortOrder="60" showInDefault="1" showInWebsite="1" showInStore="1">
<label>LinkedIn</label>
<validate>validate-url</validate>
<comment><![CDATA[Google will only show verified profiles. <a href="https://developers.google.com/search/docs/data-types/social-profile-links">Learn more</a>]]></comment>
</field>
<field id="myspace" translate="label" type="text" sortOrder="70" showInDefault="1" showInWebsite="1" showInStore="1">
<label>Myspace</label>
<field id="tiktok" translate="label" type="text" sortOrder="50" showInDefault="1" showInWebsite="1" showInStore="1">
<label>Tiktok</label>
<validate>validate-url</validate>
<comment><![CDATA[Google will only show verified profiles. <a href="https://developers.google.com/search/docs/data-types/social-profile-links">Learn more</a>]]></comment>
</field>
<field id="pinterest" translate="label" type="text" sortOrder="80" showInDefault="1" showInWebsite="1" showInStore="1">
<label>Pinterest</label>
<validate>validate-url</validate>
<comment><![CDATA[Google will only show verified profiles. <a href="https://developers.google.com/search/docs/data-types/social-profile-links">Learn more</a>]]></comment>
</field>
<field id="soundcloud" translate="label" type="text" sortOrder="90" showInDefault="1" showInWebsite="1" showInStore="1">
<label>SoundCloud</label>
<field id="linkedin" translate="label" type="text" sortOrder="60" showInDefault="1" showInWebsite="1" showInStore="1">
<label>LinkedIn</label>
<validate>validate-url</validate>
<comment><![CDATA[Google will only show verified profiles. <a href="https://developers.google.com/search/docs/data-types/social-profile-links">Learn more</a>]]></comment>
</field>
<field id="tumblr" translate="label" type="text" sortOrder="100" showInDefault="1" showInWebsite="1" showInStore="1">
<label>Tumblr</label>
<validate>validate-url</validate>
<comment><![CDATA[Google will only show verified profiles. <a href="https://developers.google.com/search/docs/data-types/social-profile-links">Learn more</a>]]></comment>
<field id="custom_link" translate="label" type="textarea" sortOrder="70" showInDefault="1" showInWebsite="1" showInStore="1">
<label>Custom Social Profile Links</label>
<backend_model>Mageplaza\Seo\Model\Config\Backend\ValidUrl</backend_model>
<comment><![CDATA[- List of Social Profile Links separated by commas to add to Social Profile.<br>- One link per line.
<br>Example:
<br>https://www.pinterest.com/
<br>https://www.amazon.com/]]></comment>
</field>
</group>
<group id="verification" translate="label comment" type="text" sortOrder="40" showInDefault="1" showInWebsite="1" showInStore="1">
Expand Down
Loading

0 comments on commit ecc59a8

Please sign in to comment.