Composable Commerce PHP SDKPHP SDK
  • Namespace
  • Class
  • Tree

Namespaces

  • Commercetools
    • Commons
      • Helper
    • Core
      • Builder
        • Request
        • Update
      • Cache
      • Client
        • Adapter
        • OAuth
      • Error
      • Helper
        • Annotate
        • State
          • Renderer
        • Subscriber
          • Log
      • Model
        • ApiClient
        • Cart
        • CartDiscount
        • Category
        • Channel
        • Common
        • Customer
        • CustomerGroup
        • CustomField
        • CustomObject
        • DiscountCode
        • Extension
        • Inventory
        • Message
        • Order
        • OrderEdit
        • Payment
        • Product
          • Search
        • ProductDiscount
        • ProductSelection
        • ProductType
        • Project
        • Review
        • ShippingMethod
        • ShoppingList
        • State
        • Store
        • Subscription
        • TaxCategory
        • Type
        • Zone
      • Request
        • ApiClients
        • CartDiscounts
          • Command
        • Carts
          • Command
        • Categories
          • Command
        • Channels
          • Command
        • CustomerGroups
          • Command
        • Customers
          • Command
        • CustomField
          • Command
        • CustomObjects
        • DiscountCodes
          • Command
        • Extensions
          • Command
        • GraphQL
        • InStores
        • Inventory
          • Command
        • Me
          • Command
        • Messages
        • OrderEdits
          • Command
          • StagedOrder
            • Command
        • Orders
          • Command
        • Payments
          • Command
        • ProductDiscounts
          • Command
        • Products
          • Command
        • ProductSelections
          • Command
        • ProductTypes
          • Command
        • Project
          • Command
        • Query
        • Reviews
          • Command
        • ShippingMethods
          • Command
        • ShoppingLists
          • Command
        • States
          • Command
        • Stores
          • Command
        • Subscriptions
          • Command
        • TaxCategories
          • Command
        • Types
          • Command
        • Zones
          • Command
      • Response

Classes

  • ActionBuilder
  • CartDiscountsActionBuilder
  • CartsActionBuilder
  • CategoriesActionBuilder
  • ChannelsActionBuilder
  • CustomerGroupsActionBuilder
  • CustomersActionBuilder
  • CustomFieldActionBuilder
  • DiscountCodesActionBuilder
  • ExtensionsActionBuilder
  • InventoryActionBuilder
  • MeActionBuilder
  • OrderEditsActionBuilder
  • OrdersActionBuilder
  • PaymentsActionBuilder
  • ProductDiscountsActionBuilder
  • ProductsActionBuilder
  • ProductSelectionsActionBuilder
  • ProductTypesActionBuilder
  • ProjectActionBuilder
  • ReviewsActionBuilder
  • ShippingMethodsActionBuilder
  • ShoppingListsActionBuilder
  • StagedOrderActionBuilder
  • StatesActionBuilder
  • StoresActionBuilder
  • SubscriptionsActionBuilder
  • TaxCategoriesActionBuilder
  • TypesActionBuilder
  • ZonesActionBuilder
  1   2   3   4   5   6   7   8   9  10  11  12  13  14  15  16  17  18  19  20  21  22  23  24  25  26  27  28  29  30  31  32  33  34  35  36  37  38  39  40  41  42  43  44  45  46  47  48  49  50  51  52  53  54  55  56  57  58  59  60  61  62  63  64  65  66  67  68  69  70  71  72  73  74  75  76  77  78  79  80  81  82  83  84  85  86  87  88  89  90  91  92  93  94  95  96  97  98  99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 
<?php

namespace Commercetools\Core\Builder\Update;

use Commercetools\Core\Error\InvalidArgumentException;
use Commercetools\Core\Request\AbstractAction;
use Commercetools\Core\Request\ShoppingLists\Command\ShoppingListAddLineItemAction;
use Commercetools\Core\Request\ShoppingLists\Command\ShoppingListAddTextLineItemAction;
use Commercetools\Core\Request\ShoppingLists\Command\ShoppingListChangeLineItemQuantityAction;
use Commercetools\Core\Request\ShoppingLists\Command\ShoppingListChangeLineItemsOrderAction;
use Commercetools\Core\Request\ShoppingLists\Command\ShoppingListChangeNameAction;
use Commercetools\Core\Request\ShoppingLists\Command\ShoppingListChangeTextLineItemNameAction;
use Commercetools\Core\Request\ShoppingLists\Command\ShoppingListChangeTextLineItemQuantityAction;
use Commercetools\Core\Request\ShoppingLists\Command\ShoppingListChangeTextLineItemsOrderAction;
use Commercetools\Core\Request\ShoppingLists\Command\ShoppingListRemoveLineItemAction;
use Commercetools\Core\Request\ShoppingLists\Command\ShoppingListRemoveTextLineItemAction;
use Commercetools\Core\Request\ShoppingLists\Command\ShoppingListSetAnonymousIdAction;
use Commercetools\Core\Request\ShoppingLists\Command\ShoppingListSetCustomFieldAction;
use Commercetools\Core\Request\ShoppingLists\Command\ShoppingListSetCustomTypeAction;
use Commercetools\Core\Request\ShoppingLists\Command\ShoppingListSetCustomerAction;
use Commercetools\Core\Request\ShoppingLists\Command\ShoppingListSetDeleteDaysAfterLastModificationAction;
use Commercetools\Core\Request\ShoppingLists\Command\ShoppingListSetDescriptionAction;
use Commercetools\Core\Request\ShoppingLists\Command\ShoppingListSetKeyAction;
use Commercetools\Core\Request\ShoppingLists\Command\ShoppingListSetLineItemCustomFieldAction;
use Commercetools\Core\Request\ShoppingLists\Command\ShoppingListSetLineItemCustomTypeAction;
use Commercetools\Core\Request\ShoppingLists\Command\ShoppingListSetSlugAction;
use Commercetools\Core\Request\ShoppingLists\Command\ShoppingListSetStoreAction;
use Commercetools\Core\Request\ShoppingLists\Command\ShoppingListSetTextLineItemCustomFieldAction;
use Commercetools\Core\Request\ShoppingLists\Command\ShoppingListSetTextLineItemCustomTypeAction;
use Commercetools\Core\Request\ShoppingLists\Command\ShoppingListSetTextLineItemDescriptionAction;

class ShoppingListsActionBuilder
{
    private $actions = [];

    /**
     * @link https://docs.commercetools.com/http-api-projects-shoppingLists.html#add-lineitem
     * @param ShoppingListAddLineItemAction|callable $action
     * @return $this
     */
    public function addLineItem($action = null)
    {
        $this->addAction($this->resolveAction(ShoppingListAddLineItemAction::class, $action));
        return $this;
    }

    /**
     * @link https://docs.commercetools.com/http-api-projects-shoppingLists.html#add-textlineitem
     * @param ShoppingListAddTextLineItemAction|callable $action
     * @return $this
     */
    public function addTextLineItem($action = null)
    {
        $this->addAction($this->resolveAction(ShoppingListAddTextLineItemAction::class, $action));
        return $this;
    }

    /**
     * @link https://docs.commercetools.com/http-api-projects-shoppingLists.html#change-lineitem-quantity
     * @param ShoppingListChangeLineItemQuantityAction|callable $action
     * @return $this
     */
    public function changeLineItemQuantity($action = null)
    {
        $this->addAction($this->resolveAction(ShoppingListChangeLineItemQuantityAction::class, $action));
        return $this;
    }

    /**
     * @link https://docs.commercetools.com/http-api-projects-shoppingLists.html#change-lineitems-order
     * @param ShoppingListChangeLineItemsOrderAction|callable $action
     * @return $this
     */
    public function changeLineItemsOrder($action = null)
    {
        $this->addAction($this->resolveAction(ShoppingListChangeLineItemsOrderAction::class, $action));
        return $this;
    }

    /**
     * @link https://docs.commercetools.com/http-api-projects-types.html#change-name
     * @param ShoppingListChangeNameAction|callable $action
     * @return $this
     */
    public function changeName($action = null)
    {
        $this->addAction($this->resolveAction(ShoppingListChangeNameAction::class, $action));
        return $this;
    }

    /**
     * @link https://docs.commercetools.com/http-api-projects-shoppingLists.html#change-textlineitem-name
     * @param ShoppingListChangeTextLineItemNameAction|callable $action
     * @return $this
     */
    public function changeTextLineItemName($action = null)
    {
        $this->addAction($this->resolveAction(ShoppingListChangeTextLineItemNameAction::class, $action));
        return $this;
    }

    /**
     * @link https://docs.commercetools.com/http-api-projects-shoppingLists.html#change-textlineitem-quantity
     * @param ShoppingListChangeTextLineItemQuantityAction|callable $action
     * @return $this
     */
    public function changeTextLineItemQuantity($action = null)
    {
        $this->addAction($this->resolveAction(ShoppingListChangeTextLineItemQuantityAction::class, $action));
        return $this;
    }

    /**
     * @link https://docs.commercetools.com/http-api-projects-shoppingLists.html#change-textlineitems-order
     * @param ShoppingListChangeTextLineItemsOrderAction|callable $action
     * @return $this
     */
    public function changeTextLineItemsOrder($action = null)
    {
        $this->addAction($this->resolveAction(ShoppingListChangeTextLineItemsOrderAction::class, $action));
        return $this;
    }

    /**
     * @link https://docs.commercetools.com/http-api-projects-shoppingLists.html#remove-lineitem
     * @param ShoppingListRemoveLineItemAction|callable $action
     * @return $this
     */
    public function removeLineItem($action = null)
    {
        $this->addAction($this->resolveAction(ShoppingListRemoveLineItemAction::class, $action));
        return $this;
    }

    /**
     * @link https://docs.commercetools.com/http-api-projects-shoppingLists.html#remove-textlineitem
     * @param ShoppingListRemoveTextLineItemAction|callable $action
     * @return $this
     */
    public function removeTextLineItem($action = null)
    {
        $this->addAction($this->resolveAction(ShoppingListRemoveTextLineItemAction::class, $action));
        return $this;
    }

    /**
     *
     * @param ShoppingListSetAnonymousIdAction|callable $action
     * @return $this
     */
    public function setAnonymousId($action = null)
    {
        $this->addAction($this->resolveAction(ShoppingListSetAnonymousIdAction::class, $action));
        return $this;
    }

    /**
     * @link https://docs.commercetools.com/http-api-projects-shoppingLists.html#set-customField
     * @param ShoppingListSetCustomFieldAction|callable $action
     * @return $this
     */
    public function setCustomField($action = null)
    {
        $this->addAction($this->resolveAction(ShoppingListSetCustomFieldAction::class, $action));
        return $this;
    }

    /**
     * @link https://docs.commercetools.com/http-api-projects-shoppingLists.html#set-customType
     * @param ShoppingListSetCustomTypeAction|callable $action
     * @return $this
     */
    public function setCustomType($action = null)
    {
        $this->addAction($this->resolveAction(ShoppingListSetCustomTypeAction::class, $action));
        return $this;
    }

    /**
     * @link https://docs.commercetools.com/http-api-projects-shoppingLists.html#set-customer
     * @param ShoppingListSetCustomerAction|callable $action
     * @return $this
     */
    public function setCustomer($action = null)
    {
        $this->addAction($this->resolveAction(ShoppingListSetCustomerAction::class, $action));
        return $this;
    }

    /**
     * @link https://docs.commercetools.com/http-api-projects-shoppingLists.html#set-deletedaysafterlastmodification
     * @param ShoppingListSetDeleteDaysAfterLastModificationAction|callable $action
     * @return $this
     */
    public function setDeleteDaysAfterLastModification($action = null)
    {
        $this->addAction($this->resolveAction(ShoppingListSetDeleteDaysAfterLastModificationAction::class, $action));
        return $this;
    }

    /**
     * @link https://docs.commercetools.com/http-api-projects-shoppingLists.html#change-description
     * @param ShoppingListSetDescriptionAction|callable $action
     * @return $this
     */
    public function setDescription($action = null)
    {
        $this->addAction($this->resolveAction(ShoppingListSetDescriptionAction::class, $action));
        return $this;
    }

    /**
     * @link https://docs.commercetools.com/http-api-projects-shoppingLists.html#set-key
     * @param ShoppingListSetKeyAction|callable $action
     * @return $this
     */
    public function setKey($action = null)
    {
        $this->addAction($this->resolveAction(ShoppingListSetKeyAction::class, $action));
        return $this;
    }

    /**
     * @link https://docs.commercetools.com/http-api-projects-shoppingLists.html#set-lineitem-customfield
     * @param ShoppingListSetLineItemCustomFieldAction|callable $action
     * @return $this
     */
    public function setLineItemCustomField($action = null)
    {
        $this->addAction($this->resolveAction(ShoppingListSetLineItemCustomFieldAction::class, $action));
        return $this;
    }

    /**
     * @link https://docs.commercetools.com/http-api-projects-shoppingLists.html#set-lineitem-custom-type
     * @param ShoppingListSetLineItemCustomTypeAction|callable $action
     * @return $this
     */
    public function setLineItemCustomType($action = null)
    {
        $this->addAction($this->resolveAction(ShoppingListSetLineItemCustomTypeAction::class, $action));
        return $this;
    }

    /**
     * @link https://docs.commercetools.com/http-api-projects-shoppingLists.html#set-slug
     * @param ShoppingListSetSlugAction|callable $action
     * @return $this
     */
    public function setSlug($action = null)
    {
        $this->addAction($this->resolveAction(ShoppingListSetSlugAction::class, $action));
        return $this;
    }

    /**
     * @link https://docs.commercetools.com/http-api-projects-shoppingLists.html#set-store
     * @param ShoppingListSetStoreAction|callable $action
     * @return $this
     */
    public function setStore($action = null)
    {
        $this->addAction($this->resolveAction(ShoppingListSetStoreAction::class, $action));
        return $this;
    }

    /**
     * @link https://docs.commercetools.com/http-api-projects-shoppingLists.html#set-textlineitem-customfield
     * @param ShoppingListSetTextLineItemCustomFieldAction|callable $action
     * @return $this
     */
    public function setTextLineItemCustomField($action = null)
    {
        $this->addAction($this->resolveAction(ShoppingListSetTextLineItemCustomFieldAction::class, $action));
        return $this;
    }

    /**
     * @link https://docs.commercetools.com/http-api-projects-shoppingLists.html#set-textlineitem-custom-type
     * @param ShoppingListSetTextLineItemCustomTypeAction|callable $action
     * @return $this
     */
    public function setTextLineItemCustomType($action = null)
    {
        $this->addAction($this->resolveAction(ShoppingListSetTextLineItemCustomTypeAction::class, $action));
        return $this;
    }

    /**
     * @link https://docs.commercetools.com/http-api-projects-shoppingLists.html#set-textlineitem-description
     * @param ShoppingListSetTextLineItemDescriptionAction|callable $action
     * @return $this
     */
    public function setTextLineItemDescription($action = null)
    {
        $this->addAction($this->resolveAction(ShoppingListSetTextLineItemDescriptionAction::class, $action));
        return $this;
    }

    /**
     * @return ShoppingListsActionBuilder
     */
    public static function of()
    {
        return new self();
    }

    /**
     * @param $class
     * @param $action
     * @return AbstractAction
     * @throws InvalidArgumentException
     */
    private function resolveAction($class, $action = null)
    {
        if (is_null($action) || is_callable($action)) {
            $callback = $action;
            $emptyAction = $class::of();
            $action = $this->callback($emptyAction, $callback);
        }
        if ($action instanceof $class) {
            return $action;
        }
        throw new InvalidArgumentException(
            sprintf('Expected method to be called with or callable to return %s', $class)
        );
    }

    /**
     * @param $action
     * @param callable $callback
     * @return AbstractAction
     */
    private function callback($action, callable $callback = null)
    {
        if (!is_null($callback)) {
            $action = $callback($action);
        }
        return $action;
    }

    /**
     * @param AbstractAction $action
     * @return $this;
     */
    public function addAction(AbstractAction $action)
    {
        $this->actions[] = $action;
        return $this;
    }

    /**
     * @return array
     */
    public function getActions()
    {
        return $this->actions;
    }


    /**
     * @param array $actions
     * @return $this
     */
    public function setActions(array $actions)
    {
        $this->actions = $actions;
        return $this;
    }
}
PHP SDK API documentation generated by ApiGen