Skip to content

Commit

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

use SnowIO\FredhopperDataModel\Command\SaveAttributeCommand;

final class AttributeDataSet implements \IteratorAggregate
{
use SetTrait;
Expand All @@ -12,6 +14,13 @@ public function with(AttributeData $attributeData): self
return $result;
}

public function mapToSaveCommands(int $timestamp): array
{
return \array_map(function (AttributeData $attributeData) use ($timestamp) {
return SaveAttributeCommand::of($attributeData)->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,8 @@
declare(strict_types=1);
namespace SnowIO\FredhopperDataModel;

use SnowIO\FredhopperDataModel\Command\SaveAttributeOptionCommand;

final class AttributeOptionSet implements \IteratorAggregate
{
use SetTrait;
Expand All @@ -14,6 +16,13 @@ public function with(AttributeOption $attributeOption): self
return $result;
}

public function mapToSaveCommands(int $timestamp): array
{
return \array_map(function (AttributeOption $attributeOption) use ($timestamp) {
return SaveAttributeOptionCommand::of($attributeOption)->withTimestamp($timestamp);
}, $this->items);
}

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

use SnowIO\FredhopperDataModel\Command\SaveCategoryCommand;

final class CategoryDataSet implements \IteratorAggregate
{
use SetTrait;
Expand All @@ -12,6 +14,13 @@ public function with(CategoryData $categoryData): self
return $result;
}

public function mapToSaveCommands(int $timestamp): array
{
return \array_map(function (CategoryData $categoryData) use ($timestamp) {
return SaveCategoryCommand::of($categoryData)->withTimestamp($timestamp);
}, $this->items);
}

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

use SnowIO\FredhopperDataModel\Command\SaveProductCommand;

final class ProductDataSet implements \IteratorAggregate
{
use SetTrait;
Expand All @@ -12,6 +14,13 @@ public function with(ProductData $productData): self
return $result;
}

public function mapToSaveCommands(int $timestamp): array
{
return \array_map(function (ProductData $productData) use ($timestamp) {
return SaveProductCommand::of($productData)->withTimestamp($timestamp);
}, $this->items);
}

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

use SnowIO\FredhopperDataModel\Command\SaveVariantCommand;

final class VariantDataSet implements \IteratorAggregate
{
use SetTrait;
Expand All @@ -12,6 +14,13 @@ public function with(VariantData $variantData): self
return $result;
}

public function mapToSaveCommands(int $timestamp): array
{
return \array_map(function (VariantData $variantData) use ($timestamp) {
return SaveVariantCommand::of($variantData)->withTimestamp($timestamp);
}, $this->items);
}

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

0 comments on commit 4e85082

Please sign in to comment.