Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

2.4 develop #127

Merged
merged 19 commits into from
Jun 24, 2022
Merged
68 changes: 68 additions & 0 deletions Model/Config/Backend/BusinessImage.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
<?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://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 http://mageplaza.com/LICENSE.txt
*/

namespace Mageplaza\Seo\Model\Config\Backend;

use Magento\Config\Model\Config\Backend\Image;

/**
* Class BusinessImage
* @package Mageplaza\Seo\Model\Config\Source
*/
class BusinessImage extends Image
{
/**
* The tail part of directory path for uploading
*
*/
const UPLOAD_DIR = 'mageplaza/seo'; // Folder save image

/**
* Return path to directory for upload file
*
* @return string
* @throw \Magento\Framework\Exception\LocalizedException
*/
protected function _getUploadDir()
{
return $this->_mediaDirectory->getAbsolutePath($this->_appendScopeInfo(self::UPLOAD_DIR));
}

/**
* Makes a decision about whether to add info about the scope.
*
* @return boolean
*/
protected function _addWhetherScopeInfo()
{
return true;
}

/**
* Getter for allowed extensions of uploaded files.
*
* @return string[]
*/
protected function _getAllowedExtensions()
{
return ['jpg', 'jpeg', 'png', 'svg'];
}
}
72 changes: 72 additions & 0 deletions Model/Config/Source/BusinessType.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
<?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 BusinessType
* @package Mageplaza\Seo\Model\Config\Source
*/
class BusinessType implements ArrayInterface
{
/**
* @return array
*/
public function toOptionArray()
{
return [
['label' => __('Store'), 'value' => 'Store'],
['label' => __('Local Business'), 'value' => 'LocalBusiness'],
['label' => __('Auto Parts Store'), 'value' => 'AutoPartsStore'],
['label' => __('Bike Store'), 'value' => 'BikeStore'],
['label' => __('Book Store'), 'value' => 'BookStore'],
['label' => __('Clothing Store'), 'value' => 'ClothingStore'],
['label' => __('Computer Store'), 'value' => 'ComputerStore'],
['label' => __('Convenience Store'), 'value' => 'ConvenienceStore'],
['label' => __('Department Store'), 'value' => 'DepartmentStore'],
['label' => __('Electronics Store'), 'value' => 'ElectronicsStore'],
['label' => __('Florist Store'), 'value' => 'Florist'],
['label' => __('Furniture Store'), 'value' => 'FurnitureStore'],
['label' => __('Garden Store'), 'value' => 'GardenStore'],
['label' => __('Grocery Store'), 'value' => 'GroceryStore'],
['label' => __('Hardware Store'), 'value' => 'HardwareStore'],
['label' => __('Hobby Shop'), 'value' => 'HobbyShop'],
['label' => __('Home Goods Store'), 'value' => 'HomeGoodsStore'],
['label' => __('Jewelry Store'), 'value' => 'JewelryStore'],
['label' => __('Liquor Store'), 'value' => 'LiquorStore'],
['label' => __('Mens Clothing Store'), 'value' => 'MensClothingStore'],
['label' => __('Mobile Phone Store'), 'value' => 'MobilePhoneStore'],
['label' => __('Movie Rental Store'), 'value' => 'MovieRentalStore'],
['label' => __('Music Store'), 'value' => 'MusicStore'],
['label' => __('Office Equipment Store'), 'value' => 'OfficeEquipmentStore'],
['label' => __('Outlet Store'), 'value' => 'OutletStore'],
['label' => __('Pawn Shop'), 'value' => 'PawnShop'],
['label' => __('Pet Store'), 'value' => 'PetStore'],
['label' => __('Shoe Store'), 'value' => 'ShoeStore'],
['label' => __('Sporting Goods Store'), 'value' => 'SportingGoodsStore'],
['label' => __('Tire Shop'), 'value' => 'TireShop'],
['label' => __('Toy Store'), 'value' => 'ToyStore'],
['label' => __('Wholesale Store'), 'value' => 'WholesaleStore'],
];
}
}
103 changes: 80 additions & 23 deletions Plugin/SeoRender.php
Original file line number Diff line number Diff line change
Expand Up @@ -294,9 +294,10 @@ public function getFullActionName()

/**
* @param Renderer $subject
* @param string $result
* @param $result
*
* @return string
* @return mixed|string
* @throws NoSuchEntityException
*/
public function afterRenderHeadContent(Renderer $subject, $result)
{
Expand All @@ -310,7 +311,8 @@ public function afterRenderHeadContent(Renderer $subject, $result)
break;
case 'cms_index_index':
if ($this->helperData->getInfoConfig('enable')) {
$result .= $this->showBusinessStructuredData();
$result .= $this->showLogoStructureData();
$result .= $this->showLocalBussinessStructureData();
}
if ($this->helperData->getRichsnippetsConfig('enable_site_link')) {
$result .= $this->showSiteLinksStructuredData();
Expand Down Expand Up @@ -365,7 +367,7 @@ public function showProductStructuredData()
'@context' => 'http://schema.org/',
'@type' => 'Product',
'name' => $currentProduct->getName(),
'description' => trim(strip_tags($currentProduct->getDescription())),
'description' => $currentProduct->getDescription() ? trim(strip_tags($currentProduct->getDescription())) : '',
'sku' => $currentProduct->getSku(),
'url' => $currentProduct->getProductUrl(),
'image' => $this->getUrl('pub/media/catalog') . 'product' . $currentProduct->getImage(),
Expand Down Expand Up @@ -555,12 +557,12 @@ public function addProductStructuredDataByType($productType, $currentProduct, $p
}

/**
* add Grouped Product Structured Data
* Add Grouped Product Structured Data
*
* @param Product $currentProduct
* @param array $productStructuredData
*
* @return mixed
* @return array
* @throws NoSuchEntityException
*/
public function getGroupedProductStructuredData($currentProduct, $productStructuredData)
Expand All @@ -577,11 +579,11 @@ public function getGroupedProductStructuredData($currentProduct, $productStructu
$offerData[] = [
'@type' => 'Offer',
'name' => $child->getName(),
'price' => $this->_priceHelper->currency($child->getPrice(), false),
'price' => $this->_priceHelper->currency($child->getFinalPrice(), false),
'sku' => $child->getSku(),
'image' => $imageUrl
];
$childrenPrice[] = $this->_priceHelper->currency($child->getPrice(), false);
$childrenPrice[] = $this->_priceHelper->currency($child->getFinalPrice(), false);
}

$productStructuredData['offers']['highPrice'] = array_sum($childrenPrice);
Expand All @@ -597,21 +599,21 @@ public function getGroupedProductStructuredData($currentProduct, $productStructu
}

/**
* add Bundle Product Structured Data
* Add Bundle Product Structured Data
*
* @param Product $currentProduct
* @param array $productStructuredData
*
* @return mixed
* @return array
* @throws NoSuchEntityException
*/
public function getBundleProductStructuredData($currentProduct, $productStructuredData)
{
$productStructuredData['offers']['@type'] = 'AggregateOffer';
try {
$productStructuredData['offers']['highPrice'] = $currentProduct->getPriceInfo()->getPrice('regular_price')
$productStructuredData['offers']['highPrice'] = $currentProduct->getPriceInfo()->getPrice('final_price')
->getMaximalPrice()->getValue();
$productStructuredData['offers']['lowPrice'] = $currentProduct->getPriceInfo()->getPrice('regular_price')
$productStructuredData['offers']['lowPrice'] = $currentProduct->getPriceInfo()->getPrice('final_price')
->getMinimalPrice()->getValue();
} catch (Exception $exception) {
$productStructuredData['offers']['highPrice'] = 0;
Expand Down Expand Up @@ -645,12 +647,12 @@ public function getBundleProductStructuredData($currentProduct, $productStructur
}

/**
* add Downloadable Product Structured Data
* Add Downloadable Product Structured Data
*
* @param Product $currentProduct
* @param array $productStructuredData
*
* @return mixed
* @return array
*/
public function getDownloadableProductStructuredData($currentProduct, $productStructuredData)
{
Expand Down Expand Up @@ -771,13 +773,13 @@ public function getRatingSummary()
}

/**
* get Business Structured Data
* Get Logo Structured Data
*
* @return string
*/
public function showBusinessStructuredData()
public function showLogoStructureData()
{
$businessStructuredData = [
$logoStructureData = [
'@context' => 'http://schema.org/',
'@type' => 'Organization',
'url' => $this->getUrl(),
Expand All @@ -786,15 +788,15 @@ public function showBusinessStructuredData()
'contactPoint' => []
];
if (!empty($this->getSocialProfiles())) {
$businessStructuredData['sameAs'] = $this->getSocialProfiles();
$logoStructureData['sameAs'] = $this->getSocialProfiles();
}

// get customer service info
if ($this->helperData->getInfoConfig('customer_service_phone')
|| $this->helperData->getInfoConfig('customer_service_contact_option')
|| $this->helperData->getInfoConfig('customer_service_area_serve')
) {
$businessStructuredData['contactPoint'][] = [
$logoStructureData['contactPoint'][] = [
'@type' => 'ContactPoint',
'telephone' => $this->helperData->getInfoConfig('customer_service_phone'),
'contactType' => 'customer service',
Expand All @@ -807,7 +809,7 @@ public function showBusinessStructuredData()
|| $this->helperData->getInfoConfig('technical_support_contact_option')
|| $this->helperData->getInfoConfig('technical_support_area_serve')
) {
$businessStructuredData['contactPoint'][] = [
$logoStructureData['contactPoint'][] = [
'@type' => 'ContactPoint',
'telephone' => $this->helperData->getInfoConfig('technical_support_phone'),
'contactType' => 'technical support',
Expand All @@ -820,7 +822,7 @@ public function showBusinessStructuredData()
|| $this->helperData->getInfoConfig('sales_contact_option')
|| $this->helperData->getInfoConfig('sales_area_serve')
) {
$businessStructuredData['contactPoint'][] = [
$logoStructureData['contactPoint'][] = [
'@type' => 'ContactPoint',
'telephone' => $this->helperData->getInfoConfig('sales_phone'),
'contactType' => 'sales',
Expand All @@ -830,11 +832,66 @@ public function showBusinessStructuredData()
}

return $this->helperData->createStructuredData(
$businessStructuredData,
'<!-- Business Structured Data by Mageplaza SEO-->'
$logoStructureData,
'<!-- Logo Structured Data by Mageplaza SEO-->'
);
}

/**
* Get Local Bussiness Structure data.
*
* @return string
* @throws NoSuchEntityException
*/
public function showLocalBussinessStructureData()
{
$localBussinessStructureData = [
'@context' => 'http://schema.org/',
'@type' => $this->helperData->getInfoConfig('business_type'),
'name' => $this->helperData->getInfoConfig('business_name'),
'address' => [
'@type' => 'PostalAddress',
'streetAddress' => $this->helperData->getInfoConfig('street_address'),
'addressLocality' => $this->helperData->getInfoConfig('city'),
'addressRegion' => $this->helperData->getInfoConfig('state_province'),
'addressCountry' => $this->helperData->getConfigValue('general/country/default'),
'postalCode' => $this->helperData->getInfoConfig('zip_code'),
'email' => $this->helperData->getInfoConfig('email'),
'faxNumber' => $this->helperData->getInfoConfig('fax')
],
'telephone' => $this->helperData->getInfoConfig('customer_service_phone'),
'priceRange' => $this->helperData->getInfoConfig('price_range'),
'description' => $this->helperData->getInfoConfig('description')
];

$bussinessImages = $this->getBussinessImageUrlConfig();
if ($this->helperData->getInfoConfig('image')) {
$image = $this->_storeManager->getStore()->getBaseUrl(UrlInterface::URL_TYPE_MEDIA)
. 'mageplaza/seo/' . $this->helperData->getInfoConfig('image');
$bussinessImages[] = $image;
}
$localBussinessStructureData['image'] = $bussinessImages;

return $this->helperData->createStructuredData(
$localBussinessStructureData,
'<!-- Local Bussiness Structured Data by Mageplaza SEO-->'
);
}

/**
* @return array
*/
protected function getBussinessImageUrlConfig()
{
if ($this->helperData->getInfoConfig('image_url')) {
return array_map('trim', explode(
"\n",
$this->helperData->getInfoConfig('image_url')
));
}
return [];
}

/**
* get Social Profiles config
*
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.4.5"
"mageplaza/module-core": "^1.4.12"
},
"type": "magento2-module",
"version": "4.1.5",
"version": "4.2.0",
"license": "proprietary",
"keywords": [
"magento 2",
Expand Down
Loading