diff --git a/src/Model/Category/CategoryDraft.php b/src/Model/Category/CategoryDraft.php index a1b85832af..ad64afa0ea 100644 --- a/src/Model/Category/CategoryDraft.php +++ b/src/Model/Category/CategoryDraft.php @@ -28,6 +28,12 @@ * @method CategoryDraft setExternalId(string $externalId = null) * @method CustomFieldObjectDraft getCustom() * @method CategoryDraft setCustom(CustomFieldObjectDraft $custom = null) + * @method LocalizedString getMetaDescription() + * @method CategoryDraft setMetaDescription(LocalizedString $metaDescription = null) + * @method LocalizedString getMetaTitle() + * @method CategoryDraft setMetaTitle(LocalizedString $metaTitle = null) + * @method LocalizedString getMetaKeywords() + * @method CategoryDraft setMetaKeywords(LocalizedString $metaKeywords = null) */ class CategoryDraft extends JsonObject { diff --git a/src/Model/Common/AbstractJsonDeserializeObject.php b/src/Model/Common/AbstractJsonDeserializeObject.php index 7ebc92e7a2..35092fa1a9 100644 --- a/src/Model/Common/AbstractJsonDeserializeObject.php +++ b/src/Model/Common/AbstractJsonDeserializeObject.php @@ -29,7 +29,7 @@ public function __construct(array $data = [], $context = null) { $this->setContext($context); if (!is_null($data)) { - $this->rawData = $data; + $this->rawData = $this->typeData = $data; } } @@ -158,7 +158,7 @@ protected function getTyped($offset) */ public function setRawData(array $rawData) { - $this->rawData = $rawData; + $this->rawData = $this->typeData = $rawData; return $this; } @@ -190,8 +190,7 @@ public function jsonSerialize() */ public function toArray() { - $data = array_merge($this->rawData, $this->typeData); - $data = array_filter($data, function ($value) { + $data = array_filter($this->typeData, function ($value) { return !is_null($value); }); $data = array_map( diff --git a/src/Model/Common/Collection.php b/src/Model/Common/Collection.php index 6f9bd5a5dc..b938fbf1c7 100644 --- a/src/Model/Common/Collection.php +++ b/src/Model/Common/Collection.php @@ -142,7 +142,7 @@ protected function initialize($offset) */ public function toArray() { - $values = $this->rawData; + $values = []; foreach ($this->typeData as $key => $value) { if ($value instanceof JsonDeserializeInterface) { $values[$key] = $value->toArray(); diff --git a/tests/unit/Model/Common/CollectionTest.php b/tests/unit/Model/Common/CollectionTest.php index f20fe87acd..7259b9fd99 100644 --- a/tests/unit/Model/Common/CollectionTest.php +++ b/tests/unit/Model/Common/CollectionTest.php @@ -213,7 +213,7 @@ public function testGetReturnRaw() [[new \DateTime('2015-01-01')]] ); $collection->setType('\DateTime'); - $this->assertSame('2015-01-01', $collection->getAt(0)->format('Y-m-d')); + $this->assertSame('2015-01-01', $collection->current()->format('Y-m-d')); } public function testSetAt() @@ -224,4 +224,15 @@ public function testSetAt() $this->assertInstanceOf('\DateTime', $collection[1]); } + + public function testAdd() + { + $collection = Collection::fromArray([ + ['currencyCode' => 'EUR', 'centAmount' => 100], + ]); + $collection->setType('\Commercetools\Core\Model\Common\Money'); + $collection->add(Money::ofCurrencyAndAmount('USD', 110)); + + $this->assertCount(2, $collection); + } }