From 6de68d1bded14dfee9d48a2550e85d61924a8624 Mon Sep 17 00:00:00 2001 From: Josh Di Fabio Date: Tue, 31 Oct 2017 14:53:06 +0000 Subject: [PATCH] Add DeleteCommandSet factories --- src/AttributeDataSet.php | 8 ++++++++ src/AttributeOptionSet.php | 9 +++++++++ src/CategoryDataSet.php | 8 ++++++++ src/ProductDataSet.php | 8 ++++++++ src/VariantDataSet.php | 8 ++++++++ 5 files changed, 41 insertions(+) diff --git a/src/AttributeDataSet.php b/src/AttributeDataSet.php index 4d876ce..0ef93ee 100644 --- a/src/AttributeDataSet.php +++ b/src/AttributeDataSet.php @@ -1,6 +1,7 @@ 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(); diff --git a/src/AttributeOptionSet.php b/src/AttributeOptionSet.php index 8b7a640..8834daf 100644 --- a/src/AttributeOptionSet.php +++ b/src/AttributeOptionSet.php @@ -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 @@ -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()}"; diff --git a/src/CategoryDataSet.php b/src/CategoryDataSet.php index 1563768..850e576 100644 --- a/src/CategoryDataSet.php +++ b/src/CategoryDataSet.php @@ -1,6 +1,7 @@ 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(); diff --git a/src/ProductDataSet.php b/src/ProductDataSet.php index ff734f6..2e6557c 100644 --- a/src/ProductDataSet.php +++ b/src/ProductDataSet.php @@ -1,6 +1,7 @@ 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(); diff --git a/src/VariantDataSet.php b/src/VariantDataSet.php index 207e4a3..fd6446d 100644 --- a/src/VariantDataSet.php +++ b/src/VariantDataSet.php @@ -1,6 +1,7 @@ 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();