Skip to content

Commit

Permalink
refactor: clean up product repository
Browse files Browse the repository at this point in the history
  • Loading branch information
EdieLemoine committed Nov 6, 2023
1 parent aa2a359 commit 1a86415
Showing 1 changed file with 6 additions and 17 deletions.
23 changes: 6 additions & 17 deletions src/Pdk/Product/Repository/PdkProductRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,8 @@
use MyParcelNL\Pdk\App\Order\Model\PdkProduct;
use MyParcelNL\Pdk\App\Order\Repository\AbstractPdkPdkProductRepository;
use MyParcelNL\Pdk\Base\Contract\CurrencyServiceInterface;
use MyParcelNL\Pdk\Facade\Pdk;
use MyParcelNL\Pdk\Settings\Model\ProductSettings;
use MyParcelNL\Pdk\Storage\Contract\StorageInterface;
use MyParcelNL\PrestaShop\Entity\MyparcelnlProductSettings;
use MyParcelNL\PrestaShop\Pdk\Base\Service\PsWeightService;
use MyParcelNL\PrestaShop\Repository\PsProductSettingsRepository;
use MyParcelNL\Sdk\src\Support\Arr;
Expand All @@ -28,12 +26,7 @@ class PdkProductRepository extends AbstractPdkPdkProductRepository
/**
* @var \MyParcelNL\PrestaShop\Repository\PsProductSettingsRepository
*/
private $productSettingsRepository;

/**
* @var \Doctrine\ORM\EntityRepository
*/
private $psProductRepository;
private $psProductSettingsRepository;

/**
* @var \MyParcelNL\PrestaShop\Pdk\Base\Service\PsWeightService
Expand All @@ -53,13 +46,9 @@ public function __construct(
CurrencyServiceInterface $currencyService
) {
parent::__construct($storage);
$this->weightService = $weightService;
$this->productSettingsRepository = $productSettingsRepository;
$this->currencyService = $currencyService;

/** @var \Doctrine\ORM\EntityManager $entityManager */
$entityManager = Pdk::get('ps.entityManager');
$this->psProductRepository = $entityManager->getRepository(MyparcelnlProductSettings::class);
$this->weightService = $weightService;
$this->psProductSettingsRepository = $productSettingsRepository;
$this->currencyService = $currencyService;
}

/**
Expand Down Expand Up @@ -97,7 +86,7 @@ public function getProduct($identifier): PdkProduct
public function getProductSettings($identifier): ProductSettings
{
/** @var \MyParcelNL\PrestaShop\Entity\MyparcelnlProductSettings $psProductSettings */
$psProductSettings = $this->productSettingsRepository->findOneBy(['productId' => $identifier]);
$psProductSettings = $this->psProductSettingsRepository->findOneBy(['productId' => $identifier]);

$array = $psProductSettings ? $psProductSettings->toArray() : [];

Expand All @@ -124,7 +113,7 @@ public function getProducts(array $identifiers = []): PdkProductCollection
*/
public function update(PdkProduct $product): void
{
$this->productSettingsRepository->updateOrCreate(
$this->psProductSettingsRepository->updateOrCreate(
[
'productId' => (int) $product->externalIdentifier,
],
Expand Down

0 comments on commit 1a86415

Please sign in to comment.