public function Handle_BuyerRegister($metadata, $request, $encoder)
 {
     // required arguments
     if (!isset($request['Buyer'])) {
         CartAPI_Helpers::dieOnError($encoder, 'IncompleteRequest', 'Buyer argument missing');
     }
     // register with user and password
     if (isset($request['Buyer']['Username']) && isset($request['Buyer']['Password'])) {
         // dies on error, syncs cookie on success
         $this->handleBuyerRegisterUserPassword($metadata, $request, $encoder);
     } else {
         // login with an external service
         if (isset($request['Buyer']['AuthServiceName']) && isset($request['Buyer']['AuthServiceToken'])) {
             // dies on error, syncs cookie on success
             $this->handleBuyerRegisterAuthService($metadata, $request['Buyer'], $encoder);
         } else {
             CartAPI_Helpers::dieOnError($encoder, 'IncompleteRequest', 'Register arguments missing');
         }
     }
     // if here we assume the customer is authenticated and the cookie is synced
     // create the response
     $response = CartAPI_Helpers::createSuccessResponse($encoder);
     // see if we need to login too, then add the session id
     if (!isset($request['Login']) || $request['Login'] == 'true') {
         $encoder->addString($response, 'SessionId', $this->getCookieSessionId());
     }
     // show the response
     $encoder->render($response);
 }
 public function Handle_GetSingleItem($metadata, $request, $encoder)
 {
     // required arguments
     if (!isset($request['Id'])) {
         CartAPI_Helpers::dieOnError($encoder, 'IncompleteRequest', 'Id argument missing');
     }
     // load the product
     global $cookie;
     $id_lang = $cookie->id_lang;
     $product = $this->getProductFromProductId($request['Id'], $id_lang);
     if (!Validate::isLoadedObject($product)) {
         CartAPI_Helpers::dieOnError($encoder, 'ItemNotFound', Tools::displayError('Product not found'));
     }
     // create the response
     $response = CartAPI_Helpers::createSuccessResponse($encoder, CartAPI_Handlers_Helpers::getLocale());
     // add the item to the response
     $item =& $encoder->addContainer($response, 'Item');
     // fill in the item fields
     $encoder->addNumber($item, 'Id', $product->id);
     $this->addTitleFromProduct($encoder, $item, $product);
     $price = $this->getPriceFromProduct($product);
     $encoder->addNumber($item, 'Price', $price);
     $referencePrice = $this->getReferencePriceFromProduct($product);
     if ($referencePrice > $price) {
         $encoder->addNumber($item, 'ReferencePrice', $referencePrice);
     }
     $this->addThumbnailUrlFromProduct($encoder, $item, $product);
     $this->addSubtitleFromProduct($encoder, $item, $product);
     $this->addImageUrlFromProduct($encoder, $item, $product, $id_lang);
     $this->addFeaturesFromProduct($encoder, $item, $product, $id_lang);
     $this->addAvailabilityFromProduct($encoder, $item, $product);
     $this->addVariationsAndCombinationsFromProduct($encoder, $item, $product, $id_lang);
     $this->addCustomizationsFromProduct($encoder, $item, $product, $id_lang);
     $this->addResourcesFromProduct($encoder, $item, $product, $id_lang);
     $this->addExtraFieldsFromProduct($metadata, $request, $encoder, $item, $product, $id_lang);
     // show the response
     $encoder->render($response);
 }
 public function Handle_GetPaymentMethods($metadata, $request, $encoder)
 {
     // required arguments
     if (!isset($request['Order'])) {
         CartAPI_Helpers::dieOnError($encoder, 'IncompleteRequest', 'Order argument missing');
     }
     // make sure the global cart object has the correct cart for this order
     if (!$this->syncGlobalCartIdWithOrder($request['Order'])) {
         CartAPI_Helpers::dieOnError($encoder, 'InvalidOrder', 'Order Id not set yet');
     }
     // make sure the global cart is synchronized with this order
     $this->syncGlobalCartProductsWithOrder($encoder, $request['Order']);
     // get the payment methods
     $result = $this->getPaymentMethodDictionaries($request['Order']);
     // create the response
     $response = CartAPI_Helpers::createSuccessResponse($encoder, CartAPI_Handlers_Helpers::getLocale());
     // add the shipping methods to the response if needed
     if (count($result) > 0) {
         $methods =& $encoder->addArray($response, 'PaymentMethod');
     }
     // encode each method
     foreach ($result as $phpArray) {
         // encode the method
         $method =& $encoder->addPhpArrayToArray($methods, $phpArray);
     }
     // show the response
     $encoder->render($response);
 }