Пример #1
0
 /**
  * Represents the "check_cart" action.
  *
  * @throws ShopgateLibraryException
  * @see http://wiki.shopgate.com/Shopgate_Plugin_API_check_cart
  */
 protected function checkCart()
 {
     if (!isset($this->params['cart'])) {
         throw new ShopgateLibraryException(ShopgateLibraryException::PLUGIN_API_NO_CART);
     }
     if (empty($this->response)) {
         $this->response = new ShopgatePluginApiResponseAppJson($this->trace_id);
     }
     $cart = new ShopgateCart($this->params['cart']);
     $cartData = $this->plugin->checkCart($cart);
     $responseData = array("external_coupons" => array());
     if (!is_array($cartData)) {
         throw new ShopgateLibraryException(ShopgateLibraryException::PLUGIN_API_WRONG_RESPONSE_FORMAT, 'Plugin Response: ' . var_export($cartData, true));
     }
     $coupons = array();
     foreach ($cartData["external_coupons"] as $coupon) {
         if (!is_object($coupon) || !$coupon instanceof ShopgateExternalCoupon) {
             throw new ShopgateLibraryException(ShopgateLibraryException::PLUGIN_API_WRONG_RESPONSE_FORMAT, 'Plugin Response: ' . var_export($coupon, true));
         }
         $coupon = $coupon->toArray();
         unset($coupon["order_index"]);
         $coupons[] = $coupon;
     }
     $responseData["external_coupons"] = $coupons;
     $this->responseData = $responseData;
 }
Пример #2
0
 /**
  * Represents the "check_cart" action.
  *
  * @throws ShopgateLibraryException
  * @see http://wiki.shopgate.com/Shopgate_Plugin_API_check_cart
  */
 protected function checkCart()
 {
     if (!isset($this->params['cart'])) {
         throw new ShopgateLibraryException(ShopgateLibraryException::PLUGIN_API_NO_CART);
     }
     if (empty($this->response)) {
         $this->response = new ShopgatePluginApiResponseAppJson($this->trace_id);
     }
     $cart = new ShopgateCart($this->params['cart']);
     $cartData = $this->plugin->checkCart($cart);
     $responseData = array();
     $responseData['internal_cart_info'] = isset($cartData['internal_cart_info']) ? $cartData['internal_cart_info'] : null;
     if (!is_array($cartData)) {
         throw new ShopgateLibraryException(ShopgateLibraryException::PLUGIN_API_WRONG_RESPONSE_FORMAT, '$cartData is of type: ' . is_object($cartData) ? get_class($cartData) : gettype($cartData));
     }
     $responseData['currency'] = '';
     if ($cart->getCurrency()) {
         $responseData['currency'] = $cart->getCurrency();
     }
     if (!empty($cartData['currency'])) {
         $responseData['currency'] = $cartData['currency'];
     }
     if (!empty($cartData['customer']) && ($cartCustomer = $cartData['customer'])) {
         /** @var ShopgateCartCustomer $cartCustomer */
         if (!is_object($cartCustomer) || !$cartCustomer instanceof ShopgateCartCustomer) {
             throw new ShopgateLibraryException(ShopgateLibraryException::PLUGIN_API_WRONG_RESPONSE_FORMAT, "{$cartCustomer} is of type: " . is_object($cartCustomer) ? get_class($cartCustomer) : gettype($cartCustomer));
         }
         foreach ($cartCustomer->getCustomerGroups() as $cartCustomerGroup) {
             /** @var ShopgateCartCustomerGroup $cartCustomerGroup */
             if (!is_object($cartCustomerGroup) || !$cartCustomerGroup instanceof ShopgateCartCustomerGroup) {
                 throw new ShopgateLibraryException(ShopgateLibraryException::PLUGIN_API_WRONG_RESPONSE_FORMAT, '$cartCustomerGroup is of type: ' . is_object($cartCustomerGroup) ? get_class($cartCustomerGroup) : gettype($cartCustomerGroup));
             }
         }
         $responseData["customer"] = $cartCustomer->toArray();
     }
     $shippingMethods = array();
     if (!empty($cartData['shipping_methods'])) {
         foreach ($cartData["shipping_methods"] as $shippingMethod) {
             /** @var ShopgateShippingMethod $shippingMethod */
             if (!is_object($shippingMethod) || !$shippingMethod instanceof ShopgateShippingMethod) {
                 throw new ShopgateLibraryException(ShopgateLibraryException::PLUGIN_API_WRONG_RESPONSE_FORMAT, '$shippingMethod is of type: ' . is_object($shippingMethod) ? get_class($shippingMethod) : gettype($shippingMethod));
             }
             $shippingMethods[] = $shippingMethod->toArray();
         }
     }
     $responseData["shipping_methods"] = $shippingMethods;
     $paymentMethods = array();
     if (!empty($cartData['payment_methods'])) {
         foreach ($cartData["payment_methods"] as $paymentMethod) {
             /** @var ShopgatePaymentMethod $paymentMethod */
             if (!is_object($paymentMethod) || !$paymentMethod instanceof ShopgatePaymentMethod) {
                 throw new ShopgateLibraryException(ShopgateLibraryException::PLUGIN_API_WRONG_RESPONSE_FORMAT, '$paymentMethod is of type: ' . is_object($paymentMethod) ? get_class($paymentMethod) : gettype($paymentMethod));
             }
             $paymentMethods[] = $paymentMethod->toArray();
         }
     }
     $responseData["payment_methods"] = $paymentMethods;
     $cartItems = array();
     if (!empty($cartData['items'])) {
         foreach ($cartData["items"] as $cartItem) {
             /** @var ShopgateCartItem $cartItem */
             if (!is_object($cartItem) || !$cartItem instanceof ShopgateCartItem) {
                 throw new ShopgateLibraryException(ShopgateLibraryException::PLUGIN_API_WRONG_RESPONSE_FORMAT, '$cartItem is of type: ' . is_object($cartItem) ? get_class($cartItem) : gettype($cartItem));
             }
             $cartItems[] = $cartItem->toArray();
         }
     }
     $responseData["items"] = $cartItems;
     $coupons = array();
     if (!empty($cartData['external_coupons'])) {
         foreach ($cartData["external_coupons"] as $coupon) {
             /** @var ShopgateExternalCoupon $coupon */
             if (!is_object($coupon) || !$coupon instanceof ShopgateExternalCoupon) {
                 throw new ShopgateLibraryException(ShopgateLibraryException::PLUGIN_API_WRONG_RESPONSE_FORMAT, '$coupon is of type: ' . is_object($coupon) ? get_class($coupon) : gettype($coupon));
             }
             $coupon = $coupon->toArray();
             unset($coupon["order_index"]);
             $coupons[] = $coupon;
         }
     }
     $responseData["external_coupons"] = $coupons;
     $this->responseData = $responseData;
 }