Skip to content

Commit

Permalink
Merge pull request #346 from Nosto/release/7.0.0
Browse files Browse the repository at this point in the history
Release/7.0.0
  • Loading branch information
dairbuirabass committed Feb 21, 2023
2 parents a9f7588 + db29583 commit 0b978ca
Show file tree
Hide file tree
Showing 7 changed files with 94 additions and 149 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@
All notable changes to this project will be documented in this file.
This project adheres to Semantic Versioning (http://semver.org/).

### 7.0.0
* Update category model to use relevant fields
* Create category collection for batched operations

### 6.2.0
* Remove DeleteProduct operation

Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "nosto/php-sdk",
"version": "6.2.0",
"version": "7.0.0",
"description": "PHP SDK for developing Nosto modules for e-commerce platforms",
"license": "BSD-3-Clause",
"require-dev": {
Expand Down
124 changes: 20 additions & 104 deletions src/Model/Category.php → src/Model/Category/Category.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
*
*/

namespace Nosto\Model;
namespace Nosto\Model\Category;

use Nosto\Mixins\HtmlEncoderTrait;
use Nosto\Types\CategoryInterface;
Expand All @@ -52,11 +52,6 @@ class Category extends AbstractObject implements
{
use HtmlEncoderTrait;

/**
* @var string categoryString
*/
private $categoryString;

/**
* @var string id
*/
Expand All @@ -68,50 +63,19 @@ class Category extends AbstractObject implements
private $parentId;

/**
* @var string name
* @var string title
*/
private $name;
private $title;

/**
* @var string url
*/
private $url;

/**
* @var string imageUrl
*/
private $imageUrl;

/**
* @var string thumbnailImageUrl
*/
private $thumbnailImageUrl;

/**
* @var bool
* @var string path
*/
private $visibleInMenu;

/**
* @var string level
*/
private $level;

/**
* @return string
*/
public function getCategoryString()
{
return $this->categoryString;
}

/**
* @param string $categoryString
*/
public function setCategoryString($categoryString)
{
$this->categoryString = $categoryString;
}
private $path;

/**
* @return string
Expand Down Expand Up @@ -148,97 +112,49 @@ public function setParentId($parentId)
/**
* @return string
*/
public function getName()
public function getTitle()
{
return $this->name;
return $this->title;
}

/**
* @param string $name
* @param string $title
*/
public function setName($name)
public function setTitle($title)
{
$this->name = $name;
$this->title = $title;
}

/**
* @return string
*/
public function getUrl()
public function getPath()
{
return $this->url;
return $this->path;
}

/**
* @param string $url
* @param string $path
*/
public function setUrl($url)
public function setPath($path)
{
$this->url = $url;
$this->path = $path;
}

/**
* @return string
*/
public function getImageUrl()
{
return $this->imageUrl;
}

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

/**
* @return string
*/
public function getThumbnailImageUrl()
{
return $this->thumbnailImageUrl;
}

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

/**
* @return bool
*/
public function getVisibleInMenu()
{
return $this->visibleInMenu;
}

/**
* @param $visibleInMenu
*/
public function setVisibleInMenu($visibleInMenu)
{
$this->visibleInMenu = $visibleInMenu ? true : false;
}

/**
* @return string
*/
public function getLevel()
public function getUrl()
{
return $this->level;
return $this->url;
}

/**
* @param int|string $level
* @param string $url
*/
public function setLevel($level)
public function setUrl($url)
{
$this->level = $level;
$this->url = $url;
}

/**
Expand Down
56 changes: 56 additions & 0 deletions src/Model/Category/CategoryCollection.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
<?php
/**
* Copyright (c) 2023, 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 <contact@nosto.com>
* @copyright 2020 Nosto Solutions Ltd
* @license http://opensource.org/licenses/BSD-3-Clause BSD 3-Clause
*
*/

namespace Nosto\Model\Category;

use Nosto\Model\AbstractCollection;
use Nosto\Types\CategoryInterface;

/**
* Collection class to store a collection of categories
*/
class CategoryCollection extends AbstractCollection
{
/**
* Appends a product to the collection of categories
*
* @param CategoryInterface $category the category to append
*/
public function append(CategoryInterface $category)
{
$this->var[] = $category;
}
}
40 changes: 6 additions & 34 deletions src/Types/CategoryInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,6 @@

interface CategoryInterface
{
/**
* The full path of the category
*
* @return string
*/
public function getCategoryString();

/**
* Get the id of the category
*
Expand All @@ -60,44 +53,23 @@ public function getId();
public function getParentId();

/**
* Get the name of the category
* Get the title of the category
*
* @return string
*/
public function getName();

/**
* Get the url
*
* @return string
*/
public function getUrl();
public function getTitle();

/**
* Get the image url
*
* @return string
*/
public function getImageUrl();

/**
* Get the image thumbnail url
* The full path of the category
*
* @return string
*/
public function getThumbnailImageUrl();
public function getPath();

/**
* Get the visibleInMenu var
*
* @return bool
*/
public function getVisibleInMenu();

/**
* Get the level
* Get the url
*
* @return string
*/
public function getLevel();
public function getUrl();
}
11 changes: 4 additions & 7 deletions tests/_support/MockCategory.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,19 +36,16 @@

namespace Nosto\Test\Support;

use Nosto\Model\Category;
use Nosto\Model\Category\Category;

class MockCategory extends Category
{
public function __construct()
{
$this->setId("10");
$this->setUrl('http://magento1.dev.nos.to/women/women-new-arrivals.html');
$this->setLevel('3');
$this->setVisibleInMenu(true);
$this->setImageUrl('http://magento1.dev.nos.to/media/catalog/category/plp-w-newarrivals_1.jpg');
$this->setName('New Arrivals');
$this->setParentId(4);
$this->setCategoryString('/Women/New Arrivals');
$this->setTitle('New Arrivals');
$this->setPath('/Women/New Arrivals');
$this->setUrl('http://magento1.dev.nos.to/women/women-new-arrivals.html');
}
}
6 changes: 3 additions & 3 deletions tests/unit/Helper/HtmlMarkupSerializationHelperTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ public function testCategory()
{
$object = new MockCategory();
$markup = $object->toHtml();
$this->assertEquals('<div class="notranslate" style="display:none"> <span class="nosto_category" style="display:none"> <span class="category_string">/Women/New Arrivals</span> <span class="id">10</span> <span class="parent_id">4</span> <span class="name">New Arrivals</span> <span class="url">http://magento1.dev.nos.to/women/women-new-arrivals.html</span> <span class="image_url">http://magento1.dev.nos.to/media/catalog/category/plp-w-newarrivals_1.jpg</span> <span class="visible_in_menu">1</span> <span class="level">3</span> </span></div>', self::stripLineBreaks($markup));
$this->assertEquals('<div class="notranslate" style="display:none"> <span class="nosto_category" style="display:none"> <span class="id">10</span> <span class="parent_id">4</span> <span class="title">New Arrivals</span> <span class="url">http://magento1.dev.nos.to/women/women-new-arrivals.html</span> <span class="path">/Women/New Arrivals</span> </span></div>', self::stripLineBreaks($markup));
}

/**
Expand All @@ -82,9 +82,9 @@ public function testCategory()
public function testCategoryWithHtml()
{
$object = new MockCategory();
$object->setName('<p>Name with html</p>');
$object->setTitle('<p>Name with html</p>');
$markup = $object->toHtml();
$this->assertEquals('<div class="notranslate" style="display:none"> <span class="nosto_category" style="display:none"> <span class="category_string">/Women/New Arrivals</span> <span class="id">10</span> <span class="parent_id">4</span> <span class="name">&lt;p&gt;Name with html&lt;/p&gt;</span> <span class="url">http://magento1.dev.nos.to/women/women-new-arrivals.html</span> <span class="image_url">http://magento1.dev.nos.to/media/catalog/category/plp-w-newarrivals_1.jpg</span> <span class="visible_in_menu">1</span> <span class="level">3</span> </span></div>', self::stripLineBreaks($markup));
$this->assertEquals('<div class="notranslate" style="display:none"> <span class="nosto_category" style="display:none"> <span class="id">10</span> <span class="parent_id">4</span> <span class="title">&lt;p&gt;Name with html&lt;/p&gt;</span> <span class="url">http://magento1.dev.nos.to/women/women-new-arrivals.html</span> <span class="path">/Women/New Arrivals</span> </span></div>', self::stripLineBreaks($markup));
}

/**
Expand Down

0 comments on commit 0b978ca

Please sign in to comment.