Skip to content

Commit

Permalink
Add DeleteCommandSet factories
Browse files Browse the repository at this point in the history
  • Loading branch information
joshdifabio committed Oct 31, 2017
1 parent d963bfe commit 6de68d1
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/AttributeDataSet.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<?php
namespace SnowIO\FredhopperDataModel;

use SnowIO\FredhopperDataModel\Command\DeleteAttributeCommand;
use SnowIO\FredhopperDataModel\Command\SaveAttributeCommand;

final class AttributeDataSet implements \IteratorAggregate
Expand All @@ -21,6 +22,13 @@ public function mapToSaveCommands(float $timestamp): array
}, $this->items);
}

public function mapToDeleteCommands(float $timestamp): array
{
return \array_map(function (AttributeData $attributeData) use ($timestamp) {
return DeleteAttributeCommand::of($attributeData->getId())->withTimestamp($timestamp);
}, $this->items);
}

private static function getKey(AttributeData $attributeData): string
{
return $attributeData->getId();
Expand Down
9 changes: 9 additions & 0 deletions src/AttributeOptionSet.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
declare(strict_types=1);
namespace SnowIO\FredhopperDataModel;

use SnowIO\FredhopperDataModel\Command\DeleteAttributeOptionCommand;
use SnowIO\FredhopperDataModel\Command\SaveAttributeOptionCommand;

final class AttributeOptionSet implements \IteratorAggregate
Expand All @@ -23,6 +24,14 @@ public function mapToSaveCommands(float $timestamp): array
}, $this->items);
}

public function mapToDeleteCommands(float $timestamp): array
{
return \array_map(function (AttributeOption $attributeOption) use ($timestamp) {
return DeleteAttributeOptionCommand::of($attributeOption->getAttributeId(), $attributeOption->getValueId())
->withTimestamp($timestamp);
}, $this->items);
}

private static function getKey(AttributeOption $attributeOption): string
{
return "{$attributeOption->getAttributeId()}-{$attributeOption->getValueId()}";
Expand Down
8 changes: 8 additions & 0 deletions src/CategoryDataSet.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<?php
namespace SnowIO\FredhopperDataModel;

use SnowIO\FredhopperDataModel\Command\DeleteCategoryCommand;
use SnowIO\FredhopperDataModel\Command\SaveCategoryCommand;

final class CategoryDataSet implements \IteratorAggregate
Expand All @@ -21,6 +22,13 @@ public function mapToSaveCommands(float $timestamp): array
}, $this->items);
}

public function mapToDeleteCommands(float $timestamp): array
{
return \array_map(function (CategoryData $categoryData) use ($timestamp) {
return DeleteCategoryCommand::of($categoryData->getId())->withTimestamp($timestamp);
}, $this->items);
}

private static function getKey(CategoryData $categoryData): string
{
return $categoryData->getId();
Expand Down
8 changes: 8 additions & 0 deletions src/ProductDataSet.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<?php
namespace SnowIO\FredhopperDataModel;

use SnowIO\FredhopperDataModel\Command\DeleteProductCommand;
use SnowIO\FredhopperDataModel\Command\SaveProductCommand;

final class ProductDataSet implements \IteratorAggregate
Expand All @@ -21,6 +22,13 @@ public function mapToSaveCommands(float $timestamp): array
}, $this->items);
}

public function mapToDeleteCommands(float $timestamp): array
{
return \array_map(function (ProductData $productData) use ($timestamp) {
return DeleteProductCommand::of($productData->getId())->withTimestamp($timestamp);
}, $this->items);
}

private static function getKey(ProductData $productData): string
{
return $productData->getId();
Expand Down
8 changes: 8 additions & 0 deletions src/VariantDataSet.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<?php
namespace SnowIO\FredhopperDataModel;

use SnowIO\FredhopperDataModel\Command\DeleteVariantCommand;
use SnowIO\FredhopperDataModel\Command\SaveVariantCommand;

final class VariantDataSet implements \IteratorAggregate
Expand All @@ -21,6 +22,13 @@ public function mapToSaveCommands(float $timestamp): array
}, $this->items);
}

public function mapToDeleteCommands(float $timestamp): array
{
return \array_map(function (VariantData $variantData) use ($timestamp) {
return DeleteVariantCommand::of($variantData->getId())->withTimestamp($timestamp);
}, $this->items);
}

private static function getKey(VariantData $variantData): string
{
return $variantData->getId();
Expand Down

0 comments on commit 6de68d1

Please sign in to comment.