2

We have request to create custom REST webservice for creating gift orders and we are successfully able to create order for single item but facing issues on taking multi items as input.

Can anyone help please?

We have created below files to handle

  1. CreateOrderInterface

    interface CreateOrderInterface
    {
     /**
     * @param string $giftCardCode
     * @return boolean;
     * @throws \Exception
     */
     public function checkGiftCard($giftCardCode);
     /**
     * @param XYZ\GiftCard\Api\JsondataInterface $orderData
     * @param XYZ\GiftCard\Api\AddressdataInterface $customerAddress
     * @param XYZ\GiftCard\Api\BillingdataInterface $billingAddress
     * @param XYZ\GiftCard\Api\ShippingdataInterface $shippingAddress
     * @param XYZ\GiftCard\Api\ItemsdataInterface $items
     * @return string;
     * @throws \Exception
     */
     public function createOrder($orderData, $customerAddress,$billingAddress,$shippingAddress,$items);
    }
    
  2. createOrder Model

    class createOrder
    {
     /**
     * @param \XYZ\GiftCard\Api\Kensium\GiftCard\Api\JsondataInterface $jsonOrderData
     * @param \XYZ\GiftCard\Api\Kensium\GiftCard\Api\AddressdataInterface $customerAddress
     * @param \XYZ\GiftCard\Api\Kensium\GiftCard\Api\BillingdataInterface $billingAddress
     * @param \XYZ\GiftCard\Api\Kensium\GiftCard\Api\ShippingdataInterface $shippingAddress
     * @param \XYZ\GiftCard\Api\Kensium\GiftCard\Api\ItemsdataInterface $items
     * @return array|string
     * @throws \Exception
     * @throws \Magento\Framework\Exception\LocalizedException
     * @throws bool
     */
     public function createOrder($jsonOrderData, $customerAddress, $billingAddress, $shippingAddress,$items)
     {
     $invalidType = array();
     $invalidSku = array();
     $invalidAmount = array();
     print_r($jsonOrderData->getItems());die;
     }
    }
    
Alex Paliarush
13.8k5 gold badges53 silver badges57 bronze badges
asked Apr 5, 2016 at 7:36
0

1 Answer 1

8

To pass an array of items annotation should be specified in the following format:

@param \XYZ\GiftCard\Api\ItemsdataInterface[] $items

Square brackets here mean, that you are passing an indexed array containing objects of \XYZ\GiftCard\Api\ItemsdataInterface type.

One more note regarding @return array|string, all parameters/return values in Magento 2 web API must be concrete types, it is not allowed to specify types like int|string for example. It is possible however to use string|null, which means that this value is optional. Also array should never be used, instead use string[], \Custom\Type[] which would let the system know array of which types is declared.

answered Apr 11, 2016 at 15:19
1
  • @Alex how to do same in magneto1.9? Commented May 7, 2017 at 10:17

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.