From db32c251d29c0b0cd5646255e493f40bdb6603eb Mon Sep 17 00:00:00 2001 From: onesh Date: Mon, 2 Oct 2023 16:01:04 +0700 Subject: [PATCH 1/6] Update: social profiles structure --- Model/Config/Backend/ValidUrl.php | 49 ++++++++++++ Plugin/SeoRender.php | 122 +++++++++++++++--------------- etc/adminhtml/system.xml | 35 +++------ 3 files changed, 121 insertions(+), 85 deletions(-) create mode 100644 Model/Config/Backend/ValidUrl.php diff --git a/Model/Config/Backend/ValidUrl.php b/Model/Config/Backend/ValidUrl.php new file mode 100644 index 0000000..cb6f833 --- /dev/null +++ b/Model/Config/Backend/ValidUrl.php @@ -0,0 +1,49 @@ +getValue())) { + $valueArray = explode(',', $this->getValue()); + foreach ($valueArray as $value) { + if (!filter_var($value, FILTER_VALIDATE_URL)) { + throw new ValidatorException(__('Invalid url format.')); + } + } + } + parent::beforeSave(); + } +} diff --git a/Plugin/SeoRender.php b/Plugin/SeoRender.php index 90413b0..e575443 100755 --- a/Plugin/SeoRender.php +++ b/Plugin/SeoRender.php @@ -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 @@ -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 @@ -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; @@ -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() ); @@ -410,7 +410,7 @@ public function showProductStructuredData() } - $stockItem = (int)$stockQty; + $stockItem = (int) $stockQty; } $priceValidUntil = $currentProduct->getSpecialToDate(); @@ -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 = [ @@ -588,7 +588,7 @@ public function getProduct() * Get Url * * @param string $route - * @param array $params + * @param array $params * * @return string */ @@ -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 @@ -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 @@ -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[] = [ @@ -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 @@ -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', @@ -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 */ @@ -771,6 +771,7 @@ public function getDownloadableProductStructuredData($currentProduct, $productSt * * @param $currentProduct * @param $productStructuredData + * * @return array * @throws NoSuchEntityException */ @@ -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; @@ -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() @@ -980,6 +981,7 @@ protected function getBussinessImageUrlConfig() $this->helperData->getInfoConfig('image_url') )); } + return []; } @@ -995,20 +997,20 @@ 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 ($customLink = $this->helperData->getSocialProfiles('custom_link')) { + $customLink = explode(',', $customLink); + $lines = array_merge($lines, $customLink); + } return $lines; } diff --git a/etc/adminhtml/system.xml b/etc/adminhtml/system.xml index 1ba4ff9..40330af 100755 --- a/etc/adminhtml/system.xml +++ b/etc/adminhtml/system.xml @@ -270,45 +270,30 @@ validate-url Learn more]]> - - - validate-url - Learn more]]> - - + validate-url Learn more]]> - + validate-url Learn more]]> - - - validate-url - Learn more]]> - - - + + validate-url Learn more]]> - - - validate-url - Learn more]]> - - - + + validate-url Learn more]]> - - - validate-url - Learn more]]> + + + Mageplaza\Seo\Model\Config\Backend\ValidUrl + - One link per line.
Example: https://www.pinterest.com/,thttps://www.amazon.com/]]>
From d9fedaef6971f8fe43dc932e69233ae40e0ac0c9 Mon Sep 17 00:00:00 2001 From: onesh Date: Mon, 23 Oct 2023 16:28:19 +0700 Subject: [PATCH 2/6] Fix: value config --- Model/Config/Backend/ValidUrl.php | 8 ++++++-- Plugin/SeoRender.php | 12 ++++++++++-- etc/adminhtml/system.xml | 5 ++++- 3 files changed, 20 insertions(+), 5 deletions(-) diff --git a/Model/Config/Backend/ValidUrl.php b/Model/Config/Backend/ValidUrl.php index cb6f833..b5e51b7 100644 --- a/Model/Config/Backend/ValidUrl.php +++ b/Model/Config/Backend/ValidUrl.php @@ -37,9 +37,13 @@ class ValidUrl extends Value public function beforeSave() { if (!empty($this->getValue())) { - $valueArray = explode(',', $this->getValue()); + $valueArray = array_map('trim', explode( + "\n", + $this->getValue() + ?? '')); foreach ($valueArray as $value) { - if (!filter_var($value, FILTER_VALIDATE_URL)) { + $value = explode(',', $value); + if (!filter_var($value[0], FILTER_VALIDATE_URL)) { throw new ValidatorException(__('Invalid url format.')); } } diff --git a/Plugin/SeoRender.php b/Plugin/SeoRender.php index e575443..3940835 100755 --- a/Plugin/SeoRender.php +++ b/Plugin/SeoRender.php @@ -1007,8 +1007,16 @@ public function getSocialProfiles() $lines[] = $profile; } } - if ($customLink = $this->helperData->getSocialProfiles('custom_link')) { - $customLink = explode(',', $customLink); + if ($this->helperData->getSocialProfiles('custom_link')) { + $customLink = []; + $valueArray = array_map('trim', explode( + "\n", + $this->helperData->getSocialProfiles('custom_link') + ?? '')); + foreach ($valueArray as $value) { + $value = explode(',', $value); + $customLink[] = $value[0]; + } $lines = array_merge($lines, $customLink); } diff --git a/etc/adminhtml/system.xml b/etc/adminhtml/system.xml index 40330af..2db7216 100755 --- a/etc/adminhtml/system.xml +++ b/etc/adminhtml/system.xml @@ -293,7 +293,10 @@ Mageplaza\Seo\Model\Config\Backend\ValidUrl - - One link per line.
Example: https://www.pinterest.com/,thttps://www.amazon.com/]]>
+ - One link per line. +
Example: +
https://www.pinterest.com/,Pinterest +
https://www.amazon.com/,Amazon"]]>
From a1b29eb627c8e377c5a4c6e6274a37d0f52689b3 Mon Sep 17 00:00:00 2001 From: onesh Date: Mon, 23 Oct 2023 16:38:11 +0700 Subject: [PATCH 3/6] Fix: label comment --- 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 2db7216..f10e76e 100755 --- a/etc/adminhtml/system.xml +++ b/etc/adminhtml/system.xml @@ -296,7 +296,7 @@ - One link per line.
Example:
https://www.pinterest.com/,Pinterest -
https://www.amazon.com/,Amazon"]]>
+
https://www.amazon.com/,Amazon]]>
From 200e95db1b21907d60eeaed755f81c9628778687 Mon Sep 17 00:00:00 2001 From: onesh Date: Tue, 24 Oct 2023 14:50:29 +0700 Subject: [PATCH 4/6] Fix: social custom link --- Model/Config/Backend/ValidUrl.php | 3 +-- Plugin/SeoRender.php | 7 +------ etc/adminhtml/system.xml | 4 ++-- 3 files changed, 4 insertions(+), 10 deletions(-) diff --git a/Model/Config/Backend/ValidUrl.php b/Model/Config/Backend/ValidUrl.php index b5e51b7..e19483a 100644 --- a/Model/Config/Backend/ValidUrl.php +++ b/Model/Config/Backend/ValidUrl.php @@ -42,8 +42,7 @@ public function beforeSave() $this->getValue() ?? '')); foreach ($valueArray as $value) { - $value = explode(',', $value); - if (!filter_var($value[0], FILTER_VALIDATE_URL)) { + if (!filter_var($value, FILTER_VALIDATE_URL)) { throw new ValidatorException(__('Invalid url format.')); } } diff --git a/Plugin/SeoRender.php b/Plugin/SeoRender.php index 3940835..09ed8fe 100755 --- a/Plugin/SeoRender.php +++ b/Plugin/SeoRender.php @@ -1008,16 +1008,11 @@ public function getSocialProfiles() } } if ($this->helperData->getSocialProfiles('custom_link')) { - $customLink = []; $valueArray = array_map('trim', explode( "\n", $this->helperData->getSocialProfiles('custom_link') ?? '')); - foreach ($valueArray as $value) { - $value = explode(',', $value); - $customLink[] = $value[0]; - } - $lines = array_merge($lines, $customLink); + $lines = array_merge($lines, $valueArray); } return $lines; diff --git a/etc/adminhtml/system.xml b/etc/adminhtml/system.xml index f10e76e..c0b2d66 100755 --- a/etc/adminhtml/system.xml +++ b/etc/adminhtml/system.xml @@ -295,8 +295,8 @@ Mageplaza\Seo\Model\Config\Backend\ValidUrl - One link per line.
Example: -
https://www.pinterest.com/,Pinterest -
https://www.amazon.com/,Amazon]]>
+
https://www.pinterest.com/ +
https://www.amazon.com/]]>
From fa4a99a18cb1d432e30be2652c650af79eef971e Mon Sep 17 00:00:00 2001 From: onesh Date: Wed, 29 Nov 2023 08:48:25 +0700 Subject: [PATCH 5/6] Update: i18n --- i18n/en_US.csv | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/i18n/en_US.csv b/i18n/en_US.csv index f08059d..45d4d47 100644 --- a/i18n/en_US.csv +++ b/i18n/en_US.csv @@ -89,16 +89,14 @@ Description,Description "Social Profiles","Social Profiles" Facebook,Facebook Twitter,Twitter -Google+,Google+ Instagram,Instagram YouTube,YouTube +Tiktok,Tiktok LinkedIn,LinkedIn -Myspace,Myspace -Pinterest,Pinterest -SoundCloud,SoundCloud -Tumblr,Tumblr +"Custom Social Profile Links","Custom Social Profile Links" Verifications,Verifications "Google Search Console","Google Search Console" "Enter verification code, it will be added into tag","Enter verification code, it will be added into tag" "Bing Webmaster Tools","Bing Webmaster Tools" +Pinterest,Pinterest "Yandex Webmaster Tools","Yandex Webmaster Tools" From 83a34076c562735981577fc882afc1c6ad4fd656 Mon Sep 17 00:00:00 2001 From: onesh Date: Wed, 29 Nov 2023 08:48:39 +0700 Subject: [PATCH 6/6] Update: composer --- composer.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/composer.json b/composer.json index 5716a80..c41002c 100644 --- a/composer.json +++ b/composer.json @@ -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",