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

Commit

Permalink
feat(ProductSearch): add matching variant to ProductVariant object
Browse files Browse the repository at this point in the history
  • Loading branch information
Jens Schulze committed Dec 29, 2015
1 parent b7ee577 commit 2e336df
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/Model/Product/ProductVariant.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@
* @method ProductVariant setAvailability(LocalizedString $availability = null)
* @method Price getPrice()
* @method ProductVariant setPrice(Price $price = null)
* @method bool getIsMatchingVariant()
* @method ProductVariant setIsMatchingVariant(bool $isMatchingVariant = null)
*/
class ProductVariant extends JsonObject
{
Expand All @@ -42,6 +44,7 @@ public function fieldDefinitions()
'attributes' => [static::TYPE => '\Commercetools\Core\Model\Common\AttributeCollection'],
'images' => [static::TYPE => '\Commercetools\Core\Model\Common\ImageCollection'],
'availability' => [static::TYPE => '\Commercetools\Core\Model\Common\LocalizedString'],
'isMatchingVariant' => [static::TYPE => 'bool']
];
}
}
9 changes: 9 additions & 0 deletions src/Model/Product/ProductVariantCollection.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,19 +17,23 @@ class ProductVariantCollection extends Collection
{
const ID = 'id';
const SKU = 'sku';
const MATCHING = 'isMatchingVariant';
protected $type = '\Commercetools\Core\Model\Product\ProductVariant';

protected function indexRow($offset, $row)
{
if ($row instanceof ProductVariant) {
$id = $row->getId();
$sku = $row->getSku();
$matching = $row->getIsMatchingVariant();
} else {
$id = isset($row[static::ID])? $row[static::ID] : null;
$sku = isset($row[static::SKU])? $row[static::SKU] : null;
$matching = isset($row[static::MATCHING])? $row[static::MATCHING] : false;
}
$this->addToIndex(static::ID, $offset, $id);
$this->addToIndex(static::SKU, $offset, $sku);
$this->addToIndex(static::MATCHING, $offset, $matching);
}

/**
Expand All @@ -49,4 +53,9 @@ public function getBySku($id)
{
return $this->getBy(static::SKU, $id);
}

public function getMatchingVariant()
{
return $this->getBy(static::MATCHING, true);
}
}

0 comments on commit 2e336df

Please # to comment.