Skip to content
This repository was archived by the owner on Oct 24, 2023. It is now read-only.

Commit b60aab0

Browse files
author
Jens Schulze
committed
feat: support staged flag for product meta update actions
Closes #358
1 parent ec2fce5 commit b60aab0

File tree

5 files changed

+87
-3
lines changed

5 files changed

+87
-3
lines changed

src/Core/Request/Products/Command/ProductSetMetaDescriptionAction.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616
* @method ProductSetMetaDescriptionAction setAction(string $action = null)
1717
* @method LocalizedString getMetaDescription()
1818
* @method ProductSetMetaDescriptionAction setMetaDescription(LocalizedString $metaDescription = null)
19+
* @method bool getStaged()
20+
* @method ProductSetMetaDescriptionAction setStaged(bool $staged = null)
1921
*/
2022
class ProductSetMetaDescriptionAction extends AbstractAction
2123
{
@@ -24,6 +26,7 @@ public function fieldDefinitions()
2426
return [
2527
'action' => [static::TYPE => 'string'],
2628
'metaDescription' => [static::TYPE => LocalizedString::class],
29+
'staged' => [static::TYPE => 'bool'],
2730
];
2831
}
2932

src/Core/Request/Products/Command/ProductSetMetaKeywordsAction.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616
* @method ProductSetMetaKeywordsAction setAction(string $action = null)
1717
* @method LocalizedString getMetaKeywords()
1818
* @method ProductSetMetaKeywordsAction setMetaKeywords(LocalizedString $metaKeywords = null)
19+
* @method bool getStaged()
20+
* @method ProductSetMetaKeywordsAction setStaged(bool $staged = null)
1921
*/
2022
class ProductSetMetaKeywordsAction extends AbstractAction
2123
{
@@ -24,6 +26,7 @@ public function fieldDefinitions()
2426
return [
2527
'action' => [static::TYPE => 'string'],
2628
'metaKeywords' => [static::TYPE => LocalizedString::class],
29+
'staged' => [static::TYPE => 'bool'],
2730
];
2831
}
2932

src/Core/Request/Products/Command/ProductSetMetaTitleAction.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616
* @method ProductSetMetaTitleAction setAction(string $action = null)
1717
* @method LocalizedString getMetaTitle()
1818
* @method ProductSetMetaTitleAction setMetaTitle(LocalizedString $metaTitle = null)
19+
* @method bool getStaged()
20+
* @method ProductSetMetaTitleAction setStaged(bool $staged = null)
1921
*/
2022
class ProductSetMetaTitleAction extends AbstractAction
2123
{
@@ -24,6 +26,7 @@ public function fieldDefinitions()
2426
return [
2527
'action' => [static::TYPE => 'string'],
2628
'metaTitle' => [static::TYPE => LocalizedString::class],
29+
'staged' => [static::TYPE => 'bool'],
2730
];
2831
}
2932

tests/integration/Product/ProductUpdateRequestTest.php

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -902,6 +902,31 @@ public function testMetaTitle()
902902
$this->assertNotSame($product->getVersion(), $result->getVersion());
903903
}
904904

905+
public function testMetaTitlePublish()
906+
{
907+
$draft = $this->getDraft('meta-title');
908+
$product = $this->createProduct($draft);
909+
910+
$metaTitle = $this->getTestRun() . '-meta-title';
911+
$request = ProductUpdateRequest::ofIdAndVersion($product->getId(), $product->getVersion())
912+
->addAction(
913+
ProductSetMetaTitleAction::of()->setMetaTitle(
914+
LocalizedString::ofLangAndText('en', $metaTitle)
915+
)->setStaged(false)
916+
)
917+
;
918+
$response = $request->executeWithClient($this->getClient());
919+
$result = $request->mapResponse($response);
920+
$this->deleteRequest->setVersion($result->getVersion());
921+
922+
$this->assertInstanceOf(Product::class, $result);
923+
$this->assertSame(
924+
$metaTitle,
925+
$result->getMasterData()->getCurrent()->getMetaTitle()->en
926+
);
927+
$this->assertNotSame($product->getVersion(), $result->getVersion());
928+
}
929+
905930
public function testMetaDescription()
906931
{
907932
$draft = $this->getDraft('meta-description');
@@ -928,6 +953,31 @@ public function testMetaDescription()
928953
$this->assertNotSame($product->getVersion(), $result->getVersion());
929954
}
930955

956+
public function testMetaDescriptionPublish()
957+
{
958+
$draft = $this->getDraft('meta-description');
959+
$product = $this->createProduct($draft);
960+
961+
$metaDescription = $this->getTestRun() . '-meta-description';
962+
$request = ProductUpdateRequest::ofIdAndVersion($product->getId(), $product->getVersion())
963+
->addAction(
964+
ProductSetMetaDescriptionAction::of()->setMetaDescription(
965+
LocalizedString::ofLangAndText('en', $metaDescription)
966+
)->setStaged(false)
967+
)
968+
;
969+
$response = $request->executeWithClient($this->getClient());
970+
$result = $request->mapResponse($response);
971+
$this->deleteRequest->setVersion($result->getVersion());
972+
973+
$this->assertInstanceOf(Product::class, $result);
974+
$this->assertSame(
975+
$metaDescription,
976+
$result->getMasterData()->getCurrent()->getMetaDescription()->en
977+
);
978+
$this->assertNotSame($product->getVersion(), $result->getVersion());
979+
}
980+
931981
public function testMetaKeywords()
932982
{
933983
$draft = $this->getDraft('meta-keywords');
@@ -954,6 +1004,31 @@ public function testMetaKeywords()
9541004
$this->assertNotSame($product->getVersion(), $result->getVersion());
9551005
}
9561006

1007+
public function testMetaKeywordsPublish()
1008+
{
1009+
$draft = $this->getDraft('meta-keywords');
1010+
$product = $this->createProduct($draft);
1011+
1012+
$metaKeywords = $this->getTestRun() . '-meta-keywords';
1013+
$request = ProductUpdateRequest::ofIdAndVersion($product->getId(), $product->getVersion())
1014+
->addAction(
1015+
ProductSetMetaKeywordsAction::of()->setMetaKeywords(
1016+
LocalizedString::ofLangAndText('en', $metaKeywords)
1017+
)->setStaged(false)
1018+
)
1019+
;
1020+
$response = $request->executeWithClient($this->getClient());
1021+
$result = $request->mapResponse($response);
1022+
$this->deleteRequest->setVersion($result->getVersion());
1023+
1024+
$this->assertInstanceOf(Product::class, $result);
1025+
$this->assertSame(
1026+
$metaKeywords,
1027+
$result->getMasterData()->getCurrent()->getMetaKeywords()->en
1028+
);
1029+
$this->assertNotSame($product->getVersion(), $result->getVersion());
1030+
}
1031+
9571032
public function testRevertStagedChanges()
9581033
{
9591034
$draft = $this->getDraft('revert');

tests/unit/Request/GenericActionTest.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -394,15 +394,15 @@ public function actionFieldProvider()
394394
],
395395
[
396396
ProductSetMetaTitleAction::class,
397-
['action', 'metaTitle']
397+
['action', 'metaTitle', 'staged']
398398
],
399399
[
400400
ProductSetMetaDescriptionAction::class,
401-
['action', 'metaDescription']
401+
['action', 'metaDescription', 'staged']
402402
],
403403
[
404404
ProductSetMetaKeywordsAction::class,
405-
['action', 'metaKeywords']
405+
['action', 'metaKeywords', 'staged']
406406
],
407407
[
408408
ProductSetPriceCustomFieldAction::class,

0 commit comments

Comments
 (0)