Skip to content

Commit

Permalink
Merge pull request #128 from mageplaza/2.3-develop
Browse files Browse the repository at this point in the history
2.3 develop
  • Loading branch information
haitv282 authored Jun 24, 2022
2 parents 42c001e + 4a5ebef commit c4f139f
Show file tree
Hide file tree
Showing 8 changed files with 357 additions and 32 deletions.
49 changes: 49 additions & 0 deletions Model/Config/Backend/BusinessImage.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
<?php

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'],
];
}
}
100 changes: 78 additions & 22 deletions Plugin/SeoRender.php
Original file line number Diff line number Diff line change
Expand Up @@ -293,9 +293,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 @@ -309,7 +310,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 @@ -553,13 +555,12 @@ public function addProductStructuredDataByType($productType, $currentProduct, $p
return $productStructuredData;
}


/**
* add Grouped Product Structured Data
*
* @param Product $currentProduct
* @param array $productStructuredData
* @param $currentProduct
* @param $productStructuredData
*
* @return mixed
* @return array
* @throws NoSuchEntityException
*/
public function getGroupedProductStructuredData($currentProduct, $productStructuredData)
Expand Down Expand Up @@ -596,12 +597,12 @@ 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)
Expand Down Expand Up @@ -644,12 +645,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 @@ -678,7 +679,7 @@ public function getDownloadableProductStructuredData($currentProduct, $productSt
}

/**
* add Configurable Product Structured Data
* Add Configurable Product Structured Data
*
* @param $currentProduct
* @param $productStructuredData
Expand Down Expand Up @@ -771,13 +772,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 +787,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 +808,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 +821,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 +831,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": "2.2.9",
"version": "2.3.0",
"license": "proprietary",
"keywords": [
"magento 2",
Expand Down
Loading

0 comments on commit c4f139f

Please sign in to comment.