Skip to content

Commit

Permalink
Merge pull request #149 from delyriand/fix/product-dto-with-null-value
Browse files Browse the repository at this point in the history
Not create dto object when we have null value in product normalizer
  • Loading branch information
maximehuran authored Dec 5, 2022
2 parents b4a5ad7 + 3d2e60e commit 376219a
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 13 deletions.
11 changes: 7 additions & 4 deletions .github/workflows/recipe.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,14 @@ jobs:

steps:
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php }}
ini-values: date.timezone=UTC

- name: Set project php-version
run: |
sudo update-alternatives --set php /usr/bin/php${{ matrix.php }}
echo "date.timezone=UTC" >> /tmp/timezone.ini
sudo mv /tmp/timezone.ini /etc/php/${{ matrix.php }}/cli/conf.d/timezone.ini
echo ${{ matrix.php }} > .php-version
echo "${{ matrix.php }}" > .php-version
- uses: actions/checkout@v2
with:
Expand Down
8 changes: 6 additions & 2 deletions .github/workflows/security.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,13 @@ jobs:
- uses: actions/checkout@v2

- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php }}
ini-values: date.timezone=UTC

- name: Set project php-version
run: |
sudo update-alternatives --set php /usr/bin/php${{ matrix.php }}
echo "date.timezone=UTC" | sudo tee /etc/php/${{ matrix.php }}/cli/conf.d/timezone.ini
echo "${{ matrix.php }}" > .php-version
- uses: actions/cache@v1
Expand Down
8 changes: 6 additions & 2 deletions .github/workflows/tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,13 @@ jobs:
node-version: '14'

- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php }}
ini-values: date.timezone=UTC

- name: Set project php-version
run: |
sudo update-alternatives --set php /usr/bin/php${{ matrix.php }}
echo "date.timezone=UTC" | sudo tee /etc/php/${{ matrix.php }}/cli/conf.d/timezone.ini
echo "${{ matrix.php }}" > .php-version
- name: Install symfony CLI
Expand Down
10 changes: 5 additions & 5 deletions src/Normalizer/Product/ProductDTONormalizer.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,13 +63,13 @@ public function denormalize($data, string $type, string $format = null, array $c
/** @var EaterInterface $object */
$object = parent::denormalize($data, $type, $format, $context);

if (\array_key_exists('main_taxon', $data)) {
if (\array_key_exists('main_taxon', $data) && null !== $data['main_taxon']) {
$taxonDTOClass = $this->automapperConfiguration->getTargetClass('taxon');
$object->setData('main_taxon', $this->denormalizer->denormalize($data['main_taxon'], $taxonDTOClass, 'json', $context));
unset($data['main_taxon']);
}

if (\array_key_exists('product_taxons', $data)) {
if (\array_key_exists('product_taxons', $data) && null !== $data['product_taxons']) {
$values = [];
$productTaxonDTOClass = $this->automapperConfiguration->getTargetClass('product_taxon');
foreach ($data['product_taxons'] as $value) {
Expand All @@ -89,7 +89,7 @@ public function denormalize($data, string $type, string $format = null, array $c
unset($data['product_taxons']);
}

if (\array_key_exists('channels', $data)) {
if (\array_key_exists('channels', $data) && null !== $data['channels']) {
$values = [];
$channelDTOClass = $this->automapperConfiguration->getTargetClass('channel');
foreach ($data['channels'] as $value) {
Expand All @@ -99,7 +99,7 @@ public function denormalize($data, string $type, string $format = null, array $c
unset($data['channels']);
}

if (\array_key_exists('attributes', $data)) {
if (\array_key_exists('attributes', $data) && null !== $data['attributes']) {
$values = [];
$productAttributeDTOClass = $this->automapperConfiguration->getTargetClass('product_attribute');
foreach ($data['attributes'] as $key => $value) {
Expand All @@ -109,7 +109,7 @@ public function denormalize($data, string $type, string $format = null, array $c
unset($data['channels']);
}

if (\array_key_exists('prices', $data)) {
if (\array_key_exists('prices', $data) && null !== $data['prices']) {
$values = [];
$pricingDTOClass = $this->automapperConfiguration->getTargetClass('pricing');
foreach ($data['prices'] as $key => $value) {
Expand Down

0 comments on commit 376219a

Please sign in to comment.