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

Commit

Permalink
feat(Product): support assets
Browse files Browse the repository at this point in the history
Closes #241
  • Loading branch information
Jens Schulze committed Aug 8, 2016

Unverified

No user is associated with the committer email.
1 parent 23e0193 commit 43f8dd6
Showing 19 changed files with 856 additions and 0 deletions.
39 changes: 39 additions & 0 deletions src/Model/Common/Asset.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<?php
/**
* @author @jayS-de <jens.schulze@commercetools.de>
*/

namespace Commercetools\Core\Model\Common;

use Commercetools\Core\Model\CustomField\CustomFieldObject;

/**
* @package Commercetools\Core\Model\Common
*
* @method string getId()
* @method Asset setId(string $id = null)
* @method AssetSourceCollection getSources()
* @method Asset setSources(AssetSourceCollection $sources = null)
* @method LocalizedString getName()
* @method Asset setName(LocalizedString $name = null)
* @method LocalizedString getDescription()
* @method Asset setDescription(LocalizedString $description = null)
* @method array getTags()
* @method Asset setTags(array $tags = null)
* @method CustomFieldObject getCustom()
* @method Asset setCustom(CustomFieldObject $custom = null)
*/
class Asset extends JsonObject
{
public function fieldDefinitions()
{
return [
'id' => [static::TYPE => 'string'],
'sources' => [static::TYPE => '\Commercetools\Core\Model\Common\AssetSourceCollection'],
'name' => [static::TYPE => '\Commercetools\Core\Model\Common\LocalizedString'],
'description' => [static::TYPE => '\Commercetools\Core\Model\Common\LocalizedString'],
'tags' => [static::TYPE => 'array'],
'custom' => [static::TYPE => '\Commercetools\Core\Model\CustomField\CustomFieldObject'],
];
}
}
18 changes: 18 additions & 0 deletions src/Model/Common/AssetCollection.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php
/**
* @author @jayS-de <jens.schulze@commercetools.de>
*/

namespace Commercetools\Core\Model\Common;

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

namespace Commercetools\Core\Model\Common;

/**
* @package Commercetools\Core\Model\Common
* @method int getW()
* @method AssetDimension setW(int $w = null)
* @method int getH()
* @method AssetDimension setH(int $h = null)
*/
class AssetDimension extends JsonObject
{
public function fieldDefinitions()
{
return [
'w' => [static::TYPE => 'int'],
'h' => [static::TYPE => 'int'],
];
}
}
36 changes: 36 additions & 0 deletions src/Model/Common/AssetDraft.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?php
/**
* @author @jayS-de <jens.schulze@commercetools.de>
*/

namespace Commercetools\Core\Model\Common;

use Commercetools\Core\Model\CustomField\CustomFieldObject;

/**
* @package Commercetools\Core\Model\Common
*
* @method AssetSourceCollection getSources()
* @method AssetDraft setSources(AssetSourceCollection $sources = null)
* @method LocalizedString getName()
* @method AssetDraft setName(LocalizedString $name = null)
* @method LocalizedString getDescription()
* @method AssetDraft setDescription(LocalizedString $description = null)
* @method array getTags()
* @method AssetDraft setTags(array $tags = null)
* @method CustomFieldObject getCustom()
* @method AssetDraft setCustom(CustomFieldObject $custom = null)
*/
class AssetDraft extends JsonObject
{
public function fieldDefinitions()
{
return [
'sources' => [static::TYPE => '\Commercetools\Core\Model\Common\AssetSourceCollection'],
'name' => [static::TYPE => '\Commercetools\Core\Model\Common\LocalizedString'],
'description' => [static::TYPE => '\Commercetools\Core\Model\Common\LocalizedString'],
'tags' => [static::TYPE => 'array'],
'custom' => [static::TYPE => '\Commercetools\Core\Model\CustomField\CustomFieldObject'],
];
}
}
18 changes: 18 additions & 0 deletions src/Model/Common/AssetDraftCollection.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php
/**
* @author @jayS-de <jens.schulze@commercetools.de>
*/

namespace Commercetools\Core\Model\Common;

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

namespace Commercetools\Core\Model\Common;

/**
* @package Commercetools\Core\Model\Common
*
* @method string getUri()
* @method AssetSource setUri(string $uri = null)
* @method string getKey()
* @method AssetSource setKey(string $key = null)
* @method AssetDimension getDimensions()
* @method AssetSource setDimensions(AssetDimension $dimensions = null)
* @method string getContentType()
* @method AssetSource setContentType(string $contentType = null)
*/
class AssetSource extends JsonObject
{
public function fieldDefinitions()
{
return [
'uri' => [static::TYPE => 'string'],
'key' => [static::TYPE => 'string'],
'dimensions' => [static::TYPE => '\Commercetools\Core\Model\Common\AssetDimension'],
'contentType' => [static::TYPE => 'string'],
];
}
}
18 changes: 18 additions & 0 deletions src/Model/Common/AssetSourceCollection.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php
/**
* @author @jayS-de <jens.schulze@commercetools.de>
*/

namespace Commercetools\Core\Model\Common;

/**
* @package Commercetools\Core\Model\Common
*
* @method AssetSourceCollection add(AssetSource $element)
* @method AssetSource current()
* @method AssetSource getAt($offset)
*/
class AssetSourceCollection extends Collection
{
protected $type = '\Commercetools\Core\Model\Common\AssetSource';
}
4 changes: 4 additions & 0 deletions src/Model/Product/ProductVariant.php
Original file line number Diff line number Diff line change
@@ -11,6 +11,7 @@
use Commercetools\Core\Model\Common\PriceCollection;
use Commercetools\Core\Model\Common\Price;
use Commercetools\Core\Model\Common\ScopedPrice;
use Commercetools\Core\Model\Common\AssetCollection;

/**
* @package Commercetools\Core\Model\Product
@@ -35,6 +36,8 @@
* @method ProductVariant setScopedPrice(ScopedPrice $scopedPrice = null)
* @method bool getScopedPriceDiscounted()
* @method ProductVariant setScopedPriceDiscounted(bool $scopedPriceDiscounted = null)
* @method AssetCollection getAssets()
* @method ProductVariant setAssets(AssetCollection $assets = null)
*/
class ProductVariant extends JsonObject
{
@@ -51,6 +54,7 @@ public function fieldDefinitions()
'isMatchingVariant' => [static::TYPE => 'bool'],
'scopedPrice' => [static::TYPE => '\Commercetools\Core\Model\Common\ScopedPrice'],
'scopedPriceDiscounted' => [static::TYPE => 'bool'],
'assets' => [static::TYPE => '\Commercetools\Core\Model\Common\AssetCollection']
];
}
}
4 changes: 4 additions & 0 deletions src/Model/Product/ProductVariantDraft.php
Original file line number Diff line number Diff line change
@@ -10,6 +10,7 @@
use Commercetools\Core\Model\Common\JsonObject;
use Commercetools\Core\Model\Common\PriceDraftCollection;
use Commercetools\Core\Model\Common\ImageCollection;
use Commercetools\Core\Model\Common\AssetDraftCollection;

/**
* @package Commercetools\Core\Model\Product
@@ -22,6 +23,8 @@
* @method AttributeCollection getAttributes()
* @method ImageCollection getImages()
* @method ProductVariantDraft setImages(ImageCollection $images = null)
* @method AssetDraftCollection getAssets()
* @method ProductVariantDraft setAssets(AssetDraftCollection $assets = null)
*/
class ProductVariantDraft extends JsonObject
{
@@ -32,6 +35,7 @@ public function fieldDefinitions()
'prices' => [self::TYPE => '\Commercetools\Core\Model\Common\PriceDraftCollection'],
'images' => [static::TYPE => '\Commercetools\Core\Model\Common\ImageCollection'],
'attributes' => [self::TYPE => '\Commercetools\Core\Model\Common\AttributeCollection'],
'assets' => [static::TYPE => '\Commercetools\Core\Model\Common\AssetDraftCollection']
];
}
}
71 changes: 71 additions & 0 deletions src/Request/Products/Command/ProductAddAssetAction.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
<?php
/**
* @author @jayS-de <jens.schulze@commercetools.de>
*/

namespace Commercetools\Core\Request\Products\Command;

use Commercetools\Core\Model\Common\Asset;
use Commercetools\Core\Model\Common\Context;
use Commercetools\Core\Request\AbstractAction;
use Commercetools\Core\Model\Common\AssetDraft;

/**
* @package Commercetools\Core\Request\Products\Command
* @link https://dev.commercetools.com/http-api-projects-products.html#add-asset
* @method string getAction()
* @method ProductAddAssetAction setAction(string $action = null)
* @method int getVariantId()
* @method ProductAddAssetAction setVariantId(int $variantId = null)
* @method string getSku()
* @method ProductAddAssetAction setSku(string $sku = null)
* @method AssetDraft getAsset()
* @method ProductAddAssetAction setAsset(AssetDraft $asset = null)
* @method bool getStaged()
* @method ProductAddAssetAction setStaged(bool $staged = null)
*/
class ProductAddAssetAction extends AbstractAction
{
public function fieldDefinitions()
{
return [
'action' => [static::TYPE => 'string'],
'variantId' => [static::TYPE => 'int'],
'sku' => [static::TYPE => 'string'],
'asset' => [static::TYPE => '\Commercetools\Core\Model\Common\AssetDraft'],
'staged' => [static::TYPE => 'bool'],
];
}

/**
* @param array $data
* @param Context|callable $context
*/
public function __construct(array $data = [], $context = null)
{
parent::__construct($data, $context);
$this->setAction('addAsset');
}

/**
* @param int $variantId
* @param Asset $asset
* @param Context|callable $context
* @return ProductAddExternalImageAction
*/
public static function ofVariantIdAndAsset($variantId, Asset $asset, $context = null)
{
return static::of($context)->setVariantId($variantId)->setAsset($asset);
}

/**
* @param string $sku
* @param Asset $asset
* @param Context|callable $context
* @return ProductAddExternalImageAction
*/
public static function ofSkuAndAsset($sku, Asset $asset, $context = null)
{
return static::of($context)->setSku($sku)->setAsset($asset);
}
}
75 changes: 75 additions & 0 deletions src/Request/Products/Command/ProductChangeAssetNameAction.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
<?php
/**
* @author @jayS-de <jens.schulze@commercetools.de>
*/

namespace Commercetools\Core\Request\Products\Command;

use Commercetools\Core\Model\Common\Context;
use Commercetools\Core\Model\Common\LocalizedString;
use Commercetools\Core\Request\AbstractAction;

/**
* @package Commercetools\Core\Request\Products\Command
* @link https://dev.commercetools.com/http-api-projects-products.html#change-asset-name
* @method string getAction()
* @method ProductChangeAssetNameAction setAction(string $action = null)
* @method LocalizedString getName()
* @method ProductChangeAssetNameAction setName(LocalizedString $name = null)
* @method bool getStaged()
* @method ProductChangeAssetNameAction setStaged(bool $staged = null)
* @method int getVariantId()
* @method ProductChangeAssetNameAction setVariantId(int $variantId = null)
* @method string getSku()
* @method ProductChangeAssetNameAction setSku(string $sku = null)
* @method string getAssetId()
* @method ProductChangeAssetNameAction setAssetId(string $assetId = null)
*/
class ProductChangeAssetNameAction extends AbstractAction
{
public function fieldDefinitions()
{
return [
'action' => [static::TYPE => 'string'],
'variantId' => [static::TYPE => 'int'],
'sku' => [static::TYPE => 'string'],
'assetId' => [static::TYPE => 'string'],
'name' => [static::TYPE => '\Commercetools\Core\Model\Common\LocalizedString'],
'staged' => [static::TYPE => 'bool'],
];
}

/**
* @param array $data
* @param Context|callable $context
*/
public function __construct(array $data = [], $context = null)
{
parent::__construct($data, $context);
$this->setAction('changeAssetName');
}

/**
* @param int $variantId
* @param string $assetId
* @param LocalizedString $name
* @param Context|callable $context
* @return ProductRemoveAssetAction
*/
public static function ofVariantIdAssetIdAndName($variantId, $assetId, LocalizedString $name, $context = null)
{
return static::of($context)->setVariantId($variantId)->setAssetId($assetId)->setName($name);
}

/**
* @param string $sku
* @param string $assetId
* @param LocalizedString $name
* @param Context|callable $context
* @return ProductRemoveAssetAction
*/
public static function ofSkuAssetIdAndName($sku, $assetId, LocalizedString $name, $context = null)
{
return static::of($context)->setSku($sku)->setAssetId($assetId)->setName($name);
}
}
Loading

0 comments on commit 43f8dd6

Please # to comment.