Skip to content

Commit

Permalink
Merge pull request PrestaShop#30567 from zuk3975/fix-command-builer-s…
Browse files Browse the repository at this point in the history
…tock-combination

Fix stock availability labels update when product is combination type
  • Loading branch information
marsaldev authored Dec 16, 2022
2 parents 6445949 + e4bfe7e commit e579a3c
Show file tree
Hide file tree
Showing 2 changed files with 86 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@

use PrestaShop\PrestaShop\Core\Domain\Product\Command\UpdateProductCommand;
use PrestaShop\PrestaShop\Core\Domain\Product\ValueObject\ProductId;
use PrestaShop\PrestaShop\Core\Domain\Product\ValueObject\ProductType;
use PrestaShop\PrestaShop\Core\Domain\Shop\ValueObject\ShopConstraint;
use PrestaShop\PrestaShop\Core\Form\IdentifiableObject\CommandBuilder\CommandBuilder;
use PrestaShop\PrestaShop\Core\Form\IdentifiableObject\CommandBuilder\CommandBuilderConfig;
Expand Down Expand Up @@ -207,11 +208,22 @@ private function configureStockInformation(CommandBuilderConfig $config, array $
->addMultiShopField('[stock][options][disabling_switch_low_stock_threshold]', 'setLowStockAlert', DataField::TYPE_BOOL)
->addMultiShopField('[stock][options][low_stock_threshold]', 'setLowStockThreshold', DataField::TYPE_INT)
->addMultiShopField('[stock][pack_stock_type]', 'setPackStockType', DataField::TYPE_INT)
->addMultiShopField('[stock][availability][available_now_label]', 'setLocalizedAvailableNowLabels', DataField::TYPE_ARRAY)
->addMultiShopField('[stock][availability][available_later_label]', 'setLocalizedAvailableLaterLabels', DataField::TYPE_ARRAY)
->addMultiShopField('[stock][availability][available_date]', 'setAvailableDate', DataField::TYPE_DATETIME)
;

$productType = $formData['header']['type'] ?? ProductType::TYPE_STANDARD;
if ($productType === ProductType::TYPE_COMBINATIONS) {
$config
->addMultiShopField('[combinations][availability][available_now_label]', 'setLocalizedAvailableNowLabels', DataField::TYPE_ARRAY)
->addMultiShopField('[combinations][availability][available_later_label]', 'setLocalizedAvailableLaterLabels', DataField::TYPE_ARRAY)
;
} else {
$config
->addMultiShopField('[stock][availability][available_now_label]', 'setLocalizedAvailableNowLabels', DataField::TYPE_ARRAY)
->addMultiShopField('[stock][availability][available_later_label]', 'setLocalizedAvailableLaterLabels', DataField::TYPE_ARRAY)
;
}

return $this;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
use PrestaShop\PrestaShop\Core\Domain\Product\Pack\ValueObject\PackStockType;
use PrestaShop\PrestaShop\Core\Domain\Product\ValueObject\DeliveryTimeNoteType;
use PrestaShop\PrestaShop\Core\Domain\Product\ValueObject\ProductCondition;
use PrestaShop\PrestaShop\Core\Domain\Product\ValueObject\ProductType;
use PrestaShop\PrestaShop\Core\Domain\Product\ValueObject\ProductVisibility;
use PrestaShop\PrestaShop\Core\Domain\Product\ValueObject\RedirectType;
use PrestaShop\PrestaShop\Core\Domain\Shop\ValueObject\ShopConstraint;
Expand All @@ -43,6 +44,7 @@ class UpdateProductCommandsBuilderTest extends AbstractProductCommandBuilderTest
/**
* @dataProvider getExpectedCommands
* @dataProvider getExpectedCommandsMultiShop
* @dataProvider getExpectedCommandsForCombinationsTypeProduct
*
* @param array $formData
* @param array $expectedCommands
Expand Down Expand Up @@ -515,6 +517,22 @@ public function getExpectedCommands(): iterable
[$command],
];

$localizedTimeInStockNotes = [
1 => 'In stock',
2 => 'Yra sandelyje',
];
$localizedTimeOutOfStockNotes = [
1 => 'Out of stock',
2 => 'Isparduota',
];
$localizedAvailableNowLabels = [
1 => 'available now en',
2 => 'available now lt',
];
$localizedAvailableLaterLabels = [
1 => 'available later en',
2 => 'available later lt',
];
$command = $this->getSingleShopCommand()
->setVisibility(ProductVisibility::INVISIBLE)
->setLocalizedShortDescriptions($localizedShortDescriptions)
Expand All @@ -540,14 +558,10 @@ public function getExpectedCommands(): iterable
->setWeight('2.2')
->setDeliveryTimeNoteType(DeliveryTimeNoteType::TYPE_SPECIFIC)
->setAdditionalShippingCost('5.7')
->setLocalizedDeliveryTimeInStockNotes([
1 => 'In stock',
2 => 'Yra sandelyje',
])
->setLocalizedDeliveryTimeOutOfStockNotes([
1 => 'Out of stock',
2 => 'Isparduota',
])
->setLocalizedDeliveryTimeInStockNotes($localizedTimeInStockNotes)
->setLocalizedDeliveryTimeOutOfStockNotes($localizedTimeOutOfStockNotes)
->setLocalizedAvailableNowLabels($localizedAvailableNowLabels)
->setLocalizedAvailableLaterLabels($localizedAvailableLaterLabels)
->setActive(false)
;

Expand Down Expand Up @@ -620,6 +634,56 @@ public function getExpectedCommands(): iterable
],
],
],
'stock' => [
'availability' => [
'available_now_label' => $localizedAvailableNowLabels,
'available_later_label' => $localizedAvailableLaterLabels,
],
],
],
[$command],
];
}

public function getExpectedCommandsForCombinationsTypeProduct(): iterable
{
$localizedAvailableNowLabels = [
1 => 'available now en',
2 => 'available now lt',
];
$localizedAvailableLaterLabels = [
1 => 'available later en',
2 => 'available later lt',
];
// check labels for combinations type product
$command = $this->getSingleShopCommand()
->setLocalizedAvailableNowLabels($localizedAvailableNowLabels)
->setLocalizedAvailableLaterLabels($localizedAvailableLaterLabels)
;
yield [
[
'header' => [
'type' => ProductType::TYPE_COMBINATIONS,
],
// for combinations product these should be ignored and the ones from combinations tab should be used instead.
'stock' => [
'availability' => [
'available_now_label' => [
1 => 'Oh yes, we have it!',
2 => 'Yra sandelyje',
],
'available_later_label' => [
1 => 'Sorry, unavailable.',
2 => 'Greitai papildysime sandelį',
],
],
],
'combinations' => [
'availability' => [
'available_now_label' => $localizedAvailableNowLabels,
'available_later_label' => $localizedAvailableLaterLabels,
],
],
],
[$command],
];
Expand Down

0 comments on commit e579a3c

Please sign in to comment.