diff --git a/Block/Entity/Attribute/CustomEntity/Renderer.php b/Block/Entity/Attribute/CustomEntity/Renderer.php index 300a51e..54c7273 100644 --- a/Block/Entity/Attribute/CustomEntity/Renderer.php +++ b/Block/Entity/Attribute/CustomEntity/Renderer.php @@ -20,6 +20,6 @@ class Renderer extends Template */ public function getTemplate(): string { - return parent::getTemplate() ?? 'Smile_CustomEntityProductLink::entity/attribute/custom_entity/renderer.phtml'; + return 'Smile_CustomEntityProductLink::entity/attribute/custom_entity/renderer.phtml'; } } diff --git a/Helper/Product.php b/Helper/Product.php index f30ab1b..5663cac 100644 --- a/Helper/Product.php +++ b/Helper/Product.php @@ -46,12 +46,14 @@ public function __construct( public function getCustomEntities(ProductInterface $product, string $attributeCode): array { $result = []; - $customEntities = $product->getExtensionAttributes()->getCustomEntities() ?? []; - foreach ($customEntities as $customEntity) { - if ($customEntity->getProductAttributeCode() !== $attributeCode || !$customEntity->getIsActive()) { - continue; + $customEntities = $product->getExtensionAttributes()->getCustomEntities(); + if ($customEntities) { + foreach ($customEntities as $customEntity) { + if ($customEntity->getProductAttributeCode() !== $attributeCode || !$customEntity->getIsActive()) { + continue; + } + $result[] = $customEntity; } - $result[] = $customEntity; } return $result; diff --git a/Model/Layer/CustomEntity/CollectionFilter.php b/Model/Layer/CustomEntity/CollectionFilter.php index bc802d1..de1eab6 100644 --- a/Model/Layer/CustomEntity/CollectionFilter.php +++ b/Model/Layer/CustomEntity/CollectionFilter.php @@ -9,11 +9,9 @@ use Magento\Catalog\Model\Layer\Category\CollectionFilter as BaseCollectionFilter; use Magento\Catalog\Model\Layer\CollectionFilterInterface; use Magento\Catalog\Model\Product\Visibility; -use Magento\Catalog\Model\ResourceModel\Product\Collection; use Magento\Framework\Registry; use Smile\CustomEntity\Api\Data\CustomEntityInterface; use Smile\CustomEntityProductLink\Helper\Product as ProductHelper; -use Smile\ElasticsuiteCore\Helper\Mapping; use Smile\ElasticsuiteCore\Search\Request\Query\QueryFactory; use Smile\ElasticsuiteCore\Search\Request\QueryInterface; @@ -35,7 +33,7 @@ class CollectionFilter extends BaseCollectionFilter implements CollectionFilterI * @param Config $catalogConfig Catalog config. * @param ProductHelper $productHelper Product helper. * @param Registry $registry Registry. - * @param Mapping $mappingHelper Mapping helper. + * @param QueryFactory $queryFactory Query factory. */ public function __construct( Visibility $productVisibility, @@ -51,12 +49,9 @@ public function __construct( } /** - * Filter product collection. - * - * @param Collection $collection Collection. - * @param Category $category Category. + * @inheritdoc */ - public function filter(Collection $collection, Category $category): void + public function filter($collection, Category $category): void { parent::filter($collection, $category); $currentCustomEntity = $this->getCurrentCustomEntity(); diff --git a/Model/Product/Indexer/Fulltext/Datasource/CustomEntity.php b/Model/Product/Indexer/Fulltext/Datasource/CustomEntity.php index 6e1af44..25b75e0 100644 --- a/Model/Product/Indexer/Fulltext/Datasource/CustomEntity.php +++ b/Model/Product/Indexer/Fulltext/Datasource/CustomEntity.php @@ -58,13 +58,9 @@ public function __construct( } /** - * Append data to a list of documents. - * - * @param int $storeId Store id. - * @param array $indexData List of documents to get enriched by the datasources. - * @return array + * @inheritdoc */ - public function addData(int $storeId, array $indexData): array + public function addData($storeId, array $indexData): array { $productIds = array_keys($indexData); $customEntitiesData = $this->loadCustomEntityRowData($storeId, $productIds, array_keys($this->attributeById)); @@ -150,7 +146,7 @@ private function addField(AttributeInterface $attribute): self $fieldConfig['is_used_in_spellcheck'] = false; $fieldConfig['is_searchable'] = false; - $fieldType = $this->attributeHelper->getFieldType($attribute); + $fieldType = $this->attributeHelper->getFieldType($attribute); $fieldOptions = ['name' => $fieldName, 'type' => $fieldType, 'fieldConfig' => $fieldConfig]; $this->fields[$fieldName] = $this->fieldFactory->create($fieldOptions); diff --git a/Model/ResourceModel/CustomEntityProductLinkManagement.php b/Model/ResourceModel/CustomEntityProductLinkManagement.php index c243203..66c41e0 100644 --- a/Model/ResourceModel/CustomEntityProductLinkManagement.php +++ b/Model/ResourceModel/CustomEntityProductLinkManagement.php @@ -9,7 +9,7 @@ /** * Custom entity product link management resource model. */ -class CustomEntityProductLinkManagement extends AbstractDb +abstract class CustomEntityProductLinkManagement extends AbstractDb { public const RELATION_TABLE_NAME = 'catalog_product_custom_entity_link'; diff --git a/Model/ResourceModel/Search/CustomCollection.php b/Model/ResourceModel/Search/CustomCollection.php index 16a7958..f868453 100644 --- a/Model/ResourceModel/Search/CustomCollection.php +++ b/Model/ResourceModel/Search/CustomCollection.php @@ -36,12 +36,9 @@ protected function _getAttributesCollection(): AbstractDb } /** - * Add the smile custom entities sql request - * - * @param mixed $query Query - * @param bool $searchOnlyInCurrentStore Search only in current store or in all stores + * @inheritdoc */ - protected function _getSearchEntityIdsSql($query, bool $searchOnlyInCurrentStore = true): string + protected function _getSearchEntityIdsSql($query, $searchOnlyInCurrentStore = true) { $sql = parent::_getSearchEntityIdsSql($query, $searchOnlyInCurrentStore); @@ -71,8 +68,8 @@ protected function _getSmileCustomSql($query): ?array $smileCustomEntityAttributeIds[] = $attribute->getId(); } + $selects = []; if ($smileCustomEntityAttributeIds) { - $selects = []; $selects[] = $this->getConnection()->select()->from( ['cpe' => 'catalog_product_entity'], $this->getEntity()->getLinkField() diff --git a/Observer/Adminhtml/CatalogProductFormExcludedAttributesObserver.php b/Observer/Adminhtml/CatalogProductFormExcludedAttributesObserver.php index d6764a7..c4276d2 100644 --- a/Observer/Adminhtml/CatalogProductFormExcludedAttributesObserver.php +++ b/Observer/Adminhtml/CatalogProductFormExcludedAttributesObserver.php @@ -44,9 +44,9 @@ public function execute(Observer $observer): void /** * Return attribute codes. * - * @return array|null + * @return array */ - private function getCustomEntityAttributeCodes(): ?array + private function getCustomEntityAttributeCodes(): array { return array_map(function ($attribute) { return $attribute->getAttributeCode(); diff --git a/Plugin/Block/Product/ListProductPlugin.php b/Plugin/Block/Product/ListProductPlugin.php index 24c4fcb..0edffbb 100644 --- a/Plugin/Block/Product/ListProductPlugin.php +++ b/Plugin/Block/Product/ListProductPlugin.php @@ -6,7 +6,6 @@ use Magento\Catalog\Api\Data\ProductInterface; use Magento\Catalog\Block\Product\ListProduct; -use Smile\CustomEntity\Api\Data\CustomEntityInterface; /** * List product block plugin. @@ -24,11 +23,13 @@ public function afterGetIdentities(ListProduct $source, array $identities): ?arr { /** @var ProductInterface $product */ foreach ($source->getLoadedProductCollection() as $product) { - $customEntities = $product->getExtensionAttributes()->getCustomEntities() ?? []; - /** @var CustomEntityInterface $customEntity */ - foreach ($customEntities as $customEntity) { - // @codingStandardsIgnoreLine - $identities = array_merge($identities, $customEntity->getIdentities()); + $customEntities = $product->getExtensionAttributes()->getCustomEntities(); + $identities = []; + if ($customEntities) { + foreach ($customEntities as $customEntity) { + // @codingStandardsIgnoreLine + $identities = array_merge($identities, $customEntity->getIdentities()); + } } } diff --git a/Plugin/Catalog/Ui/DataProvider/Product/Form/Modifier/EavPlugin.php b/Plugin/Catalog/Ui/DataProvider/Product/Form/Modifier/EavPlugin.php index 36ec1a1..7c21cd7 100644 --- a/Plugin/Catalog/Ui/DataProvider/Product/Form/Modifier/EavPlugin.php +++ b/Plugin/Catalog/Ui/DataProvider/Product/Form/Modifier/EavPlugin.php @@ -38,11 +38,11 @@ public function __construct(EntityCollectionFactory $entityCollectionFactory, Ar /** * Fix custom entity field meta. * - * @param EavModifier $subject Object. - * @param callable $proceed Original method. + * @param EavModifier $subject Object. + * @param callable $proceed Original method. * @param ProductAttributeInterface $attribute Attribute. - * @param string $groupCode Group code. - * @param int $sortOrder Sort order. + * @param string $groupCode Group code. + * @param int $sortOrder Sort order. * @return array|null */ public function aroundSetupAttributeMeta( @@ -77,9 +77,9 @@ public function aroundSetupAttributeMeta( * List of custom entities. * * @param ProductAttributeInterface $attribute Attribute. - * @return array|null + * @return array */ - private function getOptions(ProductAttributeInterface $attribute): ?array + private function getOptions(ProductAttributeInterface $attribute): array { $attributeSetId = $attribute->getCustomEntityAttributeSetId(); diff --git a/Plugin/Helper/AbstractAttributePlugin.php b/Plugin/Helper/AbstractAttributePlugin.php index 39c5a63..8e62d8d 100644 --- a/Plugin/Helper/AbstractAttributePlugin.php +++ b/Plugin/Helper/AbstractAttributePlugin.php @@ -5,6 +5,7 @@ namespace Smile\CustomEntityProductLink\Plugin\Helper; use Magento\Eav\Model\Entity\Attribute\AttributeInterface; +use Smile\CustomEntity\Model\CustomEntity; use Smile\ElasticsuiteCatalog\Helper\ProductAttribute; /** @@ -21,7 +22,7 @@ class AbstractAttributePlugin */ public function afterGetFilterField(ProductAttribute $source, string $field, AttributeInterface $attribute): ?string { - if ($attribute->getFrontendInput() == 'smile_custom_entity') { + if ($attribute->getFrontendInput() == CustomEntity::CACHE_TAG) { $field = $source->getOptionTextFieldName($field); } diff --git a/Plugin/Model/ProductPlugin.php b/Plugin/Model/ProductPlugin.php index 96d8f70..0990956 100644 --- a/Plugin/Model/ProductPlugin.php +++ b/Plugin/Model/ProductPlugin.php @@ -28,8 +28,8 @@ public function __construct(Data $helper) /** * Append custom entity identities when update product attributes. * - * @param Product $source Product model. - * @param array $identities Identities. + * @param Product $source Product model. + * @param array $identities Identities. * @return array|null */ public function afterGetIdentities(Product $source, array $identities): ?array