New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Integrate product quantities form and related command #22986
Conversation
* | ||
* @return array<string, mixed> | ||
*/ | ||
private function extractQuantityData(ProductForEditing $productForEditing): array |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please add unit test
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@jolelievre mentioned He will introduce tests for this class in one of his PR's
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes you asked the same thing in my PR about SEO This is a valid request so I'll implement them in my PR to keep this one no too big (it already add tests on Providers which was never done until now)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please add missing unit tests
admin-dev/themes/new-theme/js/pages/product/edit/product-partial-updater.js
Show resolved
Hide resolved
45ad9a6
to
71e461f
Compare
15ed002
to
605ea0c
Compare
605ea0c
to
8082f57
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we should use stock
as a prefix rather than Quantity It matches the command better and it is a bit wider name than quantity Since stock is more than just a quantity
However I'm surprised I don't see the QuantityType
form type integrated in the ProductType
form, nor do I see any modif in the twig templates
$defaultLabel = sprintf( | ||
'%s (%s)', | ||
$this->translator->trans('Default', [], 'Admin.Global'), | ||
array_search($this->defaultPackStockType, $choices, true) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice and efficient 👍
/** | ||
* Builds commands from product quantity form type | ||
*/ | ||
final class QuantityCommandBuilder implements ProductCommandBuilderInterface |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
final class QuantityCommandBuilder implements ProductCommandBuilderInterface | |
final class StockCommandBuilder implements ProductCommandBuilderInterface |
*/ | ||
public function buildCommand(ProductId $productId, array $formData): array | ||
{ | ||
if (!isset($formData['quantities'])) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if (!isset($formData['quantities'])) { | |
if (!isset($formData['stock'])) { |
@@ -63,6 +64,7 @@ public function getData($id) | |||
return [ | |||
'id' => $id, | |||
'basic' => $this->extractBasicData($productForEditing), | |||
'quantities' => $this->extractQuantityData($productForEditing), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
'quantities' => $this->extractQuantityData($productForEditing), | |
'stock' => $this->extractStockData($productForEditing), |
* | ||
* @return array<string, mixed> | ||
*/ | ||
private function extractQuantityData(ProductForEditing $productForEditing): array |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes you asked the same thing in my PR about SEO This is a valid request so I'll implement them in my PR to keep this one no too big (it already add tests on Providers which was never done until now)
use Symfony\Component\Validator\Constraints\NotBlank; | ||
use Symfony\Component\Validator\Constraints\Type; | ||
|
||
class QuantityType extends TranslatorAwareType |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
class QuantityType extends TranslatorAwareType | |
class StockType extends TranslatorAwareType |
{ | ||
$builder | ||
->add('quantity', NumberType::class, [ | ||
'label' => $this->trans('Quantity', 'Admin.Catalog.Feature'), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure but I think every inputs need 'required' => false,
to integrate smoothly with partial update
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not blocking though since it needs to be confirmed in the dedicated PR, besides I believe the required
option can be inherited by compound forms So maybe we would only need to set it in ProductType
form.type.sell.product.quantity_type: | ||
class: 'PrestaShopBundle\Form\Admin\Sell\Product\QuantityType' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
form.type.sell.product.quantity_type: | |
class: 'PrestaShopBundle\Form\Admin\Sell\Product\QuantityType' | |
form.type.sell.product.stock_type: | |
class: 'PrestaShopBundle\Form\Admin\Sell\Product\StockType' |
prestashop.core.form.command_builder.product.quantity_command_builder: | ||
class: PrestaShop\PrestaShop\Core\Form\IdentifiableObject\CommandBuilder\Product\QuantityCommandBuilder |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
prestashop.core.form.command_builder.product.quantity_command_builder: | |
class: PrestaShop\PrestaShop\Core\Form\IdentifiableObject\CommandBuilder\Product\QuantityCommandBuilder | |
prestashop.core.form.command_builder.product.stock_command_builder: | |
class: PrestaShop\PrestaShop\Core\Form\IdentifiableObject\CommandBuilder\Product\StockCommandBuilder |
125a861
to
3eba3b9
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Perfect! 👍
This change is