Skip to content

Commit

Permalink
Merge pull request #30 from magmodules/release/1.10.2
Browse files Browse the repository at this point in the history
Release/1.10.2
  • Loading branch information
Marvin-Magmodules authored Aug 21, 2024
2 parents c3ef702 + 044d33a commit f506905
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 13 deletions.
39 changes: 28 additions & 11 deletions Service/WebApi/Product.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
use Magento\Catalog\Model\Product as ProductModel;
use Magento\Catalog\Model\ResourceModel\Product\Collection;
use Magento\Catalog\Model\ResourceModel\Product\CollectionFactory as ProductCollectionFactory;
use Magento\Catalog\Api\Data\ProductAttributeInterface;
use Magento\Eav\Api\AttributeRepositoryInterface;
use Magento\Framework\Api\SearchCriteria\CollectionProcessorInterface;
use Magento\Framework\Api\SearchCriteriaInterface;
use Magento\Framework\UrlInterface;
Expand All @@ -19,7 +21,6 @@
use Magmodules\Reloadify\Model\RequestLog\CollectionFactory as RequestLogCollectionFactory;
use Magento\Catalog\Model\Product\Visibility;
use Magento\Store\Model\StoreManagerInterface;
use Magento\Catalog\Model\Product\Type;

/**
* Product web API service class
Expand Down Expand Up @@ -69,6 +70,10 @@ class Product
* @var StoreManagerInterface
*/
private $storeManager;
/**
* @var AttributeRepositoryInterface
*/
private $attributeRepository;

private $mediaPath = '';

Expand All @@ -90,7 +95,8 @@ public function __construct(
ConfigRepository $configRepository,
CollectionProcessorInterface $collectionProcessor,
Visibility $productVisibility,
StoreManagerInterface $storeManager
StoreManagerInterface $storeManager,
AttributeRepositoryInterface $attributeRepository
) {
$this->productsCollectionFactory = $productsCollectionFactory;
$this->reviewCollectionFactory = $reviewCollectionFactory;
Expand All @@ -99,6 +105,7 @@ public function __construct(
$this->collectionProcessor = $collectionProcessor;
$this->productVisibility = $productVisibility;
$this->storeManager = $storeManager;
$this->attributeRepository = $attributeRepository;
}

/**
Expand All @@ -113,23 +120,33 @@ public function execute(int $storeId, array $extra = [], SearchCriteriaInterface
$data = [];
$collection = $this->getCollection($storeId, $extra, $searchCriteria);
$ean = $this->configRepository->getEan($storeId);
$eanType = $this->attributeRepository->get(ProductAttributeInterface::ENTITY_TYPE_CODE, $ean)
->getFrontendInput();
$name = $this->configRepository->getName($storeId);
$nameType = $this->attributeRepository->get(ProductAttributeInterface::ENTITY_TYPE_CODE, $name)
->getFrontendInput();
$sku = $this->configRepository->getSku($storeId);
$skuType = $this->attributeRepository->get(ProductAttributeInterface::ENTITY_TYPE_CODE, $sku)
->getFrontendInput();
$brand = $this->configRepository->getBrand($storeId);
$brandType = $this->attributeRepository->get(ProductAttributeInterface::ENTITY_TYPE_CODE, $brand)
->getFrontendInput();
$description = $this->configRepository->getDescription($storeId);
$descriptionType = $this->attributeRepository
->get(ProductAttributeInterface::ENTITY_TYPE_CODE, $description)->getFrontendInput();

foreach ($collection as $product) {
$data[] = [
"id" => $product->getId(),
"name" => $this->getAttributeValue($product, $name),
"name" => $this->getAttributeValue($product, $name, $nameType),
'product_type' => $product->getTypeId(),
"ean" => $this->getAttributeValue($product, $ean),
"ean" => $this->getAttributeValue($product, $ean, $eanType),
"short_description" => $product->getShortDescription(),
"description" => $this->getAttributeValue($product, $description),
"description" => $this->getAttributeValue($product, $description, $descriptionType),
"price" => $product->getPrice(),
"url" => $product->getProductUrl(),
"sku" => $this->getAttributeValue($product, $sku),
"brand" => $this->getAttributeValue($product, $brand),
"sku" => $this->getAttributeValue($product, $sku, $skuType),
"brand" => $this->getAttributeValue($product, $brand, $brandType),
"main_image" => $this->getMainImage($product),
"visible" => (bool)((int)$product->getVisibility() - 1),
"variant_ids" => $this->getVariants($product),
Expand All @@ -149,12 +166,12 @@ public function execute(int $storeId, array $extra = [], SearchCriteriaInterface
* @param $attribute
* @return mixed|string
*/
private function getAttributeValue($product, $attribute)
private function getAttributeValue($product, $attribute, $type)
{
$value = '';
if ($attribute) {
if ($dropdownValue = $product->getAttributeText($attribute)) {
$value = $dropdownValue;
if ($attribute && $type) {
if (($type == 'select') || ($type == 'multiselect')) {
$value = $product->getAttributeText($attribute);
} else {
$value = $product->getData($attribute);
}
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "magmodules/magento2-reloadify",
"description": "Reloadify extension for Magento 2",
"type": "magento2-module",
"version": "1.10.1",
"version": "1.10.2",
"license": [
"BSD-2-Clause"
],
Expand Down
2 changes: 1 addition & 1 deletion etc/config.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
<default>
<magmodules_reloadify>
<general>
<version>v1.10.1</version>
<version>v1.10.2</version>
<enable>0</enable>
<debug>0</debug>
</general>
Expand Down

0 comments on commit f506905

Please sign in to comment.