Overview

Namespaces

  • Html2Text
  • Izberg
    • Exception
    • Resource
      • Category

Classes

  • Html2Text\Html2Text
  • Izberg\Helper
  • Izberg\Izberg
  • Izberg\Resource
  • Izberg\Resource\Address
  • Izberg\Resource\Application
  • Izberg\Resource\ApplicationCategory
  • Izberg\Resource\Attributes
  • Izberg\Resource\BillingAddress
  • Izberg\Resource\Brand
  • Izberg\Resource\Carrier
  • Izberg\Resource\Cart
  • Izberg\Resource\CartItem
  • Izberg\Resource\CartShippingChoice
  • Izberg\Resource\Category
  • Izberg\Resource\Category\CategoryAbstract
  • Izberg\Resource\Country
  • Izberg\Resource\CoverImage
  • Izberg\Resource\Currency
  • Izberg\Resource\Discount
  • Izberg\Resource\ExtraInfo
  • Izberg\Resource\Feed
  • Izberg\Resource\LocaleConfig
  • Izberg\Resource\Merchant
  • Izberg\Resource\MerchantAddress
  • Izberg\Resource\MerchantImage
  • Izberg\Resource\MerchantOrder
  • Izberg\Resource\MerchantReview
  • Izberg\Resource\Message
  • Izberg\Resource\Meta
  • Izberg\Resource\Offer
  • Izberg\Resource\OfferImage
  • Izberg\Resource\Order
  • Izberg\Resource\OrderItem
  • Izberg\Resource\Payment
  • Izberg\Resource\PaymentCardAlias
  • Izberg\Resource\Product
  • Izberg\Resource\ProductAttribute
  • Izberg\Resource\ProductBrand
  • Izberg\Resource\ProductChannel
  • Izberg\Resource\ProductChannelFileOutput
  • Izberg\Resource\Productoffer
  • Izberg\Resource\ProductOfferVariation
  • Izberg\Resource\ProductVariation
  • Izberg\Resource\ProfileImage
  • Izberg\Resource\Receiver
  • Izberg\Resource\ReturnRequest
  • Izberg\Resource\Review
  • Izberg\Resource\Sender
  • Izberg\Resource\ShippingAddress
  • Izberg\Resource\ShippingMerchantTemplate
  • Izberg\Resource\ShippingProvider
  • Izberg\Resource\ShippingProviderAssignment
  • Izberg\Resource\ShoppingPreference
  • Izberg\Resource\User
  • Izberg\Resource\Webhook

Exceptions

  • Izberg\Exception\BadRequestException
  • Izberg\Exception\ForbiddenException
  • Izberg\Exception\GenericException
  • Izberg\Exception\HttpException
  • Izberg\Exception\InternalErrorException
  • Izberg\Exception\MethodNotAllowedException
  • Izberg\Exception\NotFoundException
  • Izberg\Exception\UnauthorizedException
  • Overview
  • Namespace
  • Class
  1: <?php
  2: namespace Izberg\Resource;
  3: use Izberg\Resource;
  4: 
  5: class Cart extends Resource
  6: {
  7:     /**
  8:     * get current cart items
  9:     *
 10:     * @return Object Array
 11:     */
 12:     public function getItems($params = null, $accept_type = "Accept: application/json")
 13:     {
 14:         $list = self::$Izberg->Call("cart/".$this->id."/items/", 'GET', $params, $accept_type);
 15:         $object_list = array();
 16:         if (!isset($list->objects))
 17:           return null;
 18:         foreach ($list->objects as $object)
 19:         {
 20:           $obj = new CartItem();
 21:           $obj->hydrate($object);
 22:           $object_list[] = $obj;
 23:         }
 24:         if (!isset($this->items)) {
 25:           $this->items = array();
 26:         }
 27:         $this->items = array_merge($this->items, $object_list);
 28:         return $object_list;
 29:     }
 30: 
 31:     /**
 32:     * add an item to a cart
 33:     *
 34:     * @return Array
 35:     */
 36:     public function addItem($params = null, $accept_type = 'Content-Type: application/json')
 37:     {
 38:         // Params:
 39:         //   offer_id: Integer
 40:         //   variation_id: Integer
 41:         //   quantity: Integer
 42:         //   gift: Boolean
 43:         //   bundled: Boolean
 44:         $response = self::$Izberg->Call("cart/".($this->id ? $this->id : "none")."/items/", 'POST', $params, $accept_type);
 45:         $object = new CartItem();
 46:         $object->hydrate($response);
 47:         $this->items[] = $object;
 48:         return $object;
 49:     }
 50: 
 51:     /**
 52:     * update an item to a cart
 53:     *
 54:     * @return Array
 55:     */
 56:     public function updateItem($id, $params = null, $accept_type = 'Accept: application/json')
 57:     {
 58:         // Params:
 59:         //   offer_id: Integer
 60:         //   variation_id: Integer
 61:         //   quantity: Integer
 62:         //   gift: Boolean
 63:         //   bundled: Boolean
 64:         $object = new CartItem();
 65:         $response = parent::$Izberg->Call($object->getName()."/".$id."/", "PUT", $params, $accept_type);
 66:         $object->hydrate($response);
 67:         return $object;
 68:     }
 69: 
 70:     /**
 71:     * Set cart shipping address
 72:     *
 73:     * @return StdObject
 74:     */
 75:     public function setShippingAddress($id)
 76:     {
 77:         $params["shipping_address"] = "/v1/address/".$id."/";
 78:         $this->shipping_address = "/v1/address/".$id."/";
 79:         return parent::$Izberg->update('Cart', $this->id, $params);
 80:     }
 81: 
 82: 
 83:     /**
 84:     * Set cart Billing address
 85:     *
 86:     * @return StdObject
 87:     */
 88:     public function setBillingAddress($id)
 89:     {
 90:         $params["billing_address"] = "/v1/address/".$id."/";
 91:         $this->billing_address = "/v1/address/".$id."/";
 92:         return parent::$Izberg->update('Cart', $this->id, $params);
 93:     }
 94: 
 95:     public function createOrder($params = null, $accept_type = 'Content-Type: application/json')
 96:     {
 97:         $object = new Order();
 98:         $response = parent::$Izberg->Call("cart/" . $this->id . "/createOrder/", 'POST', $params, $accept_type);
 99:         $object->hydrate($response);
100:         return $object;
101:     }
102: 
103:     public function addOffer($product_offer_id,$quantity = 1)
104:     {
105:         $params = array(
106:             'offer_id'=> $product_offer_id,
107:             'quantity'=> $quantity
108:         );
109:         return parent::$Izberg->Call($this->getName()."/items/", "POST", $params);
110:     }
111: 
112:     /**
113:       * Remove an item from cart
114:       * @param $id
115:       * @param string $accept_type
116:       * @return CartItem
117:       */
118:       public function removeItem($id, $accept_type = 'Accept: application/json')
119:       {
120:       $object = new CartItem();
121:       $response = parent::$Izberg->Call($object->getName()."/".$id."/", "DELETE", array(), $accept_type);
122:       $object->hydrate($response);
123:       return $object;
124:       }
125: 
126:     /**
127:       * Apply a coupon code
128:       * @param $code
129:       * @param string $action
130:       * @return DiscountCode
131:       */
132:     public function discountCode($code, $action = "add")
133:     {
134:       $params = array('discount_code'=> $code);
135:       $id = $this->id ? $this->id : 'mine';
136:       return parent::$Izberg->Call("cart/" . $id . "/" . $action . "_discount_code/", "POST", $params, 'Content-Type: application/json');
137:     }
138: 
139:     /**
140:     * Remove all cart items
141:     * @return Boolean
142:     */
143:     public function clean() {
144:       $this->getItems();
145:       foreach ($this->items as $item) {
146:         $item->delete();
147:       }
148:       return true;
149:     }
150: 
151: 
152:     /**
153:     * Remove all shipping options
154:     * @return Array
155:     */
156:     public function shippingOptions() {
157:       $id = $this->id ? $this->id : 'mine';
158:       return parent::$Izberg->Call("cart/" . $id . "/shipping_options/" , "GET", null, 'Content-Type: application/json');
159:     }
160: 
161:     /**
162:     * Get a shipping options
163:     * @return Array
164:     */
165:     public function shippingOption($option_id) {
166:       return parent::$Izberg->Call("cart_shipping_choice/" . $option_id . "/" , "GET", null, 'Content-Type: application/json');
167:     }
168: 
169:     /**
170:     * Select a shipping option
171:     * @return ShippingOption
172:     */
173:     public function selectShippingOption($option_id) {
174:       $id = $this->id ? $this->id : 'mine';
175:       return parent::$Izberg->Call("cart/" . $id . "/shipping_options/" . $option_id . "/select/" , "POST", array(), 'Content-Type: application/json');
176:     }
177: 
178:     /**
179:     * Select multiple shipping options
180:     * @param Array $ids
181:     * @return Array
182:     */
183:     public function selectShippingOptions($params) {
184:       $id = $this->id ? $this->id : 'mine';
185:       return parent::$Izberg->Call("cart/" . $id . "/shipping_options/" , "POST", $params, 'Content-Type: application/json');
186:     }
187: 
188:     /**
189:     * Update all available shipping options for cart
190:     * @return Array
191:     */
192:     public function updateShippingOptions() {
193:       $id = $this->id ? $this->id : 'mine';
194:       return parent::$Izberg->Call("cart/" . $id . "/shipping_options/update/" , "POST", null, 'Content-Type: application/json');
195:     }
196: }
197: 
API documentation generated by ApiGen