示例#1
0
    public function getProductsGroupByCategories(Shopware_StoreApi_Models_Query_Product $productQuery, Shopware_StoreApi_Models_Query_Category $categoryQuery)
    {
        if(!$productQuery instanceof Shopware_StoreApi_Models_Query_Product) {
            return new Shopware_StoreApi_Exception_Response('The parameter productModel is not instance of Shopware_StoreApi_Models_Query_Product', 10);
        }
        if(!$categoryQuery instanceof Shopware_StoreApi_Models_Query_Category) {
            return new Shopware_StoreApi_Exception_Response('The parameter productModel is not instance of Shopware_StoreApi_Models_Query_Category', 10);
        }

        $productQueryData = array();
        $productQueryData['start']          = $productQuery->getStart();
        $productQueryData['limit']          = $productQuery->getLimit();
        $productQueryData['orderBy']        = $productQuery->getOrderBy();
        $productQueryData['orderDirection'] = $productQuery->getOrderDirection();
        $productQueryData['criterion']      = $productQuery->getCriterion();

        $categoryQueryData = array();
        $categoryQueryData['start']          = $categoryQuery->getStart();
        $categoryQueryData['limit']          = $categoryQuery->getLimit();
        $categoryQueryData['orderBy']        = $categoryQuery->getOrderBy();
        $categoryQueryData['orderDirection'] = $categoryQuery->getOrderDirection();
        $categoryQueryData['criterion']      = $categoryQuery->getCriterion();

        return $this->gateway->getProductsGroupByCategories($productQueryData, $categoryQueryData);
    }
示例#2
0
 public function getCategories(Shopware_StoreApi_Models_Query_Category $categoryQuery)
 {
     if (!$categoryQuery instanceof Shopware_StoreApi_Models_Query_Category) {
         return new Shopware_StoreApi_Exception_Response('The parameter productModel is not instance of Shopware_StoreApi_Models_Query_Category', 10);
     }
     $start = $categoryQuery->getStart();
     $limit = $categoryQuery->getLimit();
     $orderBy = $categoryQuery->getOrderBy();
     $orderDirection = $categoryQuery->getOrderDirection();
     $criterion = $categoryQuery->getCriterion();
     return $this->gateway->getCategories($start, $limit, $orderBy, $orderDirection, $criterion);
 }
示例#3
0
文件: Store.php 项目: nhp/shopware-4
    /**
     * The getCategoriesWithProducts function returns all defined community store categories,
     * with the first six products of the category.
     * The function selects first all categories and calls for each category the internal helper function
     * "getCategoryProducts" which selects all products for a specify store category.
     *
     * @param      $offset
     * @param      $limit
     * @param null $orderBy
     * @param null $filters
     * @param      $shopwareVersion
     * @return array|Shopware_StoreApi_Core_Response_SearchResult
     */
    public function getCategoriesWithProducts($offset = null, $limit = null, $orderBy = null, $filters = null, $shopwareVersion)
    {
        $categoryQuery = new Shopware_StoreApi_Models_Query_Category();
        $categoryQuery->setOrderBy(Shopware_StoreApi_Models_Query_Category::ORDER_BY_DESCRIPTION);
        $categoryQuery->setOrderDirection(Shopware_StoreApi_Models_Query_Category::ORDER_DIRECTION_ASC);
        $productQuery = $this->getProductQueryForListing($offset, $limit, $orderBy, $filters);
        $productQuery->addCriterion(
            new Shopware_StoreApi_Models_Query_Criterion_Version($shopwareVersion)
        );

        $resultSet = $this->getProductService()->getProductsGroupByCategories($productQuery, $categoryQuery);

        if ($resultSet instanceof Shopware_StoreApi_Exception_Response) {
            return $resultSet;
        }
        $iterator = $resultSet->getIterator();
        $categories = array();

        /**@var $model Shopware_StoreApi_Models_Category */
        foreach($iterator as $model) {
            $category = $model->getRawData();
            $productResult = $model->getProducts();
            if ($productResult instanceof Shopware_StoreApi_Exception_Response) {
                $products = array('message' => $productResult->getMessage(), 'code' => $productResult->getCode());
            } else {
                $products = array();
                /**@var $productModel Shopware_StoreApi_Models_Product*/
                foreach($productResult as $productModel) {
                    $product = $productModel->getRawData();
                    $product['details'] = $productModel->getDetails();
                    $products[] = $product;
                }
            }
            unset($category['_products']);
            $category['products'] = $products;
            $categories[] = $category;
        }

        return $categories;
    }