Skip to content

Commit

Permalink
Merge pull request #249 from Nosto/release/4.0.6
Browse files Browse the repository at this point in the history
Release/4.0.6
  • Loading branch information
olsi-qose authored Oct 28, 2019
2 parents 2ab9500 + 233d1e3 commit f5cd092
Show file tree
Hide file tree
Showing 7 changed files with 369 additions and 18 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
All notable changes to this project will be documented in this file.
This project adheres to Semantic Versioning (http://semver.org/).

## 4.0.6
* Support faceting and pagination in Category Merchandising query

## 4.0.5
* Introduce new exception types for product building failures

Expand Down
164 changes: 164 additions & 0 deletions src/Operation/Recommendation/AbstractFilters.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,164 @@
<?php
/**
* Copyright (c) 2019, Nosto Solutions Ltd
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* 3. Neither the name of the copyright holder nor the names of its contributors
* may be used to endorse or promote products derived from this software without
* specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* @author Nosto Solutions Ltd <[email protected]>
* @copyright 2019 Nosto Solutions Ltd
* @license http://opensource.org/licenses/BSD-3-Clause BSD 3-Clause
*
*/

namespace Nosto\Operation\Recommendation;

abstract class AbstractFilters
{
/** @var string[] */
public $brands = [];

/** @var string[] */
public $categories = [];

/** @var array */
public $customFields = [];

/** @var boolean */
public $discounted;

/** @var string[] */
public $productIds;

/** @var string */
public $search;

/** @var string[] */
public $tag1;

/** @var string[] */
public $tag2;

/** @var string[] */
public $tag3;

/**
* @param string[] $brands
*/
public function setBrands(array $brands)
{
$this->brands = array_merge($this->brands, $brands);
}

/**
* @param string[] $categories
*/
public function setCategories(array $categories)
{
$this->categories = array_merge($this->categories, $categories);
}

/**
* @param string $attribute
* @param array $values
*/
public function setCustomFields($attribute, array $values)
{
foreach ($this->customFields as $customField) {
if ($customField['attribute'] === $attribute) {
$customField['values'] = array_merge($customField['values'], $values);
}
}

$this->customFields[] = [
'attribute' => $attribute,
'values' => $values
];
}

/**
* @param boolean $discounted
*/
public function setDiscounted($discounted)
{
$this->discounted = $discounted;
}

/**
* @param string[] $productIds
*/
public function setProductIds(array $productIds)
{
$this->productIds = array_merge($this->productIds, $productIds);
}

/**
* @param string $search
*/
public function setSearch($search)
{
$this->search = $search;
}

/**
* @param string[] $tag1
*/
public function setTag1(array $tag1)
{
$this->tag1 = $tag1;
}

/**
* @param string[] $tag2
*/
public function setTag2(array $tag2)
{
$this->tag2 = $tag2;
}

/**
* @param string[] $tag3
*/
public function setTag3(array $tag3)
{
$this->tag3 = $tag3;
}

/**
* @return array
* @suppress PhanTypeSuspiciousNonTraversableForeach
*/
public function toArray()
{
$array = [];
foreach ($this as $key => $value) {
if ($value !== null) {
$array = array_merge($array, [$key => $value]);
}
}
return $array;
}
}
46 changes: 34 additions & 12 deletions src/Operation/Recommendation/CategoryMerchandising.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,23 @@ class CategoryMerchandising extends AbstractRecommendation
/** @var string $category */
private $category;

/** @var IncludeFilters */
private $includeFilters;

/** @var ExcludeFilters */
private $excludeFilters;

/** @var int */
private $skipPages;

/**
* CategoryMerchandising constructor.
* @param AccountInterface $account
* @param $customerId
* @param $category
* @param $skipPages
* @param IncludeFilters $includeFilters
* @param ExcludeFilters $excludeFilters
* @param string $activeDomain
* @param string $customerBy
* @param bool $previewMode
Expand All @@ -57,12 +69,18 @@ public function __construct(
AccountInterface $account,
$customerId,
$category,
$skipPages,
IncludeFilters $includeFilters,
ExcludeFilters $excludeFilters,
$activeDomain = '',
$customerBy = self::IDENTIFIER_BY_CID,
$previewMode = false,
$limit = self::LIMIT
) {
$this->category = $category;
$this->skipPages = $skipPages;
$this->includeFilters = $includeFilters;
$this->excludeFilters = $excludeFilters;
parent::__construct($account, $customerId, $activeDomain, $customerBy, $previewMode, $limit);
}

Expand All @@ -73,28 +91,29 @@ public function getQuery()
{
$query =
<<<QUERY
mutation(
query(
\$customerId: String!,
\$category: String!,
\$limit: Int!,
\$preview: Boolean!,
\$by: LookupParams!
\$by: LookupParams!,
\$skipPages: Int,
\$includeFilters: InputIncludeParams,
\$excludeFilters: InputFilterParams
) {
updateSession (
session (
id: \$customerId,
by: \$by,
params: {
event: {
type: VIEWED_CATEGORY
target: \$category
}
}) {
by: \$by,
) {
id
recos (preview: \$preview, image: VERSION_10_MAX_SQUARE) {
category (
category: \$category
minProducts: 1
maxProducts: \$limit
maxProducts: \$limit,
skipPages: \$skipPages,
include: \$includeFilters,
exclude: \$excludeFilters
) {
primary {
productId
Expand Down Expand Up @@ -124,7 +143,10 @@ public function getVariables()
'category' => $this->category,
'limit' => $this->limit,
'preview' => $this->previewMode,
'by' => $this->customerBy
'by' => $this->customerBy,
'skipPages' => $this->skipPages,
'includeFilters' => $this->includeFilters->toArray(),
'excludeFilters' => $this->excludeFilters->toArray()
];

return $variables;
Expand Down
42 changes: 42 additions & 0 deletions src/Operation/Recommendation/ExcludeFilters.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<?php
/**
* Copyright (c) 2019, Nosto Solutions Ltd
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* 3. Neither the name of the copyright holder nor the names of its contributors
* may be used to endorse or promote products derived from this software without
* specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* @author Nosto Solutions Ltd <[email protected]>
* @copyright 2019 Nosto Solutions Ltd
* @license http://opensource.org/licenses/BSD-3-Clause BSD 3-Clause
*
*/

namespace Nosto\Operation\Recommendation;

class ExcludeFilters extends AbstractFilters
{

}
Loading

0 comments on commit f5cd092

Please sign in to comment.