-
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
1 parent
7d59612
commit 6b846e8
Showing
14 changed files
with
164 additions
and
136 deletions.
There are no files selected for viewing
10 changes: 5 additions & 5 deletions
10
...ttributeValueResolver/DefaultResolver.php → ...ttributeValueResolver/DefaultResolver.php
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
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,26 @@ | ||
<?php declare(strict_types=1); | ||
|
||
namespace MateuszMesek\DocumentDataCatalogProduct\Model\Command; | ||
|
||
use Magento\Catalog\Api\Data\ProductInterface; | ||
use Magento\Catalog\Model\Product; | ||
use MateuszMesek\DocumentDataApi\Model\Command\GetDocumentDataInterface; | ||
use MateuszMesek\DocumentDataApi\Model\Data\DocumentDataInterface; | ||
use MateuszMesek\DocumentDataCatalogProduct\Model\Data\InputFactory; | ||
|
||
class GetDocumentData | ||
{ | ||
public function __construct( | ||
private readonly InputFactory $inputFactory, | ||
private readonly GetDocumentDataInterface $getDocumentData | ||
) | ||
{ | ||
} | ||
|
||
public function execute(ProductInterface $product): ?DocumentDataInterface | ||
{ | ||
$input = $this->inputFactory->create(['product' => $product]); | ||
|
||
return $this->getDocumentData->execute(Product::ENTITY, $input); | ||
} | ||
} |
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,77 @@ | ||
<?php declare(strict_types=1); | ||
|
||
namespace MateuszMesek\DocumentDataCatalogProduct\Model\Command; | ||
|
||
use Magento\Catalog\Model\ProductFactory; | ||
use Magento\Catalog\Model\ResourceModel\Product as ProductResource; | ||
use Magento\Catalog\Model\ResourceModel\Product\Website\Link as ProductWebsiteLinkResource; | ||
use Magento\Framework\Exception\NoSuchEntityException; | ||
use Magento\Store\Model\Store; | ||
use Magento\Store\Model\StoreManagerInterface; | ||
use MateuszMesek\DocumentDataApi\Model\Data\DocumentDataInterface; | ||
|
||
class GetDocumentDataByProductIdAndStoreId | ||
{ | ||
public function __construct( | ||
private readonly ProductWebsiteLinkResource $productWebsiteLinkResource, | ||
private readonly StoreManagerInterface $storeManager, | ||
private readonly ProductResource $productResource, | ||
private readonly ProductFactory $productFactory, | ||
private readonly GetDocumentData $getDocumentData | ||
) | ||
{ | ||
} | ||
|
||
public function execute(int $productId, int $storeId): ?DocumentDataInterface | ||
{ | ||
if (!$this->isProductAvailableInStore($productId, $storeId)) { | ||
return null; | ||
} | ||
|
||
$product = $this->productFactory->create(); | ||
$product->setStoreId($storeId); | ||
|
||
$this->productResource->load($product, $productId); | ||
|
||
return $this->getDocumentData->execute($product); | ||
} | ||
|
||
/** | ||
* @param int $productId | ||
* @param int $storeId | ||
* @return bool | ||
*/ | ||
private function isProductAvailableInStore(int $productId, int $storeId): bool | ||
{ | ||
return in_array( | ||
$this->getWebsiteIdByStoreId($storeId), | ||
$this->getWebsiteIdsByProductId($productId), | ||
true | ||
); | ||
} | ||
|
||
/** | ||
* @param int $storeId | ||
* @return int | ||
*/ | ||
private function getWebsiteIdByStoreId(int $storeId): int | ||
{ | ||
try { | ||
return (int)$this->storeManager->getStore($storeId)->getWebsiteId(); | ||
} catch (NoSuchEntityException $exception) { | ||
return Store::DEFAULT_STORE_ID; | ||
} | ||
} | ||
|
||
/** | ||
* @param int $productId | ||
* @return int[] | ||
*/ | ||
private function getWebsiteIdsByProductId(int $productId): array | ||
{ | ||
return array_map( | ||
'intval', | ||
$this->productWebsiteLinkResource->getWebsiteIdsByProductId($productId) | ||
); | ||
} | ||
} |
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
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
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
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
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
File renamed without changes.
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
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
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
Oops, something went wrong.