/** * Represents the "redeem_coupons" action. * * @throws ShopgateLibraryException * @see http://wiki.shopgate.com/Shopgate_Plugin_API_redeem_coupons */ protected function redeemCoupons() { 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']); $couponData = $this->plugin->redeemCoupons($cart); if (!is_array($couponData)) { throw new ShopgateLibraryException(ShopgateLibraryException::PLUGIN_API_WRONG_RESPONSE_FORMAT, 'Plugin Response: ' . var_export($couponData, true)); } // Workaround: // $couponData was specified to be a ShopgateExternalCoupon[]. // Now supports the same format as checkCart(), i.e. array('external_coupons' => ShopgateExternalCoupon[]). if (!empty($couponData['external_coupons']) && is_array($couponData['external_coupons'])) { $couponData = $couponData['external_coupons']; } $responseData = array("external_coupons" => array()); foreach ($couponData 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"]); $responseData["external_coupons"][] = $coupon; } $this->responseData = $responseData; }