Passed
Pull Request — develop (#423)
by nikos
09:13
created

LineItemDraft::fieldDefinitions()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 14
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 12
CRAP Score 1

Importance

Changes 0
Metric Value
eloc 12
dl 0
loc 14
ccs 12
cts 12
cp 1
rs 9.8666
c 0
b 0
f 0
cc 1
nc 1
nop 0
crap 1
1
<?php
2
/**
3
 * @author @jenschude <[email protected]>
4
 */
5
6
namespace Commercetools\Core\Model\Cart;
7
8
use Commercetools\Core\Model\Channel\ChannelReference;
9
use Commercetools\Core\Model\Common\Context;
10
use Commercetools\Core\Model\Common\JsonObject;
11
use Commercetools\Core\Model\Common\LocalizedString;
12
use Commercetools\Core\Model\Common\Money;
13
use Commercetools\Core\Model\Common\Price;
14
use Commercetools\Core\Model\Order\ItemState;
15
use Commercetools\Core\Model\Order\ItemStateCollection;
16
use Commercetools\Core\Model\Product\ProductVariant;
17
use Commercetools\Core\Model\TaxCategory\TaxRate;
18
use Commercetools\Core\Model\CustomField\CustomFieldObject;
19
use Commercetools\Core\Model\TaxCategory\ExternalTaxRateDraft;
20
21
/**
22
 * @package Commercetools\Core\Model\Cart
23
 * @link https://docs.commercetools.com/http-api-projects-carts.html#lineitemdraft
24
 * @method string getProductId()
25
 * @method LineItemDraft setProductId(string $productId = null)
26
 * @method int getVariantId()
27
 * @method LineItemDraft setVariantId(int $variantId = null)
28
 * @method int getQuantity()
29
 * @method LineItemDraft setQuantity(int $quantity = null)
30
 * @method ChannelReference getSupplyChannel()
31
 * @method LineItemDraft setSupplyChannel(ChannelReference $supplyChannel = null)
32
 * @method ChannelReference getDistributionChannel()
33
 * @method LineItemDraft setDistributionChannel(ChannelReference $distributionChannel = null)
34
 * @method CustomFieldObject getCustom()
35
 * @method LineItemDraft setCustom(CustomFieldObject $custom = null)
36
 * @method ExternalTaxRateDraft getExternalTaxRate()
37
 * @method LineItemDraft setExternalTaxRate(ExternalTaxRateDraft $externalTaxRate = null)
38
 * @method Money getExternalPrice()
39
 * @method LineItemDraft setExternalPrice(Money $externalPrice = null)
40
 * @method ExternalLineItemTotalPrice getExternalTotalPrice()
41
 * @method LineItemDraft setExternalTotalPrice(ExternalLineItemTotalPrice $externalTotalPrice = null)
42
 * @method string getSku()
43
 * @method LineItemDraft setSku(string $sku = null)
44
 * @method ItemShippingDetailsDraft getShippingDetails()
45
 * @method LineItemDraft setShippingDetails(ItemShippingDetailsDraft $shippingDetails = null)
46
 */
47
class LineItemDraft extends JsonObject
48
{
49 54
    public function fieldDefinitions()
50
    {
51
        return [
52 54
            'productId' => [static::TYPE => 'string'],
53 54
            'variantId' => [static::TYPE => 'int'],
54 54
            'quantity' => [static::TYPE => 'int'],
55 54
            'supplyChannel' => [static::TYPE => ChannelReference::class],
56 54
            'distributionChannel' => [static::TYPE => ChannelReference::class],
57 54
            'externalTaxRate' => [static::TYPE => ExternalTaxRateDraft::class],
58 54
            'externalPrice' => [static::TYPE => Money::class],
59 54
            'externalTotalPrice' => [static::TYPE => ExternalLineItemTotalPrice::class],
60 54
            'custom' => [static::TYPE => CustomFieldObject::class],
61 54
            'sku' => [static::TYPE => 'string'],
62 54
            'shippingDetails' => [static::TYPE => ItemShippingDetailsDraft::class],
63
        ];
64
    }
65
66
    /**
67
     * @param string $productId
68
     * @param Context|callable $context
69
     * @return LineItemDraft
70
     */
71
    public static function ofProductId($productId, $context = null)
72
    {
73
        $draft = static::of($context);
74
        return $draft->setProductId($productId);
75
    }
76
77
    /**
78
     * @param string $sku
79
     * @param Context|callable $context
80
     * @return LineItemDraft
81
     */
82 8
    public static function ofSku($sku, $context = null)
83
    {
84 8
        $draft = static::of($context);
85 8
        return $draft->setSku($sku);
86
    }
87
}
88