Skip to content

Commit

Permalink
Merge pull request PrestaShop#22238 from zuk3975/m/product/combinatio…
Browse files Browse the repository at this point in the history
…n-details

Rename UpdateCombinationOptionsCommand to *Details* and add $weight handling
  • Loading branch information
jolelievre authored Dec 7, 2020
2 parents 3ee4438 + 2f8c11d commit e719e31
Show file tree
Hide file tree
Showing 12 changed files with 165 additions and 95 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,14 @@

use Combination;
use PrestaShop\PrestaShop\Adapter\Product\Repository\CombinationRepository;
use PrestaShop\PrestaShop\Core\Domain\Product\Combination\Command\UpdateCombinationOptionsCommand;
use PrestaShop\PrestaShop\Core\Domain\Product\Combination\CommandHandler\UpdateCombinationOptionsHandlerInterface;
use PrestaShop\PrestaShop\Core\Domain\Product\Combination\Command\UpdateCombinationDetailsCommand;
use PrestaShop\PrestaShop\Core\Domain\Product\Combination\CommandHandler\UpdateCombinationDetailsHandlerInterface;
use PrestaShop\PrestaShop\Core\Domain\Product\Combination\Exception\CannotUpdateCombinationException;

/**
* Handles @see UpdateCombinationOptionsCommand using legacy object model
* Handles @see UpdateCombinationDetailsCommand using legacy object model
*/
final class UpdateCombinationOptionsHandler implements UpdateCombinationOptionsHandlerInterface
final class UpdateCombinationDetailsHandler implements UpdateCombinationDetailsHandlerInterface
{
/**
* @var CombinationRepository
Expand All @@ -56,7 +56,7 @@ public function __construct(
/**
* {@inheritdoc}
*/
public function handle(UpdateCombinationOptionsCommand $command): void
public function handle(UpdateCombinationDetailsCommand $command): void
{
$combination = $this->combinationRepository->get($command->getCombinationId());
$updatableProperties = $this->fillUpdatableProperties($combination, $command);
Expand All @@ -70,11 +70,11 @@ public function handle(UpdateCombinationOptionsCommand $command): void

/**
* @param Combination $combination
* @param UpdateCombinationOptionsCommand $command
* @param UpdateCombinationDetailsCommand $command
*
* @return string[]|array<string, int[]>
*/
private function fillUpdatableProperties(Combination $combination, UpdateCombinationOptionsCommand $command): array
private function fillUpdatableProperties(Combination $combination, UpdateCombinationDetailsCommand $command): array
{
//@todo: ps_stock table contains properties(reference, ean13 etc.) that should be updated too depending if we still support ADVANCED_STOCK_MANAGEMENT
// check Product::updateAttribute L 2165
Expand Down Expand Up @@ -105,6 +105,10 @@ private function fillUpdatableProperties(Combination $combination, UpdateCombina
$updatableProperties[] = 'upc';
}

if (null !== $command->getWeight()) {
$combination->weight = (float) (string) $command->getWeight();
}

return $updatableProperties;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@
use PrestaShop\PrestaShop\Adapter\Product\Repository\CombinationRepository;
use PrestaShop\PrestaShop\Core\Domain\Product\Combination\Query\GetCombinationForEditing;
use PrestaShop\PrestaShop\Core\Domain\Product\Combination\QueryHandler\GetCombinationForEditingHandlerInterface;
use PrestaShop\PrestaShop\Core\Domain\Product\Combination\QueryResult\CombinationDetails;
use PrestaShop\PrestaShop\Core\Domain\Product\Combination\QueryResult\CombinationForEditing;
use PrestaShop\PrestaShop\Core\Domain\Product\Combination\QueryResult\CombinationOptions;
use PrestaShop\PrestaShop\Core\Domain\Product\Combination\QueryResult\CombinationPrices;

/**
Expand Down Expand Up @@ -64,24 +64,25 @@ public function handle(GetCombinationForEditing $query): CombinationForEditing
$combination = $this->combinationRepository->get($query->getCombinationId());

return new CombinationForEditing(
$this->getOptions($combination),
$this->getDetails($combination),
$this->getPrices($combination)
);
}

/**
* @param Combination $combination
*
* @return CombinationOptions
* @return CombinationDetails
*/
private function getOptions(Combination $combination): CombinationOptions
private function getDetails(Combination $combination): CombinationDetails
{
return new CombinationOptions(
return new CombinationDetails(
$combination->ean13,
$combination->isbn,
$combination->mpn,
$combination->reference,
$combination->upc
$combination->upc,
new DecimalNumber($combination->weight)
);
}

Expand Down
5 changes: 3 additions & 2 deletions src/Adapter/Product/Validate/CombinationValidator.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ class CombinationValidator extends AbstractObjectModelValidator
*/
public function validate(Combination $combination): void
{
$this->validateOptions($combination);
$this->validateDetails($combination);
$this->validatePrices($combination);
}

Expand All @@ -53,13 +53,14 @@ public function validate(Combination $combination): void
* @throws CoreException
* @throws ProductConstraintException
*/
private function validateOptions(Combination $combination): void
private function validateDetails(Combination $combination): void
{
$this->validateCombinationProperty($combination, 'ean13', ProductConstraintException::INVALID_EAN_13);
$this->validateCombinationProperty($combination, 'isbn', ProductConstraintException::INVALID_ISBN);
$this->validateCombinationProperty($combination, 'mpn', ProductConstraintException::INVALID_MPN);
$this->validateCombinationProperty($combination, 'reference', ProductConstraintException::INVALID_REFERENCE);
$this->validateCombinationProperty($combination, 'upc', ProductConstraintException::INVALID_UPC);
$this->validateCombinationProperty($combination, 'weight', ProductConstraintException::INVALID_WEIGHT);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@

namespace PrestaShop\PrestaShop\Core\Domain\Product\Combination\Command;

use PrestaShop\Decimal\DecimalNumber;
use PrestaShop\PrestaShop\Core\Domain\Product\Combination\ValueObject\CombinationId;
use PrestaShop\PrestaShop\Core\Domain\Product\Exception\ProductConstraintException;
use PrestaShop\PrestaShop\Core\Domain\Product\ValueObject\Ean13;
Expand All @@ -36,9 +37,9 @@
use PrestaShop\PrestaShop\Core\Domain\Product\ValueObject\Upc;

/**
* Updates combination options
* Updates combination details
*/
class UpdateCombinationOptionsCommand
class UpdateCombinationDetailsCommand
{
/**
* @var CombinationId
Expand Down Expand Up @@ -70,6 +71,11 @@ class UpdateCombinationOptionsCommand
*/
private $upc;

/**
* @var DecimalNumber|null
*/
private $weight;

/**
* @param int $combinationId
*
Expand Down Expand Up @@ -100,9 +106,9 @@ public function getEan13(): ?Ean13
/**
* @param string $ean13
*
* @return UpdateCombinationOptionsCommand
* @return UpdateCombinationDetailsCommand
*/
public function setEan13(string $ean13): UpdateCombinationOptionsCommand
public function setEan13(string $ean13): UpdateCombinationDetailsCommand
{
$this->ean13 = new Ean13($ean13);

Expand All @@ -120,9 +126,9 @@ public function getIsbn(): ?Isbn
/**
* @param string $isbn
*
* @return UpdateCombinationOptionsCommand
* @return UpdateCombinationDetailsCommand
*/
public function setIsbn(string $isbn): UpdateCombinationOptionsCommand
public function setIsbn(string $isbn): UpdateCombinationDetailsCommand
{
$this->isbn = new Isbn($isbn);

Expand All @@ -140,9 +146,9 @@ public function getMpn(): ?string
/**
* @param string $mpn
*
* @return UpdateCombinationOptionsCommand
* @return UpdateCombinationDetailsCommand
*/
public function setMpn(string $mpn): UpdateCombinationOptionsCommand
public function setMpn(string $mpn): UpdateCombinationDetailsCommand
{
$this->mpn = $mpn;

Expand All @@ -160,9 +166,9 @@ public function getReference(): ?Reference
/**
* @param string $reference
*
* @return UpdateCombinationOptionsCommand
* @return UpdateCombinationDetailsCommand
*/
public function setReference(string $reference): UpdateCombinationOptionsCommand
public function setReference(string $reference): UpdateCombinationDetailsCommand
{
$this->reference = new Reference($reference);

Expand All @@ -180,12 +186,32 @@ public function getUpc(): ?Upc
/**
* @param string $upc
*
* @return UpdateCombinationOptionsCommand
* @return UpdateCombinationDetailsCommand
*/
public function setUpc(string $upc): UpdateCombinationOptionsCommand
public function setUpc(string $upc): UpdateCombinationDetailsCommand
{
$this->upc = new Upc($upc);

return $this;
}

/**
* @return DecimalNumber|null
*/
public function getWeight(): ?DecimalNumber
{
return $this->weight;
}

/**
* @param string $weight
*
* @return UpdateCombinationDetailsCommand
*/
public function setWeight(string $weight): UpdateCombinationDetailsCommand
{
$this->weight = new DecimalNumber($weight);

return $this;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,15 @@

namespace PrestaShop\PrestaShop\Core\Domain\Product\Combination\CommandHandler;

use PrestaShop\PrestaShop\Core\Domain\Product\Combination\Command\UpdateCombinationOptionsCommand;
use PrestaShop\PrestaShop\Core\Domain\Product\Combination\Command\UpdateCombinationDetailsCommand;

/**
* Defines contract to handle @see UpdateCombinationOptionsCommand
* Defines contract to handle @see UpdateCombinationDetailsCommand
*/
interface UpdateCombinationOptionsHandlerInterface
interface UpdateCombinationDetailsHandlerInterface
{
/**
* @param UpdateCombinationOptionsCommand $command
* @param UpdateCombinationDetailsCommand $command
*/
public function handle(UpdateCombinationOptionsCommand $command): void;
public function handle(UpdateCombinationDetailsCommand $command): void;
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,12 @@

namespace PrestaShop\PrestaShop\Core\Domain\Product\Combination\QueryResult;

use PrestaShop\Decimal\DecimalNumber;

/**
* Transfers combination options information
* Transfers combination details
*/
class CombinationOptions
class CombinationDetails
{
/**
* @var string
Expand All @@ -58,25 +60,33 @@ class CombinationOptions
*/
private $upc;

/**
* @var DecimalNumber
*/
private $weight;

/**
* @param string $ean13
* @param string $isbn
* @param string $mpn
* @param string $reference
* @param string $upc
* @param DecimalNumber $weight
*/
public function __construct(
string $ean13,
string $isbn,
string $mpn,
string $reference,
string $upc
string $upc,
DecimalNumber $weight
) {
$this->ean13 = $ean13;
$this->isbn = $isbn;
$this->mpn = $mpn;
$this->reference = $reference;
$this->upc = $upc;
$this->weight = $weight;
}

/**
Expand Down Expand Up @@ -118,4 +128,12 @@ public function getUpc(): string
{
return $this->upc;
}

/**
* @return DecimalNumber
*/
public function getWeight(): DecimalNumber
{
return $this->weight;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,33 +34,33 @@
class CombinationForEditing
{
/**
* @var CombinationOptions
* @var CombinationDetails
*/
private $options;
private $details;

/**
* @var CombinationPrices
*/
private $prices;

/**
* @param CombinationOptions $options
* @param CombinationDetails $details
* @param CombinationPrices $prices
*/
public function __construct(
CombinationOptions $options,
CombinationDetails $details,
CombinationPrices $prices
) {
$this->options = $options;
$this->details = $details;
$this->prices = $prices;
}

/**
* @return CombinationOptions
* @return CombinationDetails
*/
public function getOptions(): CombinationOptions
public function getDetails(): CombinationDetails
{
return $this->options;
return $this->details;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,7 @@ public function getLocalizedDeliveryTimeOutOfStockNotes(): ?array
*
* @return UpdateProductShippingCommand
*/
public function setLocalizedDeliveryTimeOutOfStockNotes(array $localizedDeliveryTimeOutOfStockNotes)
public function setLocalizedDeliveryTimeOutOfStockNotes(array $localizedDeliveryTimeOutOfStockNotes): UpdateProductShippingCommand
{
$this->localizedDeliveryTimeOutOfStockNotes = $localizedDeliveryTimeOutOfStockNotes;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -524,13 +524,13 @@ services:
- name: tactician.handler
command: PrestaShop\PrestaShop\Core\Domain\Product\Combination\Query\GetCombinationForEditing

prestashop.adapter.product.command.update_combination_options_handler:
class: PrestaShop\PrestaShop\Adapter\Product\CommandHandler\UpdateCombinationOptionsHandler
prestashop.adapter.product.command.update_combination_details_handler:
class: PrestaShop\PrestaShop\Adapter\Product\CommandHandler\UpdateCombinationDetailsHandler
arguments:
- '@prestashop.adapter.product.repository.combination_repository'
tags:
- name: tactician.handler
command: PrestaShop\PrestaShop\Core\Domain\Product\Combination\Command\UpdateCombinationOptionsCommand
command: PrestaShop\PrestaShop\Core\Domain\Product\Combination\Command\UpdateCombinationDetailsCommand

prestashop.adapter.product.validate.combination_validator:
class: PrestaShop\PrestaShop\Adapter\Product\Validate\CombinationValidator
Expand Down
Loading

0 comments on commit e719e31

Please sign in to comment.