Overview
  • Package
  • Class
  • Tree
  • Todo

Packages

  • AddonValue
    • Interfaces
  • ApiV2Controllers
  • Category
    • Collections
    • Entities
    • Factories
    • Interfaces
    • Providers
    • Repositories
    • Storages
  • Customer
    • Address
    • Country
    • CountryZone
    • Interfaces
    • Validation
    • ValueObjects
  • Email
    • Collections
    • Entities
    • Exceptions
    • Interfaces
    • Repository
    • ValueObjects
  • Http
    • Collections
    • Exceptions
    • Factories
    • Interfaces
    • ValueObjects
  • Loaders
    • CrossCuttingLoader
    • GXCoreLoader
    • Interfaces
  • None
  • Order
    • Collections
    • Entities
    • Factories
    • Interfaces
    • Repositories
    • Storages
    • ValueObjects
  • Product
    • Collections
    • Entities
    • Factories
    • Interfaces
    • Providers
    • Repositories
    • Storages
  • ProductModule
    • Collections
    • Deleter
    • Entities
    • Factories
    • Interface
    • Interfaces
    • Reader
    • Repositories
    • Writer
  • Shared
    • Exceptions
    • FileSystem
    • Interfaces
    • Storage
    • Types
  • Statistics
    • Interfaces
  • UserConfiguration
    • Interfaces
    • Repository

Classes

  • AbstractAddonValueServiceFactory
  • AbstractAddonValueStorage
  • AbstractApiV2Controller
  • AbstractCategoryServiceFactory
  • AbstractCollection
  • AbstractCustomerFactory
  • AbstractCustomerServiceFactory
  • AbstractFileStorage
  • AbstractHttpContextFactory
  • AbstractHttpViewControllerRegistryFactory
  • AbstractImagesApiV2Controller
  • AbstractOrderServiceFactory
  • AbstractProductAttributeServiceFactory
  • AbstractProductServiceFactory
  • AddonValueService
  • AddonValueServiceFactory
  • AddonValueStorageFactory
  • AddressBlock
  • AddressBookService
  • AddressClass
  • AddressesApiV2Controller
  • AddressFormatProvider
  • AdminHttpViewController
  • AdminPageHttpControllerResponse
  • Asset
  • AssetCollection
  • AttachmentCollection
  • AttachmentName
  • AttachmentPath
  • AttachmentsApiV2Controller
  • AttachmentsHandler
  • BoolType
  • CategoriesApiV2Controller
  • Category
  • CategoryAddonValueStorage
  • CategoryFactory
  • CategoryIconsApiV2Controller
  • CategoryImagesApiV2Controller
  • CategoryListItem
  • CategoryListItemCollection
  • CategoryListProvider
  • CategoryListProviderFactory
  • CategoryObjectService
  • CategoryReadService
  • CategoryRepository
  • CategoryRepositoryDeleter
  • CategoryRepositoryReader
  • CategoryRepositoryWriter
  • CategoryServiceFactory
  • CategorySettings
  • CategorySettingsRepository
  • CategorySettingsRepositoryReader
  • CategorySettingsRepositoryWriter
  • CategoryWriteService
  • ContactCollection
  • ContactName
  • ContactType
  • CountriesApiV2Controller
  • CountryService
  • CrossCuttingLoader
  • CurrencyCode
  • Customer
  • CustomerAccountInputValidator
  • CustomerAddress
  • CustomerAddressDeleter
  • CustomerAddressInputValidator
  • CustomerAddressReader
  • CustomerAddressRepository
  • CustomerAddressWriter
  • CustomerB2BStatus
  • CustomerCallNumber
  • CustomerCity
  • CustomerCompany
  • CustomerCountry
  • CustomerCountryIso2
  • CustomerCountryIso3
  • CustomerCountryName
  • CustomerCountryReader
  • CustomerCountryRepository
  • CustomerCountryZone
  • CustomerCountryZoneIsoCode
  • CustomerCountryZoneName
  • CustomerCountryZoneReader
  • CustomerCountryZoneRepository
  • CustomerDateOfBirth
  • CustomerDeleter
  • CustomerEmail
  • CustomerFactory
  • CustomerFirstname
  • CustomerGender
  • CustomerInputValidator
  • CustomerInputValidatorSettings
  • CustomerLastname
  • CustomerNumber
  • CustomerPassword
  • CustomerPostcode
  • CustomerReader
  • CustomerReadService
  • CustomerRegistrationInputValidatorService
  • CustomerRepository
  • CustomersApiV2Controller
  • CustomerService
  • CustomerServiceFactory
  • CustomerServiceSettings
  • CustomerStatusInformation
  • CustomerStatusProvider
  • CustomerStreet
  • CustomerSuburb
  • CustomerVatNumber
  • CustomerWriter
  • CustomerWriteService
  • DecimalType
  • DefaultApiV2Controller
  • EditableCollection
  • EditableKeyValueCollection
  • Email
  • EmailAddress
  • EmailAttachment
  • EmailCollection
  • EmailContact
  • EmailContent
  • EmailDeleter
  • EmailFactory
  • EmailReader
  • EmailRepository
  • EmailsApiV2Controller
  • EmailService
  • EmailStringType
  • EmailSubject
  • EmailWriter
  • EmptyCurrencyCode
  • EmptyDateTime
  • EmptyLanguageCode
  • EmptyOrderItemDownloadInformation
  • EmptyProductImage
  • EnvCategoryServiceSettings
  • EnvironmentHttpContextFactory
  • EnvironmentHttpViewControllerRegistryFactory
  • EnvProductImageFileStorageSettings
  • ExistingDirectory
  • ExistingFile
  • FilenameStringType
  • GXCoreLoader
  • GXCoreLoaderSettings
  • GXEngineOrder
  • GXEngineProduct
  • HttpApiV2Controller
  • HttpContext
  • HttpContextReader
  • HttpControllerResponse
  • HttpDispatcher
  • HttpResponseProcessor
  • HttpService
  • HttpServiceFactory
  • HttpViewController
  • HttpViewControllerFactory
  • HttpViewControllerRegistry
  • IdCollection
  • IdType
  • ImageFileStorage
  • IntType
  • JsonHttpControllerResponse
  • KeyValueCollection
  • LanguageCode
  • LegacyProductImageProcessing
  • MailerAdapter
  • NonEmptyStringType
  • OrderAddonValueStorage
  • OrderFactory
  • OrderItem
  • OrderItemAddonValueStorage
  • OrderItemAttribute
  • OrderItemAttributeCollection
  • OrderItemAttributeFactory
  • OrderItemAttributeRepository
  • OrderItemAttributeRepositoryDeleter
  • OrderItemAttributeRepositoryFactory
  • OrderItemAttributeRepositoryReader
  • OrderItemAttributeRepositoryWriter
  • OrderItemCollection
  • OrderItemDownloadInformation
  • OrderItemFactory
  • OrderItemProperty
  • OrderItemPropertyFactory
  • OrderItemPropertyRepository
  • OrderItemPropertyRepositoryDeleter
  • OrderItemPropertyRepositoryReader
  • OrderItemPropertyRepositoryWriter
  • OrderItemRepository
  • OrderItemRepositoryDeleter
  • OrderItemRepositoryReader
  • OrderItemRepositoryWriter
  • OrderListGenerator
  • OrderListItem
  • OrderListItemCollection
  • OrderObjectService
  • OrderPaymentType
  • OrderReadService
  • OrderRepository
  • OrderRepositoryDeleter
  • OrderRepositoryReader
  • OrderRepositoryWriter
  • OrdersApiV2Controller
  • OrderServiceFactory
  • OrderServiceSettings
  • OrderShippingType
  • OrdersHistoryApiV2Controller
  • OrdersItemsApiV2Controller
  • OrdersItemsAttributesApiV2Controller
  • OrderStatusHistoryListItem
  • OrderStatusHistoryListItemCollection
  • OrderStatusHistoryStorage
  • OrdersTotalsApiV2Controller
  • OrderTotal
  • OrderTotalCollection
  • OrderTotalFactory
  • OrderTotalRepository
  • OrderTotalRepositoryDeleter
  • OrderTotalRepositoryReader
  • OrderTotalRepositoryWriter
  • OrderWriteService
  • ProductAddonValueStorage
  • ProductAttribute
  • ProductAttributeCollection
  • ProductAttributeFactory
  • ProductAttributeObjectService
  • ProductAttributeRepository
  • ProductAttributeRepositoryDeleter
  • ProductAttributeRepositoryReader
  • ProductAttributeRepositoryWriter
  • ProductAttributeService
  • ProductAttributeServiceFactory
  • ProductCategoryLinker
  • ProductFactory
  • ProductImage
  • ProductImageCollection
  • ProductImageContainer
  • ProductImageContainerRepository
  • ProductImageFileStorage
  • ProductImagesApiV2Controller
  • ProductListItem
  • ProductListItemCollection
  • ProductListProvider
  • ProductListProviderFactory
  • ProductObjectService
  • ProductPermissionSetter
  • ProductReadService
  • ProductRepository
  • ProductRepositoryDeleter
  • ProductRepositoryReader
  • ProductRepositoryWriter
  • ProductsApiV2Controller
  • ProductServiceFactory
  • ProductSettings
  • ProductSettingsRepository
  • ProductSettingsRepositoryReader
  • ProductSettingsRepositoryWriter
  • ProductsLinksApiV2Controller
  • ProductWriteService
  • RedirectHttpControllerResponse
  • StaticCrossCuttingLoader
  • StaticGXCoreLoader
  • StatisticsService
  • StoredCategory
  • StoredOrderItem
  • StoredOrderItemAttribute
  • StoredOrderItemAttributeCollection
  • StoredOrderItemCollection
  • StoredOrderItemProperty
  • StoredOrderTotal
  • StoredOrderTotalCollection
  • StoredProduct
  • StoredProductAttribute
  • StoredProductAttributeCollection
  • StringCollection
  • StringType
  • UserConfigurationReader
  • UserConfigurationService
  • UserConfigurationWriter
  • VatNumberValidator
  • WritableDirectory
  • WritableFile
  • YetAnotherLanguageProvider
  • ZonesApiV2Controller

Interfaces

  • AddonValueContainerInterface
  • AddonValueServiceInterface
  • AddonValueStorageFactoryInterface
  • AddressBlockInterface
  • AddressBookServiceInterface
  • AddressClassInterface
  • AddressFormatProviderInterface
  • AssetCollectionInterface
  • AssetInterface
  • AttachmentCollectionInterface
  • AttachmentNameInterface
  • AttachmentPathInterface
  • AttachmentsHandlerInterface
  • CategoryFactoryInterface
  • CategoryInterface
  • CategoryListProviderFactoryInterface
  • CategoryListProviderInterface
  • CategoryObjectServiceInterface
  • CategoryReadServiceInterface
  • CategoryRepositoryDeleterInterface
  • CategoryRepositoryInterface
  • CategoryRepositoryReaderInterface
  • CategoryRepositoryWriterInterface
  • CategoryServiceSettingsInterface
  • CategorySettingsInterface
  • CategorySettingsRepositoryInterface
  • CategorySettingsRepositoryReaderInterface
  • CategorySettingsRepositoryWriterInterface
  • CategoryWriteServiceInterface
  • ContactCollectionInterface
  • ContactNameInterface
  • ContactTypeInterface
  • ContentViewInterface
  • CountryServiceInterface
  • CrossCuttingLoaderInterface
  • CrossCuttingObjectInterface
  • CustomerAccountInputValidatorInterface
  • CustomerAddressDeleterInterface
  • CustomerAddressInputValidatorInterface
  • CustomerAddressInterface
  • CustomerAddressReaderInterface
  • CustomerAddressRepositoryInterface
  • CustomerAddressWriterInterface
  • CustomerB2BStatusInterface
  • CustomerCallNumberInterface
  • CustomerCityInterface
  • CustomerCompanyInterface
  • CustomerCountryInterface
  • CustomerCountryIso2Interface
  • CustomerCountryIso3Interface
  • CustomerCountryNameInterface
  • CustomerCountryReaderInterface
  • CustomerCountryRepositoryInterface
  • CustomerCountryZoneInterface
  • CustomerCountryZoneIsoCodeInterface
  • CustomerCountryZoneNameInterface
  • CustomerCountryZoneReaderInterface
  • CustomerCountryZoneRepositoryInterface
  • CustomerDeleterInterface
  • CustomerEmailInterface
  • CustomerFirstnameInterface
  • CustomerGenderInterface
  • CustomerInputValidatorInterface
  • CustomerInputValidatorSettingsInterface
  • CustomerInterface
  • CustomerLastnameInterface
  • CustomerNumberInterface
  • CustomerPasswordInterface
  • CustomerPostcodeInterface
  • CustomerReaderInterface
  • CustomerReadServiceInterface
  • CustomerRegistrationInputValidatorServiceInterface
  • CustomerRepositoryInterface
  • CustomerServiceInterface
  • CustomerServiceSettingsInterface
  • CustomerStatusProviderInterface
  • CustomerStreetInterface
  • CustomerSuburbInterface
  • CustomerVatNumberInterface
  • CustomerWriterInterface
  • CustomerWriteServiceInterface
  • EmailAddressInterface
  • EmailAttachmentInterface
  • EmailCollectionInterface
  • EmailContactInterface
  • EmailContentInterface
  • EmailDeleterInterface
  • EmailFactoryInterface
  • EmailInterface
  • EmailReaderInterface
  • EmailRepositoryInterface
  • EmailServiceInterface
  • EmailSubjectInterface
  • EmailWriterInterface
  • GXCoreLoaderInterface
  • GXCoreLoaderSettingsInterface
  • HttpContextInterface
  • HttpContextReaderInterface
  • HttpControllerResponseInterface
  • HttpDispatcherInterface
  • HttpResponseProcessorInterface
  • HttpServiceFactoryInterface
  • HttpServiceInterface
  • HttpViewControllerFactoryInterface
  • HttpViewControllerInterface
  • HttpViewControllerRegistryInterface
  • IdInterface
  • LanguageProviderInterface
  • MailerAdapterInterface
  • OrderFactoryInterface
  • OrderInterface
  • OrderItemAttributeFactoryInterface
  • OrderItemAttributeInterface
  • OrderItemAttributeRepositoryDeleterInterface
  • OrderItemAttributeRepositoryFactoryInterface
  • OrderItemAttributeRepositoryInterface
  • OrderItemAttributeRepositoryReaderInterface
  • OrderItemAttributeRepositoryWriterInterface
  • OrderItemFactoryInterface
  • OrderItemInterface
  • OrderItemPropertyFactoryInterface
  • OrderItemPropertyRepositoryDeleterInterface
  • OrderItemPropertyRepositoryReaderInterface
  • OrderItemPropertyRepositoryWriterInterface
  • OrderItemRepositoryDeleterInterface
  • OrderItemRepositoryInterface
  • OrderItemRepositoryReaderInterface
  • OrderItemRepositoryWriterInterface
  • OrderListGeneratorInterface
  • OrderObjectServiceInterface
  • OrderPaymentTypeInterface
  • OrderReadServiceInterface
  • OrderRepositoryDeleterInterface
  • OrderRepositoryInterface
  • OrderRepositoryReaderInterface
  • OrderRepositoryWriterInterface
  • OrderServiceSettingsInterface
  • OrderShippingTypeInterface
  • OrderStatusHistoryReaderInterface
  • OrderStatusHistoryWriterInterface
  • OrderTotalFactoryInterface
  • OrderTotalInterface
  • OrderTotalRepositoryDeleterInterface
  • OrderTotalRepositoryInterface
  • OrderTotalRepositoryReaderInterface
  • OrderTotalRepositoryWriterInterface
  • OrderWriteServiceInterface
  • ProductAttributeFactoryInterface
  • ProductAttributeInterface
  • ProductAttributeObjectServiceInterface
  • ProductAttributeRepositoryDeleterInterface
  • ProductAttributeRepositoryInterface
  • ProductAttributeRepositoryReaderInterface
  • ProductAttributeRepositoryWriterInterface
  • ProductAttributeServiceInterface
  • ProductCategoryLinkerInterface
  • ProductFactoryInterface
  • ProductImageContainerInterface
  • ProductImageContainerRepositoryInterface
  • ProductImageInterface
  • ProductImagePathsSettingsInterface
  • ProductImageProcessingInterface
  • ProductInterface
  • ProductListProviderFactoryInterface
  • ProductListProviderInterface
  • ProductObjectServiceInterface
  • ProductPermissionSetterInterface
  • ProductReadServiceInterface
  • ProductRepositoryDeleterInterface
  • ProductRepositoryInterface
  • ProductRepositoryReaderInterface
  • ProductRepositoryWriterInterface
  • ProductSettingsInterface
  • ProductSettingsRepositoryInterface
  • ProductSettingsRepositoryReaderInterface
  • ProductSettingsRepositoryWriterInterface
  • ProductWriteServiceInterface
  • StatisticsServiceInterface
  • StoredCategoryInterface
  • StoredOrderItemAttributeInterface
  • StoredOrderItemInterface
  • StoredOrderTotalInterface
  • StoredProductAttributeInterface
  • StoredProductInterface
  • UserConfigurationReaderInterface
  • UserConfigurationServiceInterface
  • UserConfigurationWriterInterface
  • VatNumberValidatorInterface

Exceptions

  • AjaxException
  • AttachmentNotFoundException
  • FileNotFoundException
  • HttpApiV2Exception
  • MissingControllerNameException
  • UnknownEnvironmentException
  1 <?php
  2 
  3 /* --------------------------------------------------------------
  4    OrdersTotalsApiV2Controller.inc.php 2016-03-07
  5    Gambio GmbH
  6    http://www.gambio.de
  7    Copyright (c) 2016 Gambio GmbH
  8    Released under the GNU General Public License (Version 2)
  9    [http://www.gnu.org/licenses/gpl-2.0.html]
 10    --------------------------------------------------------------
 11 */
 12 
 13 MainFactory::load_class('HttpApiV2Controller');
 14 
 15 /**
 16  * Class OrdersTotalsApiV2Controller
 17  *
 18  * Notice: This controller is a sub-resource of the OrdersV2Controller.
 19  *
 20  * @category   System
 21  * @package    ApiV2Controllers
 22  */
 23 class OrdersTotalsApiV2Controller extends HttpApiV2Controller
 24 {
 25     /**
 26      * Order write service.
 27      * 
 28      * @var OrderWriteService
 29      */
 30     protected $orderWriteService;
 31 
 32     /**
 33      * Order read service.
 34      * 
 35      * @var OrderReadService
 36      */
 37     protected $orderReadService;
 38 
 39     /**
 40      * Order JSON serializer.
 41      * 
 42      * @var OrderJsonSerializer
 43      */
 44     protected $orderJsonSerializer;
 45 
 46 
 47     /**
 48      * Initializes API Controller
 49      * 
 50      * @throws HttpApiV2Exception On missing order ID.
 51      */
 52     protected function __initialize()
 53     {
 54         // Check if the order ID was provided
 55         if(!isset($this->uri[1]) || !is_numeric($this->uri[1]))
 56         {
 57             throw new HttpApiV2Exception('Order record ID was not provided in the resource URL.', 400);
 58         }
 59 
 60         $this->orderWriteService   = StaticGXCoreLoader::getService('OrderWrite');
 61         $this->orderReadService    = StaticGXCoreLoader::getService('OrderRead');
 62         $this->orderJsonSerializer = MainFactory::create('OrderJsonSerializer');
 63     }
 64 
 65 
 66     /**
 67      * @api        {post} /orders/:id/totals Create Order Total
 68      * @apiVersion 2.1.0
 69      * @apiName    CreateOrderTotal
 70      * @apiGroup   Orders
 71      *
 72      * @apiDescription
 73      * Creates a new order total entry to the existing order. The order total JSON format must be the same with the
 74      * "totals" entries in the original order total.
 75      *
 76      * @apiExample {json} Request-Body
 77      * {
 78      *   "title": "Zwischensumme:",
 79      *   "value": 50,
 80      *   "valueText": "50,00 EUR",
 81      *   "class": "ot_subtotal",
 82      *   "sortOrder": 10
 83      * }
 84      *
 85      * @apiSuccess (Success 201) Response-Body If successful, this method returns a complete Order Total resource in the
 86      * response body.
 87      *
 88      * @apiError 400-BadRequest The request body was empty.
 89      *           
 90      * @apiError (Error 5xx) 500-InternalError One of the given properties has an invalid value type.
 91      *           
 92      * @apiErrorExample Error-Response (Empty request body)
 93      * HTTP/1.1 400 Bad Request
 94      * {
 95      *   "code": 400,
 96      *   "status": "error",
 97      *   "message": "Order total data were not provided."
 98      * }
 99      */
100     public function post()
101     {
102         $orderTotalJsonString = $this->api->request->getBody();
103 
104         if(empty($orderTotalJsonString))
105         {
106             throw new HttpApiV2Exception('Order total data were not provided.', 400);
107         }
108 
109         $orderId = new IdType($this->uri[1]);
110 
111         $orderTotal = $this->orderJsonSerializer->deserializeOrderTotal(json_decode($orderTotalJsonString));
112 
113         $orderTotalId = $this->orderWriteService->addOrderTotal($orderId, $orderTotal);
114         $order = $this->orderReadService->getOrderById($orderId);
115 
116         foreach($order->getOrderTotals()->getArray() as $storedOrderTotal)
117         {
118             /** @var StoredOrderTotalInterface $storedOrderTotal */
119             if($storedOrderTotal->getOrderTotalId() === $orderTotalId)
120             {
121                 $response = $this->orderJsonSerializer->serializeOrderTotal($storedOrderTotal);
122             }
123         }
124 
125         $this->_writeResponse($response, 201);
126     }
127 
128 
129     /**
130      * @api        {put} /orders/:id/totals/:id Update Order Total
131      * @apiVersion 2.1.0
132      * @apiName    UpdateOrderTotal
133      * @apiGroup   Orders
134      *
135      * @apiDescription
136      * Use this method to update an existing order total. Use the same order total JSON format as in the POST method.
137      *
138      * @apiSuccess Response-Body If successful, this method returns the updated Order Total resource in the
139      * response body.
140      *
141      * @apiError 400-BadRequest The order total ID in the URI was not provided or is invalid.
142      * @apiErrorExample Error-Response (Missing ID)
143      * HTTP/1.1 400 Bad Request
144      * {
145      *   "code": 400,
146      *   "status": "error",
147      *   "message": "Order total record ID was not provided or is invalid."
148      * }
149      *
150      * @apiError 400-BadRequest The request body is empty.
151      * @apiErrorExample Error-Response (Empty request body)
152      * HTTP/1.1 400 Bad Request
153      * {
154      *   "code": 400,
155      *   "status": "error",
156      *   "message": "Order total data were not provided."
157      * }
158      *
159      * @apiError 404-NotFound The provided order total was not found in the given order.
160      * @apiErrorExample Error-Response (Not found in order)
161      * HTTP/1.1 404 Not Found
162      * {
163      *   "code": 404,
164      *   "status": "error",
165      *   "message": "The provided order total ID does not exist in the given order!"
166      * }
167      */
168     public function put()
169     {
170         if(!isset($this->uri[3]) || !is_numeric($this->uri[3]))
171         {
172             throw new HttpApiV2Exception('Order total record ID was not provided or is invalid: '
173                                          . gettype($this->uri[3]), 400);
174         }
175 
176         $orderTotalJsonString = $this->api->request->getBody();
177 
178         if(empty($orderTotalJsonString))
179         {
180             throw new HttpApiV2Exception('Order total data were not provided.', 400);
181         }
182 
183         $orderId = new IdType($this->uri[1]);
184         $order   = $this->orderReadService->getOrderById($orderId);
185 
186         $baseOrderTotal = null;
187         foreach($order->getOrderTotals()->getArray() as $orderTotal)
188         {
189             if($orderTotal->getOrderTotalId() === (int)$this->uri[3])
190             {
191                 $baseOrderTotal = $orderTotal;
192                 break;
193             }
194         }
195 
196         if($baseOrderTotal === null)
197         {
198             throw new HttpApiV2Exception('The provided order total ID does not exist in the given order!', 404);
199         }
200 
201         // Ensure that the order total has the correct order total id of the request url
202         $orderTotalJsonString = $this->_setJsonValue($orderTotalJsonString, 'id', (int)$this->uri[3]);
203 
204         $storedOrderTotal = $this->orderJsonSerializer->deserializeOrderTotal(json_decode($orderTotalJsonString),
205                                                                               $baseOrderTotal);
206 
207         $this->orderWriteService->updateOrderTotal($storedOrderTotal);
208 
209         $response = $this->orderJsonSerializer->serializeOrderTotal($storedOrderTotal);
210         $this->_writeResponse($response);
211     }
212 
213     /**
214      * @api        {delete} /orders/:id/totals/:id Delete Order Total
215      * @apiVersion 2.1.0
216      * @apiName    DeleteOrderTotal
217      * @apiGroup   Orders
218      *
219      * @apiDescription
220      * Use this method to remove an order total from an existing order.
221      *
222      * @apiSuccessExample {json} Success-Response
223      * {
224      *   "code" => 200,
225      *   "status" => "success",
226      *   "action" => "delete",
227      *   "resource" => "OrderTotal",
228      *   "orderId" => 400345,
229      *   "orderTotalId" => 1
230      * }
231      *
232      * @apiError 400-BadRequest The order total ID in the URI was not provided or is invalid.
233      * @apiError 404-NotFound The provided order total was not found in the given order.
234      *           
235      * @apiErrorExample Error-Response
236      * HTTP/1.1 400 Bad Request
237      * {
238      *   "code": 400,
239      *   "status": "error",
240      *   "message": "Order total record ID was not provided in the resource URL."
241      * }
242      *
243      */
244     public function delete()
245     {
246         // Check if record ID was provided.
247         if(!isset($this->uri[3]) || !is_numeric($this->uri[3]))
248         {
249             throw new HttpApiV2Exception('Order total record ID was not provided in the resource URL.', 400);
250         }
251 
252         $orderId = new IdType($this->uri[1]);
253 
254         $order = $this->orderReadService->getOrderById($orderId);
255 
256         $storedOrderTotal = null;
257         foreach($order->getOrderTotals()->getArray() as $orderTotal)
258         {
259             if($orderTotal->getOrderTotalId() === (int)$this->uri[3])
260             {
261                 $storedOrderTotal = $orderTotal;
262                 break;
263             }
264         }
265         
266         if($storedOrderTotal === null)
267         {
268             throw new HttpApiV2Exception('The provided order total ID does not exist in the given order!', 404);
269         }
270 
271         // Remove order total record from database.
272         $this->orderWriteService->removeOrderTotal($storedOrderTotal);
273 
274         // Return response JSON.
275         $response = array(
276             'code'         => 200,
277             'status'       => 'success',
278             'action'       => 'delete',
279             'resource'     => 'OrderTotal',
280             'orderId'      => (int)$this->uri[1],
281             'orderTotalId' => (int)$this->uri[3]
282         );
283 
284         $this->_writeResponse($response);
285     }
286 
287     /**
288      * @api        {get} /orders/:id/totals/:id Get Order Total
289      * @apiVersion 2.1.0
290      * @apiName    GetOrderTotal
291      * @apiGroup   Orders
292      *
293      * @apiDescription
294      * Returns all or just a single order total from an existing orders. All the GET manipulation parameters are applied
295      * with this method (search, sort, minimize, paginate etc).
296      *
297      * @apiExample {curl} Get All Entries
298      *             curl -i --user admin@shop.de:12345 http://shop.de/api.php/v2/orders/400785/totals
299      *
300      * @apiExample {curl} Get Entry With ID = 4
301      *             curl -i --user admin@shop.de:12345 http://shop.de/api.php/v2/orders/400242/totals/4
302      */
303     public function get()
304     {
305         $orderId = new IdType($this->uri[1]);
306         $order   = $this->orderReadService->getOrderById($orderId);
307 
308         $response = array();
309         foreach($order->getOrderTotals()->getArray() as $orderTotal)
310         {
311             $response[] = $this->orderJsonSerializer->serializeOrderTotal($orderTotal);
312         }
313 
314         if(isset($this->uri[3]))
315         {
316             foreach($response as $item)
317             {
318                 if($item['id'] === (int)$this->uri[3])
319                 {
320                     $response = $item;
321                     break;
322                 }
323             }
324         }
325         else if($this->api->request->get('q') !== null)
326         {
327             $this->_searchResponse($response, $this->api->request->get('q'));
328         }
329 
330         $this->_paginateResponse($response);
331         $this->_sortResponse($response);
332         $this->_minimizeResponse($response);
333         $this->_linkResponse($response);
334         $this->_writeResponse($response);
335     }
336 }
337 
API documentation generated by ApiGen