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

Commit

Permalink
feat(ShoppingList): support shopping list
Browse files Browse the repository at this point in the history
Closes #287
  • Loading branch information
Jens Schulze committed Feb 7, 2017
1 parent c286e78 commit d8fdf4d
Show file tree
Hide file tree
Showing 24 changed files with 1,141 additions and 0 deletions.
65 changes: 65 additions & 0 deletions src/Model/ShoppingList/LineItem.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
<?php
/**
* @author @jayS-de <jens.schulze@commercetools.de>
*/

namespace Commercetools\Core\Model\ShoppingList;

use Commercetools\Core\Model\Common\JsonObject;
use Commercetools\Core\Model\ProductType\ProductTypeReference;
use Commercetools\Core\Model\CustomField\CustomFieldObject;
use Commercetools\Core\Model\Common\DateTimeDecorator;
use Commercetools\Core\Model\Common\LocalizedString;
use Commercetools\Core\Model\Product\ProductVariant;

/**
* @package Commercetools\Core\Model\ShoppingList
*
* @method string getId()
* @method LineItem setId(string $id = null)
* @method string getProductId()
* @method LineItem setProductId(string $productId = null)
* @method int getVariantId()
* @method LineItem setVariantId(int $variantId = null)
* @method ProductTypeReference getProductType()
* @method LineItem setProductType(ProductTypeReference $productType = null)
* @method int getQuantity()
* @method LineItem setQuantity(int $quantity = null)
* @method CustomFieldObject getCustom()
* @method LineItem setCustom(CustomFieldObject $custom = null)
* @method DateTimeDecorator getAddedAt()
* @method LineItem setAddedAt(\DateTime $addedAt = null)
* @method LocalizedString getName()
* @method LineItem setName(LocalizedString $name = null)
* @method DateTimeDecorator getDeactivatedAt()
* @method LineItem setDeactivatedAt(\DateTime $deactivatedAt = null)
* @method LocalizedString getProductSlug()
* @method LineItem setProductSlug(LocalizedString $productSlug = null)
* @method ProductVariant getVariant()
* @method LineItem setVariant(ProductVariant $variant = null)
*/
class LineItem extends JsonObject
{
public function fieldDefinitions()
{
return [
'id' => [static::TYPE => 'string'],
'productId' => [static::TYPE => 'string'],
'variantId' => [static::TYPE => 'int'],
'productType' => [static::TYPE => '\Commercetools\Core\Model\ProductType\ProductTypeReference'],
'quantity' => [static::TYPE => 'int'],
'custom' => [static::TYPE => '\Commercetools\Core\Model\CustomField\CustomFieldObject'],
'addedAt' => [
static::TYPE => '\DateTime',
static::DECORATOR => '\Commercetools\Core\Model\Common\DateTimeDecorator'
],
'name' => [static::TYPE => '\Commercetools\Core\Model\Common\LocalizedString'],
'deactivatedAt' => [
static::TYPE => '\DateTime',
static::DECORATOR => '\Commercetools\Core\Model\Common\DateTimeDecorator'
],
'productSlug' => [static::TYPE => '\Commercetools\Core\Model\Common\LocalizedString'],
'variant' => [static::TYPE => '\Commercetools\Core\Model\Product\ProductVariant'],
];
}
}
21 changes: 21 additions & 0 deletions src/Model/ShoppingList/LineItemCollection.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?php
/**
* @author @jayS-de <jens.schulze@commercetools.de>
*/

namespace Commercetools\Core\Model\ShoppingList;

use Commercetools\Core\Model\Common\Collection;

/**
* @package Commercetools\Core\Model\ShoppingList
*
* @method LineItemCollection add(LineItem $element)
* @method LineItem current()
* @method LineItem getAt($offset)
* @method LineItem getById($offset)
*/
class LineItemCollection extends Collection
{
protected $type = '\Commercetools\Core\Model\ShoppingList\LineItem';
}
41 changes: 41 additions & 0 deletions src/Model/ShoppingList/LineItemDraft.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<?php
/**
* @author @jayS-de <jens.schulze@commercetools.de>
*/

namespace Commercetools\Core\Model\ShoppingList;

use Commercetools\Core\Model\Common\JsonObject;
use Commercetools\Core\Model\CustomField\CustomFieldObjectDraft;
use Commercetools\Core\Model\Common\DateTimeDecorator;

/**
* @package Commercetools\Core\Model\ShoppingList
*
* @method string getProductId()
* @method LineItemDraft setProductId(string $productId = null)
* @method int getVariantId()
* @method LineItemDraft setVariantId(int $variantId = null)
* @method int getQuantity()
* @method LineItemDraft setQuantity(int $quantity = null)
* @method CustomFieldObjectDraft getCustom()
* @method LineItemDraft setCustom(CustomFieldObjectDraft $custom = null)
* @method DateTimeDecorator getAddedAt()
* @method LineItemDraft setAddedAt(\DateTime $addedAt = null)
*/
class LineItemDraft extends JsonObject
{
public function fieldDefinitions()
{
return [
'productId' => [static::TYPE => 'string'],
'variantId' => [static::TYPE => 'int'],
'quantity' => [static::TYPE => 'int'],
'custom' => [static::TYPE => '\Commercetools\Core\Model\CustomField\CustomFieldObjectDraft'],
'addedAt' => [
static::TYPE => '\DateTime',
static::DECORATOR => '\Commercetools\Core\Model\Common\DateTimeDecorator'
],
];
}
}
20 changes: 20 additions & 0 deletions src/Model/ShoppingList/LineItemDraftCollection.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?php
/**
* @author @jayS-de <jens.schulze@commercetools.de>
*/

namespace Commercetools\Core\Model\ShoppingList;

use Commercetools\Core\Model\Common\Collection;

/**
* @package Commercetools\Core\Model\ShoppingList
*
* @method LineItemDraftCollection add(LineItemDraft $element)
* @method LineItemDraft current()
* @method LineItemDraft getAt($offset)
*/
class LineItemDraftCollection extends Collection
{
protected $type = '\Commercetools\Core\Model\ShoppingList\LineItemDraft';
}
67 changes: 67 additions & 0 deletions src/Model/ShoppingList/ShoppingList.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
<?php
/**
* @author @jayS-de <jens.schulze@commercetools.de>
*/

namespace Commercetools\Core\Model\ShoppingList;

use Commercetools\Core\Model\Common\JsonObject;
use Commercetools\Core\Model\Common\DateTimeDecorator;
use Commercetools\Core\Model\Common\LocalizedString;
use Commercetools\Core\Model\Customer\CustomerReference;
use Commercetools\Core\Model\CustomField\CustomFieldObject;

/**
* @package Commercetools\Core\Model\ShoppingList
* @link https://dev.commercetools.com/http-api-projects-shoppingLists.html#shoppingList
* @method string getId()
* @method ShoppingList setId(string $id = null)
* @method string getKey()
* @method ShoppingList setKey(string $key = null)
* @method int getVersion()
* @method ShoppingList setVersion(int $version = null)
* @method DateTimeDecorator getCreatedAt()
* @method ShoppingList setCreatedAt(\DateTime $createdAt = null)
* @method DateTimeDecorator getLastModifiedAt()
* @method ShoppingList setLastModifiedAt(\DateTime $lastModifiedAt = null)
* @method LocalizedString getSlug()
* @method ShoppingList setSlug(LocalizedString $slug = null)
* @method LocalizedString getName()
* @method ShoppingList setName(LocalizedString $name = null)
* @method LocalizedString getDescription()
* @method ShoppingList setDescription(LocalizedString $description = null)
* @method CustomerReference getCustomer()
* @method ShoppingList setCustomer(CustomerReference $customer = null)
* @method LineItem getLineItems()
* @method ShoppingList setLineItems(LineItem $lineItems = null)
* @method TextLineItemCollection getTextLineItems()
* @method ShoppingList setTextLineItems(TextLineItemCollection $textLineItems = null)
* @method CustomFieldObject getCustom()
* @method ShoppingList setCustom(CustomFieldObject $custom = null)
*/
class ShoppingList extends JsonObject
{
public function fieldDefinitions()
{
return [
'id' => [static::TYPE => 'string'],
'key' => [static::TYPE => 'string'],
'version' => [static::TYPE => 'int'],
'createdAt' => [
static::TYPE => '\DateTime',
static::DECORATOR => '\Commercetools\Core\Model\Common\DateTimeDecorator'
],
'lastModifiedAt' => [
static::TYPE => '\DateTime',
static::DECORATOR => '\Commercetools\Core\Model\Common\DateTimeDecorator'
],
'slug' => [static::TYPE => '\Commercetools\Core\Model\Common\LocalizedString'],
'name' => [static::TYPE => '\Commercetools\Core\Model\Common\LocalizedString'],
'description' => [static::TYPE => '\Commercetools\Core\Model\Common\LocalizedString'],
'customer' => [static::TYPE => '\Commercetools\Core\Model\Customer\CustomerReference'],
'lineItems' => [static::TYPE => '\Commercetools\Core\Model\ShoppingList\LineItem'],
'textLineItems' => [static::TYPE => '\Commercetools\Core\Model\ShoppingList\TextLineItemCollection'],
'custom' => [static::TYPE => '\Commercetools\Core\Model\CustomField\CustomFieldObject'],
];
}
}
37 changes: 37 additions & 0 deletions src/Model/ShoppingList/ShoppingListCollection.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?php
/**
* @author @jayS-de <jens.schulze@commercetools.de>
*/

namespace Commercetools\Core\Model\ShoppingList;

use Commercetools\Core\Model\Common\Collection;

/**
* @package Commercetools\Core\Model\ShoppingList
*
* @method ShoppingListCollection add(ShoppingList $element)
* @method ShoppingList current()
* @method ShoppingList getAt($offset)
* @method ShoppingList getById($offset)
*/
class ShoppingListCollection extends Collection
{
const KEY = 'key';
protected $type = '\Commercetools\Core\Model\ShoppingList\ShoppingList';

protected function indexRow($offset, $row)
{
$id = null;
$key = null;
if ($row instanceof ShoppingList) {
$id = $row->getId();
$key = $row->getKey();
} elseif (is_array($row)) {
$id = isset($row[static::ID]) ? $row[static::ID] : null;
$key = isset($row[static::KEY]) ? $row[static::KEY] : null;
}
$this->addToIndex(static::ID, $offset, $id);
$this->addToIndex(static::KEY, $offset, $key);
}
}
70 changes: 70 additions & 0 deletions src/Model/ShoppingList/ShoppingListDraft.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
<?php
/**
* @author @jayS-de <jens.schulze@commercetools.de>
*/

namespace Commercetools\Core\Model\ShoppingList;

use Commercetools\Core\Model\Common\Context;
use Commercetools\Core\Model\Common\Resource;
use Commercetools\Core\Model\Common\LocalizedString;
use Commercetools\Core\Model\Customer\CustomerReference;
use Commercetools\Core\Model\CustomField\CustomFieldObjectDraft;

/**
* @package Commercetools\Core\Model\ShoppingList
* @link https://dev.commercetools.com/http-api-projects-shoppingLists.html#shoppingListDraft
* @method string getKey()
* @method ShoppingListDraft setKey(string $key = null)
* @method LocalizedString getSlug()
* @method ShoppingListDraft setSlug(LocalizedString $slug = null)
* @method LocalizedString getName()
* @method ShoppingListDraft setName(LocalizedString $name = null)
* @method LocalizedString getDescription()
* @method ShoppingListDraft setDescription(LocalizedString $description = null)
* @method CustomerReference getCustomer()
* @method ShoppingListDraft setCustomer(CustomerReference $customer = null)
* @method LineItemDraftCollection getLineItems()
* @method ShoppingListDraft setLineItems(LineItemDraftCollection $lineItems = null)
* @method TextLineItemDraftCollection getTextLineItems()
* @method ShoppingListDraft setTextLineItems(TextLineItemDraftCollection $textLineItems = null)
* @method CustomFieldObjectDraft getCustom()
* @method ShoppingListDraft setCustom(CustomFieldObjectDraft $custom = null)
*/
class ShoppingListDraft extends Resource
{
public function fieldDefinitions()
{
return [
'key' => [static::TYPE => 'string'],
'slug' => [static::TYPE => '\Commercetools\Core\Model\Common\LocalizedString'],
'name' => [static::TYPE => '\Commercetools\Core\Model\Common\LocalizedString'],
'description' => [static::TYPE => '\Commercetools\Core\Model\Common\LocalizedString'],
'customer' => [static::TYPE => '\Commercetools\Core\Model\Customer\CustomerReference'],
'lineItems' => [static::TYPE => '\Commercetools\Core\Model\ShoppingList\LineItemDraftCollection'],
'textLineItems' => [static::TYPE => '\Commercetools\Core\Model\ShoppingList\TextLineItemDraftCollection'],
'custom' => [static::TYPE => '\Commercetools\Core\Model\CustomField\CustomFieldObjectDraft'],
];
}

/**
* @param string $name
* @param Context|null $context
* @return ShoppingListDraft
*/
public static function ofName($name, $context = null)
{
return static::of($context)->setName($name);
}

/**
* @param string $name
* @param string $key
* @param Context|null $context
* @return ShoppingListDraft
*/
public static function ofNameAndKey($name, $key, $context = null)
{
return static::of($context)->setName($name)->setKey($key);
}
}
45 changes: 45 additions & 0 deletions src/Model/ShoppingList/TextLineItem.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
<?php
/**
* @author @jayS-de <jens.schulze@commercetools.de>
*/

namespace Commercetools\Core\Model\ShoppingList;

use Commercetools\Core\Model\Common\JsonObject;
use Commercetools\Core\Model\Common\LocalizedString;
use Commercetools\Core\Model\Common\DateTimeDecorator;
use Commercetools\Core\Model\CustomField\CustomFieldObject;

/**
* @package Commercetools\Core\Model\ShoppingList
*
* @method string getId()
* @method TextLineItem setId(string $id = null)
* @method LocalizedString getName()
* @method TextLineItem setName(LocalizedString $name = null)
* @method LocalizedString getDescription()
* @method TextLineItem setDescription(LocalizedString $description = null)
* @method int getQuantity()
* @method TextLineItem setQuantity(int $quantity = null)
* @method DateTimeDecorator getAddedAt()
* @method TextLineItem setAddedAt(\DateTime $addedAt = null)
* @method CustomFieldObject getCustom()
* @method TextLineItem setCustom(CustomFieldObject $custom = null)
*/
class TextLineItem extends JsonObject
{
public function fieldDefinitions()
{
return [
'id' => [static::TYPE => 'string'],
'name' => [static::TYPE => '\Commercetools\Core\Model\Common\LocalizedString'],
'description' => [static::TYPE => '\Commercetools\Core\Model\Common\LocalizedString'],
'quantity' => [static::TYPE => 'int'],
'addedAt' => [
static::TYPE => '\DateTime',
static::DECORATOR => '\Commercetools\Core\Model\Common\DateTimeDecorator'
],
'custom' => [static::TYPE => '\Commercetools\Core\Model\CustomField\CustomFieldObject'],
];
}
}
21 changes: 21 additions & 0 deletions src/Model/ShoppingList/TextLineItemCollection.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?php
/**
* @author @jayS-de <jens.schulze@commercetools.de>
*/

namespace Commercetools\Core\Model\ShoppingList;

use Commercetools\Core\Model\Common\Collection;

/**
* @package Commercetools\Core\Model\ShoppingList
*
* @method TextLineItemCollection add(TextLineItem $element)
* @method TextLineItem current()
* @method TextLineItem getAt($offset)
* @method TextLineItem getById($offset)
*/
class TextLineItemCollection extends Collection
{
protected $type = '\Commercetools\Core\Model\ShoppingList\TextLineItem';
}
Loading

0 comments on commit d8fdf4d

Please sign in to comment.