Skip to content

Commit

Permalink
Merge pull request Nosto#204 from Nosto/release/3.13.0
Browse files Browse the repository at this point in the history
Release/3.13.0
  • Loading branch information
supercid committed Apr 8, 2019
2 parents 4ab720d + fb1147e commit 980fdee
Show file tree
Hide file tree
Showing 10 changed files with 93 additions and 30 deletions.
4 changes: 3 additions & 1 deletion .github/pull-request-template.md
Expand Up @@ -30,4 +30,6 @@
- [ ] I have correctly labeled this pull request.
- [ ] I have linked the corresponding issue in this description.
- [ ] I have updated the corresponding Jira ticket.
- [ ] I have requested a review from at least 2 reviewers
- [ ] I have requested a review from at least 2 reviewers
- [ ] I have checked the base branch of this pull request
- [ ] I have checked my code for any possible security vulnerabilities
7 changes: 5 additions & 2 deletions CHANGELOG.md
Expand Up @@ -2,8 +2,11 @@
All notable changes to this project will be documented in this file.
This project adheres to Semantic Versioning (http://semver.org/).

### 3.12.1
* Fix GraphQL url
## 3.13.0
* Add date published to product interface and product object

## 3.12.1
* Fix GraphQL URL

## 3.12.0
* Add `APPS` token as a default token to be generated on account creation
Expand Down
6 changes: 3 additions & 3 deletions src/Helper/HtmlMarkupSerializationHelper.php
Expand Up @@ -83,7 +83,7 @@ public static function objectToMarkup($object, $key, $spaces = 0, $indent = 2)
}

/**
* Servialize the object to html
* Serialize the object to html
*
* @param mixed $object to be serialized
* @param string $key $key the html element class
Expand All @@ -94,8 +94,8 @@ public static function objectToMarkup($object, $key, $spaces = 0, $indent = 2)
*/
private static function toHtml($object, $key, $spaces = 0, $indent = 2, $style = null)
{
if (!$object && $object !== 0 && $object !== '0' && $object !== false && $object !== 0.00) {
return "";
if (SerializationHelper::isNull($object)) {
return '';
}

if ($object instanceof SanitizableInterface) {
Expand Down
14 changes: 14 additions & 0 deletions src/Helper/SerializationHelper.php
Expand Up @@ -95,6 +95,9 @@ private static function toArray($object)
}
$key = self::toSnakeCase($key);
$value = $object->$getter();
if (self::isNull($value)) {
continue;
}
if ($value instanceof \Iterator) {
$value = iterator_to_array($value);
}
Expand Down Expand Up @@ -185,4 +188,15 @@ public static function toSnakeCase($input)
}
return implode('_', $ret);
}

/**
* Check for multiple types of invalid values in a variable and returns.
*
* @param $var
* @return bool
*/
public static function isNull($var)
{
return (!$var && $var !== 0 && $var !== '0' && $var !== false && $var !== 0.00);
}
}
31 changes: 31 additions & 0 deletions src/Object/Product/Product.php
Expand Up @@ -48,6 +48,7 @@
use Nosto\Types\Product\VariationInterface;
use Nosto\Types\SanitizableInterface;
use Nosto\Types\ValidatableInterface;
use Nosto\Helper\DateHelper;

/**
* Model for product information. This is used when compiling the info about a
Expand Down Expand Up @@ -244,6 +245,12 @@ class Product extends AbstractObject implements
*/
private $customFields = array();

/**
* Product publication date in shop
* @var string
*/
private $datePublished;

public function __construct()
{
$this->skus = new SkuCollection();
Expand Down Expand Up @@ -616,6 +623,30 @@ public function setBrand($brand)
$this->brand = $brand;
}

/**
* @inheritDoc
*/
public function getDatePublished()
{
return $this->datePublished;
}

/**
* Sets the product publication date in the shop
* in the Y-m-d format.
*
* @param $datePublished
* @throws NostoException
*/
public function setDatePublished($datePublished)
{
try {
$this->datePublished = DateHelper::format($datePublished);
} catch (\Exception $e) {
throw new NostoException($e->getMessage());
}
}

/**
* @inheritdoc
*/
Expand Down
7 changes: 7 additions & 0 deletions src/Types/Product/ProductInterface.php
Expand Up @@ -147,6 +147,13 @@ public function getDescription();
*/
public function getBrand();

/**
* Returns the product publication date in the shop.
*
* @return string the date in format "Y-m-d".
*/
public function getDatePublished();

/**
* Returns the product variation id.
*
Expand Down
1 change: 1 addition & 0 deletions tests/_support/MockProduct.php
Expand Up @@ -68,6 +68,7 @@ public function __construct()
$this->setCondition("Used");
$this->setGtin("gtin");
$this->setGoogleCategory("All");
$this->setDatePublished('2013-03-05T08:25:10+02:00');
}

public function __get($name)
Expand Down
15 changes: 10 additions & 5 deletions tests/unit/Helper/DateHelperTest.php
Expand Up @@ -49,9 +49,14 @@ class DateHelperTest extends Test
*/
public function testHelperFormatting()
{
$this->assertEquals("2009-01-31", DateHelper::format("2009-01-31"));
$this->assertEquals("2016-01-01", DateHelper::format("01.01.2016"));
$this->assertEquals("1970-01-01", DateHelper::format("01.24.2016"));
$this->assertEquals("1970-01-01", DateHelper::format(null));
$this->assertEquals('2009-01-31', DateHelper::format('2009-01-31'));
$this->assertEquals('2016-01-01', DateHelper::format('01.01.2016'));
$this->assertEquals('1970-01-01', DateHelper::format('01.24.2016'));
$this->assertEquals('1970-01-01', DateHelper::format(null));
$this->assertEquals('2013-03-05', DateHelper::format('2013-03-05T08:25:10+02:00'));
$this->assertEquals('2013-03-05', DateHelper::format('5-3-2013'));
$this->assertEquals('2015-07-13', DateHelper::format('15-7-13'));
$this->assertEquals('1970-01-01', DateHelper::format('5-13-2013'));
$this->assertEquals('1970-01-01', DateHelper::format('15-17-3'));
}
}
}

0 comments on commit 980fdee

Please sign in to comment.