Shop::load()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 1
b 0
f 0
nc 1
nop 3
dl 0
loc 3
rs 10
1
<?php
2
3
namespace Helix\Shopify;
4
5
use Helix\Shopify\Base\AbstractEntity;
6
use Helix\Shopify\Base\AbstractEntity\ImmutableInterface;
7
use Helix\Shopify\Base\AbstractEntity\MetafieldTrait;
8
use Helix\Shopify\Base\Data;
9
use LogicException;
10
11
/**
12
 * The shop.
13
 *
14
 * @immutable Cannot be modified via the API.
15
 *
16
 * @see https://shopify.dev/docs/admin-api/rest/reference/store-properties/shop
17
 *
18
 * @method string   getAddress1                     ()
19
 * @method string   getAddress2                     ()
20
 * @method bool     isCheckoutApiSupported          ()
21
 * @method string   getCity                         ()
22
 * @method string   getCountry                      ()
23
 * @method string   getCountryCode                  ()
24
 * @method string   getCountryName                  ()
25
 * @method string   getCountyTaxes                  ()
26
 * @method string   getCreatedAt                    ()
27
 * @method string   getCustomerEmail                ()
28
 * @method string   getCurrency                     ()
29
 * @method string   getDomain                       ()
30
 * @method string   getEnabledPresentmentCurrencies ()
31
 * @method bool     isEligibleForCardReaderGiveaway ()
32
 * @method bool     isEligibleForPayments           ()
33
 * @method string   getEmail                        ()
34
 * @method bool     isForceSsl                      ()
35
 * @method string   getGoogleAppsDomain             ()
36
 * @method bool     isGoogleAppsLoginEnabled        ()
37
 * @method bool     getHasDiscounts                 ()
38
 * @method bool     getHasGiftCards                 ()
39
 * @method bool     getHasStorefront                ()
40
 * @method string   getIanaTimezone                 ()
41
 * @method string   getLatitude                     ()
42
 * @method string   getLongitude                    ()
43
 * @method string   getMoneyFormat                  ()
44
 * @method string   getMoneyInEmailsFormat          ()
45
 * @method string   getMoneyWithCurrencyFormat      ()
46
 * @method string   getMoneyWithCurrencyInEmailsFormat()
47
 * @method bool     isMultiLocationEnabled          ()
48
 * @method string   getMyshopifyDomain              ()
49
 * @method string   getName                         ()
50
 * @method bool     isPasswordEnabled               ()
51
 * @method string   getPhone                        ()
52
 * @method string   getPlanDisplayName              ()
53
 * @method string   getPrimaryLocale                ()
54
 * @method string   getProvince                     ()
55
 * @method string   getProvinceCode                 ()
56
 * @method bool     getRequiresExtraPaymentsAgreement()
57
 * @method bool     isSetupRequired                 ()
58
 * @method string   getShopOwner                    ()
59
 * @method string   getSource                       ()
60
 * @method bool     getTaxesIncluded                ()
61
 * @method bool     getTaxShipping                  ()
62
 * @method string   getTimezone                     ()
63
 * @method string   getUpdatedAt                    ()
64
 * @method string   getWeightUnit                   ()
65
 * @method string   getZip                          ()
66
 */
67
class Shop extends AbstractEntity implements ImmutableInterface
68
{
69
70
    use MetafieldTrait;
71
72
    const TYPE = 'shop';
73
74
    /**
75
     * The shop is a special entity that isn't loaded by its id.
76
     *
77
     * @param Api|Data $caller
78
     * @param string $id ignored
79
     * @param array $query ignored
80
     * @internal Use {@link Api::getShop()} instead.
81
     */
82
    final public static function load($caller, string $id, array $query = [])
83
    {
84
        throw new LogicException;
85
    }
86
87
    /**
88
     * @param Api|Data $caller
89
     * @param string $path ignored
90
     * @param array $query ignored
91
     * @internal Use {@link Api::getShop()} instead.
92
     */
93
    final public static function loadAll($caller, string $path, array $query = [])
94
    {
95
        throw new LogicException;
96
    }
97
98
    /**
99
     * @return string
100
     */
101
    final public function __toString(): string
102
    {
103
        return 'shop';
104
    }
105
106
    /**
107
     * @param array $query
108
     * @return AbandonedCheckout[]
109
     */
110
    public function getAbandonedCheckouts(array $query = [])
111
    {
112
        $checkouts = $this->api->get('checkouts', $query)['checkouts'] ?? [];
113
        return $this->api->factoryAll($this, AbandonedCheckout::class, $checkouts);
114
    }
115
116
    /**
117
     * @return int
118
     */
119
    public function getAbandonedCheckoutsCount(): int
120
    {
121
        return $this->api->get('checkouts/count')['count'];
122
    }
123
124
    /**
125
     * @param string $code
126
     * @return Country
127
     */
128
    public function newCountry(string $code)
129
    {
130
        return $this->api->factory($this, Country::class, [
131
            'code' => $code
132
        ]);
133
    }
134
135
    /**
136
     * @return Customer
137
     */
138
    public function newCustomer()
139
    {
140
        return $this->api->factory($this, Customer::class);
141
    }
142
}