Passed
Push — develop ( 2123c4...47647c )
by
unknown
15:28 queued 14s
created

LineItemDraft::ofProductIdVariantIdAndQuantity()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
eloc 1
dl 0
loc 3
ccs 2
cts 2
cp 1
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 4
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 156
    public function fieldDefinitions()
50
    {
51
        return [
52 156
            'productId' => [static::TYPE => 'string'],
53 156
            'variantId' => [static::TYPE => 'int'],
54 156
            'quantity' => [static::TYPE => 'int'],
55 156
            'supplyChannel' => [static::TYPE => ChannelReference::class],
56 156
            'distributionChannel' => [static::TYPE => ChannelReference::class],
57 156
            'externalTaxRate' => [static::TYPE => ExternalTaxRateDraft::class],
58 156
            'externalPrice' => [static::TYPE => Money::class],
59 156
            'externalTotalPrice' => [static::TYPE => ExternalLineItemTotalPrice::class],
60 156
            'custom' => [static::TYPE => CustomFieldObject::class],
61 156
            'sku' => [static::TYPE => 'string'],
62 156
            '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 $productId
79
     * @param int $variantId
80
     * @param int $quantity
81
     * @param Context|callable $context
82
     * @return LineItemDraft
83
     */
84 148
    public static function ofProductIdVariantIdAndQuantity($productId, $variantId, $quantity, $context = null)
85
    {
86 148
        return static::of($context)->setProductId($productId)->setVariantId($variantId)->setQuantity($quantity);
87
    }
88
89
    /**
90
     * @param string $sku
91
     * @param Context|callable $context
92
     * @return LineItemDraft
93
     */
94 3
    public static function ofSku($sku, $context = null)
95
    {
96 3
        $draft = static::of($context);
97 3
        return $draft->setSku($sku);
98
    }
99
100
    /**
101
     * @param string $sku
102
     * @param int $quantity
103
     * @param Context|callable $context
104
     * @return LineItemDraft
105
     */
106 10
    public static function ofSkuAndQuantity($sku, $quantity, $context = null)
107
    {
108 10
        return static::of($context)->setSku($sku)->setQuantity($quantity);
109
    }
110
}
111