shop.php 10.9 KB
<?php
class Flora_Api_Service_Shop extends Flora_Api_Service
{
    const API_PRODUCT_BYID = "shop/product";
    const API_PRODUCT_PARENT_BYID = "shop/products/parent";
    const API_PRODUCTS_LIST = "shop/products";
    const API_PRODUCTS_FEATURED = "shop/products/featured";
    const API_PRODUCTS_SEARCH = "shop/products/search";
    const API_CATEGORIES = "shop/categories";
    const API_CATEGORY_BYID = "shop/category";
    const API_CURRENCIES_LIST = "shop/currencies";
    const API_CURRENCY_BYID = "shop/currency";
    const API_ORDER_REASONS_LIST = "shop/order/reasons";
    const API_ORDER_REASON_BYID = "shop/order/reason";
    const API_ORDER_REASON_TEXTS_LIST = "shop/order/reason/texts";
    const API_ORDER_REASON_TEXT_BYID = "shop/order/reason/text";
    const API_ORDER_SUBMIT = "shop/order/submit";
    const API_ORDER_SUBMIT_PHONE = "shop/order/submit/phone";
    const API_ORDER_SUBMIT_REQUEST = "shop/order/submit/request";
    const API_ORDER_BYID = "shop/order/get";
    const API_ORDER_USER_LIST = "shop/order/my";
    const API_ORDER_CALCULATE = "shop/order/calculate";
    const API_ORDER_STATUS = "shop/order/status";
    const API_ORDER_TICKETS = "shop/order/tickets";
    const API_ORDER_TICKET_SUBMIT = "shop/order/tickets/submit";
    const API_ORDER_LAST_DELIVERED = "shop/order/lastdelivered";
    const API_PAYMENTSYSTEMS_LIST = "shop/paysystems";
    const API_PAYMENTSYSTEM_BYID = "shop/paysystem";
    const API_PROMO_CHECK = "shop/promo/check";
    const API_GALLERY = "shop/gallery";
    const API_REVIEWS_SUBMIT = "shop/reviews/submit";
    const API_REVIEWS = "shop/reviews";
    const API_REVIEW = "shop/review";
    const API_SALONS = "shop/salons";
    const API_SALONS_COUNTRIES = "shop/salons/countries";
    const API_SALONS_CITIES = "shop/salons/cities";

    /**
     * @param $id
     * @return Flora_Model_Shop_Product
     */
    public function getProductById($id)
    {
        return $this->call(self::API_PRODUCT_BYID, array("id" => $id));
    }

    /**
     * @param $id
     * @return Flora_Model_Shop_Product
     */
    public function getParentProductById($id)
    {
        return $this->call(self::API_PRODUCT_PARENT_BYID, array("id" => $id));
    }

    /**
     * @param int $parent_id
     * @return Flora_Collection|Flora_Model_Shop_Product_Category[]
     */
    public function getCategoriesList($parent_id = 0)
    {
        return $this->call(self::API_CATEGORIES, array("parent_id" => $parent_id));
    }

    /**
     * @param bool|array|int $category
     * @param array $products
     * @return Flora_Model_Shop_Product[]|Flora_Collection|mixed
     */
    public function getProductsList($category = array(), $products = array())
    {
        return $this->call(self::API_PRODUCTS_LIST, array(
            "category" => join(',', array_filter(array_map('intval', (array)$category))),
            "products" => join(',', array_filter(array_map('intval', (array)$products)))
        ));
    }

    /**
     * @param $id
     * @return Flora_Model_Shop_Product_Category
     */
    public function getCategoryById($id)
    {
        return $this->call(self::API_CATEGORY_BYID, array("id" => $id));
    }

    /**
     * @param int $city_id
     * @param int $country_id
     * @param int $get_products_of_day
     * @return Flora_Collection|Flora_Model_Shop_Product[]
     */
    public function getFeaturedProducts($city_id = 0, $country_id = 0, $get_products_of_day = 0)
    {
        return $this->call(self::API_PRODUCTS_FEATURED, array('country_id' => $country_id, 'city_id' => $city_id, 'product_of_day' => $get_products_of_day));
    }

    /**
     * @param $query string
     * @return Flora_Collection|Flora_Model_Shop_Product[]
     */
    public function searchProducts($query)
    {
        return $this->call(self::API_PRODUCTS_SEARCH, array('query' => $query));
    }

    /**
     * @param int $order_id
     * @return Flora_Model_Shop_Currency[]|Flora_Collection
     */
    public function getCurrenciesList($order_id = 0)
    {
        return $this->call(self::API_CURRENCIES_LIST, array('order_id' => $order_id));
    }

    /**
     * @param int $id
     * @param int $order_id
     * @return Flora_Model_Shop_Currency
     */
    public function getCurrencyById($id, $order_id = 0)
    {
        return $this->call(self::API_CURRENCY_BYID, array('id' => $id, 'order_id' => $order_id));
    }

    /**
     * @return Flora_Collection|Flora_Model_Shop_Order_Reason[]
     */
    public function getOrderReasons()
    {
        return $this->call(self::API_ORDER_REASONS_LIST);
    }

    /**
     * @param $id
     * @return Flora_Model_Shop_Order_Reason
     */
    public function getOrderReasonById($id)
    {
        return $this->call(self::API_ORDER_REASON_BYID, array("id" => $id));
    }

    /**
     * @param int $parent_id
     * @return Flora_Collection|Flora_Model_Shop_Order_Reasons_Text[]
     */
    public function getOrderReasonsTexts($parent_id = 0)
    {
        return $this->call(self::API_ORDER_REASON_TEXTS_LIST, array("parent_id" => $parent_id));
    }

    /**
     * @param $id
     * @return Flora_Model_Shop_Order_Reasons_Text
     */
    public function getOrderReasonsTextById($id)
    {
        return $this->call(self::API_ORDER_REASON_TEXT_BYID, array("id" => $id));
    }

    /**
     * @return Flora_Model_Shop_PaySystem[]|Flora_Collection
     */
    public function getPaymentSystemsList()
    {
        return $this->call(self::API_PAYMENTSYSTEMS_LIST);
    }

    /**
     * @param $id int|string
     * @return Flora_Model_Shop_PaySystem
     */
    public function getPaymentSystemById($id)
    {
        return $this->call(self::API_PAYMENTSYSTEM_BYID, array("id" => $id));
    }

    /**
     * @param Flora_Validation_Order $order
     * @return Flora_Api_Result_Order_Submit
     */
    public function submitOrder(Flora_Validation_Order $order)
    {
        return $this->call(self::API_ORDER_SUBMIT, false, $order);
    }

    /**
     * @param Flora_Validation_Order_Phone $order
     * @return Flora_Api_Result_Order_Submit
     */
    public function submitOrderPhone(Flora_Validation_Order_Phone $order)
    {
        return $this->call(self::API_ORDER_SUBMIT_PHONE, false, $order);
    }

    /**
     * @param $name
     * @param $phone
     * @param $about
     * @param string $email
     * @param string $type
     * @return int
     */
    public function submitOrderRequest($name, $phone, $about, $email = '', $type = '')
    {
        return $this->call(self::API_ORDER_SUBMIT_REQUEST, false, array(
            'name' => $name,
            'phone' => $phone,
            'email' => $email,
            'type' => $type,
            'about' => $about,
        ));
    }

    /**
     * @param $code
     * @return Flora_Model_Shop_Promo_Code
     */
    public function checkPromoCode($code)
    {
        return $this->call(self::API_PROMO_CHECK, array("code" => $code));
    }

    /**
     * @param Flora_Validation_Order $order
     * @return Flora_Model_Shop_Order
     */
    public function calculateOrder(Flora_Validation_Order $order)
    {
        return $this->call(self::API_ORDER_CALCULATE, false, $order);
    }

    /**
     * @param $id
     * @return Flora_Model_Shop_Order
     */
    public function getOrderById($id)
    {
        return $this->call(self::API_ORDER_BYID, array("id" => $id));
    }

    /**
     * @param bool $is_draft
     * @return Flora_Collection|Flora_Model_Shop_Order[]
     */
    public function getUserOrders($is_draft = false)
    {
        return $this->call(self::API_ORDER_USER_LIST, array('is_draft' => (int)(bool)$is_draft));
    }

    /**
     * @param $orderID
     * @return stdClass
     */
    public function getOrderStatus($orderID)
    {
        return $this->call(self::API_ORDER_STATUS, array("id" => (int)$orderID));
    }

    /**
     * @param $orderID
     * @param $key string
     * @return array|stdClass[]
     */
    public function getOrderTickets($orderID, $key)
    {
        return $this->call(self::API_ORDER_TICKETS, array("id" => (int)$orderID, 'key' => $key));
    }

    /**
     * @param $orderID
     * @param $key string
     * @param $message string
     * @return bool
     */
    public function submitOrderTicket($orderID, $key, $message)
    {
        return $this->call(self::API_ORDER_TICKET_SUBMIT, array("id" => (int)$orderID, 'key' => $key, 'message' => $message));
    }

    /**
     * @return Flora_Collection|stdClass[]
     */
    public function getGallery()
    {
        return $this->call(self::API_GALLERY);
    }

    /**
     * @param $fio
     * @param $email
     * @param $orderid
     * @param $comment
     * @param string $phone
     * @param string $comment_operator
     * @param string $comment_florist
     * @param string $comment_manager
     * @param string $comment_courier
     * @param string $comment_flowers_quality
     * @param string $comment_flowers_rating
     * @return int
     */
    public function submitReview(
        $fio, $email, $orderid, $comment, $phone = '', $comment_operator = '', $comment_florist = '',
        $comment_manager = '', $comment_courier = '', $comment_flowers_quality = '',
        $comment_flowers_rating = ''
    )
    {
        return $this->call(self::API_REVIEWS_SUBMIT, array(), array(
            'fio' => $fio,
            'email' => $email,
            'orderid' => $orderid,
            'comment' => $comment,
            'phone' => $phone,
            'comment_operator' => $comment_operator,
            'comment_florist' => $comment_florist,
            'comment_manager' => $comment_manager,
            'comment_courier' => $comment_courier,
            'comment_flowers_quality' => $comment_flowers_quality,
            'comment_flowers_rating' => $comment_flowers_rating
        ));
    }

    /**
     * @param int $limit
     * @param int $offset
     * @return Flora_Collection|stdClass[]
     */
    public function getReviews($limit = 0, $offset = 0)
    {
        return $this->call(self::API_REVIEWS, array("limit" => (int)$limit, "offset" => (int)$offset));
    }

    /**
     * @param $id
     * @return stdClass
     */
    public function getReview($id)
    {
        return $this->call(self::API_REVIEW, array("id" => (int)$id));
    }

    /**
     * @return array|stdClass[]
     */
    public function getLastDelivered()
    {
        return $this->call(self::API_ORDER_LAST_DELIVERED);
    }

    /**
     * @return Flora_Model_Geo_Country[]|Flora_Collection
     */
    public function getCashSalonsCountries()
    {
        return $this->call(self::API_SALONS_COUNTRIES);
    }

    /**
     * @param $country_id
     * @return Flora_Model_Geo_City[]|Flora_Collection
     */
    public function getCashSalonsCities($country_id)
    {
        return $this->call(self::API_SALONS_CITIES, array("country_id" => $country_id));
    }

    /**
     * @param $city_id
     * @return Flora_Model_Shop_Salon[]|Flora_Collection
     */
    public function getCashSalonsByCity($city_id)
    {
        return $this->call(self::API_SALONS, array('city_id' => (int)$city_id));
    }
}