-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 64d25ad
Showing
13 changed files
with
911 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
<?php | ||
/** | ||
* Copyright © MageWorx. All rights reserved. | ||
* See LICENSE.txt for license details. | ||
*/ | ||
|
||
namespace MageWorx\SeoXTemplatesGraphQl\Plugin; | ||
|
||
use GraphQL\Language\AST\FieldNode; | ||
use Magento\Eav\Model\Entity\Collection\AbstractCollection; | ||
use Magento\CatalogGraphQl\Model\AttributesJoiner; | ||
|
||
class AddSeoNameToCategoryCollectionPlugin | ||
{ | ||
/** | ||
* @var \MageWorx\SeoXTemplates\Helper\Data | ||
*/ | ||
protected $helperData; | ||
|
||
/** | ||
* AddSeoNameToCategoryCollectionPlugin constructor. | ||
* | ||
* @param \MageWorx\SeoXTemplates\Helper\Data $helperData | ||
*/ | ||
public function __construct( | ||
\MageWorx\SeoXTemplates\Helper\Data $helperData | ||
) { | ||
$this->helperData = $helperData; | ||
} | ||
|
||
/** | ||
* Adds "category_seo_name" attribute to category collection if needed | ||
* | ||
* @param AttributesJoiner $subject | ||
* @param $result | ||
* @param FieldNode $fieldNode | ||
* @param AbstractCollection $collection | ||
*/ | ||
public function afterJoin( | ||
AttributesJoiner $subject, | ||
$result, | ||
FieldNode $fieldNode, | ||
AbstractCollection $collection | ||
): void { | ||
if ($collection instanceof \Magento\Catalog\Model\ResourceModel\Category\Collection) { | ||
if ($this->helperData->isUseCategorySeoName()) { | ||
if ($collection->isAttributeAdded('name')) { | ||
$collection->addAttributeToSelect('category_seo_name'); | ||
} | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
<?php | ||
/** | ||
* Copyright © MageWorx. All rights reserved. | ||
* See LICENSE.txt for license details. | ||
*/ | ||
|
||
namespace MageWorx\SeoXTemplatesGraphQl\Plugin; | ||
|
||
use Magento\CatalogGraphQl\Model\Resolver\Products\DataProvider\Product\CollectionProcessorInterface; | ||
use Magento\Catalog\Model\ResourceModel\Product\Collection; | ||
use Magento\Framework\Api\SearchCriteriaInterface; | ||
|
||
class AddSeoNameToProductCollectionPlugin | ||
{ | ||
/** | ||
* @var \MageWorx\SeoXTemplates\Helper\Data | ||
*/ | ||
protected $helperData; | ||
|
||
/** | ||
* AddSeoNameToProductCollectionPlugin constructor. | ||
* | ||
* @param \MageWorx\SeoXTemplates\Helper\Data $helperData | ||
*/ | ||
public function __construct( | ||
\MageWorx\SeoXTemplates\Helper\Data $helperData | ||
) { | ||
$this->helperData = $helperData; | ||
} | ||
|
||
/** | ||
* @param CollectionProcessorInterface $subject | ||
* @param Collection $result | ||
* @param Collection $collection | ||
* @param SearchCriteriaInterface $searchCriteria | ||
* @param array $attributeNames | ||
* @return Collection | ||
*/ | ||
public function afterProcess( | ||
CollectionProcessorInterface $subject, | ||
Collection $result, | ||
Collection $collection, | ||
SearchCriteriaInterface $searchCriteria, | ||
array $attributeNames | ||
) { | ||
if ($this->helperData->isUseProductSeoName()) { | ||
if ($result->isAttributeAdded('name')) { | ||
$result->addAttributeToSelect('product_seo_name'); | ||
} | ||
} | ||
|
||
return $result; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,114 @@ | ||
<?php | ||
/** | ||
* Copyright © MageWorx. All rights reserved. | ||
* See LICENSE.txt for license details. | ||
*/ | ||
|
||
namespace MageWorx\SeoXTemplatesGraphQl\Plugin; | ||
|
||
use Magento\Framework\GraphQl\Config\Element\Field; | ||
use Magento\Framework\GraphQl\Schema\Type\ResolveInfo; | ||
use MageWorx\SeoXTemplates\Model\DynamicRenderer\Category as Renderer; | ||
|
||
class ModifyCategoryDescriptionPlugin | ||
{ | ||
/** | ||
* Filter object | ||
* | ||
* @var \MageWorx\SeoXTemplates\Model\DynamicRenderer\Category | ||
*/ | ||
protected $dynamicRenderer; | ||
|
||
/** | ||
* @var \MageWorx\SeoXTemplates\Helper\Data | ||
*/ | ||
protected $helperData; | ||
|
||
/** | ||
* ModifyCategoryDescriptionPlugin constructor. | ||
* | ||
* @param \MageWorx\SeoXTemplates\Helper\Data $helperData | ||
* @param Renderer $renderer | ||
*/ | ||
public function __construct( | ||
\MageWorx\SeoXTemplates\Helper\Data $helperData, | ||
Renderer $renderer | ||
) { | ||
$this->helperData = $helperData; | ||
$this->dynamicRenderer = $renderer; | ||
} | ||
|
||
/** | ||
* @param \Magento\CatalogGraphQl\Model\Resolver\Category\CategoryHtmlAttribute $subject | ||
* @param string|null $result | ||
* @param Field $field | ||
* @param $context | ||
* @param ResolveInfo $info | ||
* @param array|null $value | ||
* @param array|null $args | ||
*/ | ||
public function afterResolve( | ||
$subject, | ||
$result, | ||
Field $field, | ||
$context, | ||
ResolveInfo $info, | ||
array $value = null, | ||
array $args = null | ||
) { | ||
if (!$result) { | ||
return $result; | ||
} | ||
|
||
/** @var \Magento\Catalog\Model\Category $category */ | ||
$category = $value['model']; | ||
$fieldName = $field->getName(); | ||
|
||
if ($this->out($category, $fieldName)) { | ||
return $result; | ||
} | ||
|
||
if (!$this->isCurrentEntity($category, $info)) { | ||
return $result; | ||
} | ||
|
||
if ($this->dynamicRenderer->modifyCategoryDescription($category)) { | ||
return $category->getData('description'); | ||
} | ||
|
||
return $result; | ||
} | ||
|
||
/** | ||
* @param \Magento\Catalog\Model\Category $category | ||
* @param ResolveInfo $info | ||
* @return bool | ||
*/ | ||
protected function isCurrentEntity($category, $info) | ||
{ | ||
$variables = $info->variableValues; | ||
|
||
return !empty($variables['_filter_0']['category_url_path']['eq']) | ||
&& $variables['_filter_0']['category_url_path']['eq'] === $category->getUrlPath(); | ||
} | ||
|
||
/** | ||
* Check if go out | ||
* | ||
* @param \Magento\Catalog\Model\Category $category | ||
* @param string $fieldName | ||
* @return boolean | ||
*/ | ||
protected function out($category, $fieldName) | ||
{ | ||
if (!is_object($category)) { | ||
return true; | ||
} | ||
|
||
if ($fieldName !== 'description') { | ||
return true; | ||
} | ||
|
||
return false; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
<?php | ||
/** | ||
* Copyright © MageWorx. All rights reserved. | ||
* See LICENSE.txt for license details. | ||
*/ | ||
|
||
namespace MageWorx\SeoXTemplatesGraphQl\Plugin; | ||
|
||
use Magento\Framework\GraphQl\Config\Element\Field; | ||
use Magento\Framework\GraphQl\Schema\Type\ResolveInfo; | ||
use MageWorx\SeoXTemplates\Model\DynamicRenderer\Category as Renderer; | ||
|
||
class ModifyCategoryNamePlugin | ||
{ | ||
/** | ||
* @var \MageWorx\SeoXTemplates\Helper\Data | ||
*/ | ||
protected $helperData; | ||
|
||
/** | ||
* ModifyCategoryNamePlugin constructor. | ||
* | ||
* @param \MageWorx\SeoXTemplates\Helper\Data $helperData | ||
*/ | ||
public function __construct( | ||
\MageWorx\SeoXTemplates\Helper\Data $helperData | ||
) { | ||
$this->helperData = $helperData; | ||
} | ||
|
||
/** | ||
* @param \MageWorx\SeoAllGraphQl\Model\Resolver\Category\SeoRenderedElement $subject | ||
* @param string|null $result | ||
* @param Field $field | ||
* @param $context | ||
* @param ResolveInfo $info | ||
* @param array|null $value | ||
* @param array|null $args | ||
* | ||
* @return strung | ||
*/ | ||
public function afterResolve( | ||
$subject, | ||
$result, | ||
Field $field, | ||
$context, | ||
ResolveInfo $info, | ||
array $value = null, | ||
array $args = null | ||
) { | ||
if (!$result) { | ||
return $result; | ||
} | ||
|
||
/** @var \Magento\Catalog\Model\Category $category */ | ||
$category = $value['model']; | ||
$fieldName = $field->getName(); | ||
|
||
if ($this->out($category, $fieldName)) { | ||
return $result; | ||
} | ||
|
||
$categorySeoName = $category->getData('category_seo_name'); | ||
$category->setData('name', $categorySeoName); | ||
|
||
return $categorySeoName; | ||
} | ||
|
||
/** | ||
* Check if go out | ||
* | ||
* @param \Magento\Catalog\Model\Category $category | ||
* @param string $fieldName | ||
* @return boolean | ||
*/ | ||
protected function out($category, $fieldName) | ||
{ | ||
if (!is_object($category)) { | ||
return true; | ||
} | ||
|
||
if ($fieldName !== 'name') { | ||
return true; | ||
} | ||
|
||
if (!$this->helperData->isUseCategorySeoName()) { | ||
return true; | ||
} | ||
|
||
if (empty($category->getData('category_seo_name'))) { | ||
return true; | ||
} | ||
|
||
return false; | ||
} | ||
} |
Oops, something went wrong.