Code Duplication    Length = 84-84 lines in 2 locations

src/Intraface/XMLRPC/Shop/Server0004.php 1 location

@@ 43-126 (lines=84) @@
40
     *
41
     * @return array
42
     */
43
    public function getProducts($credentials, $shop_id, $search = array())
44
    {
45
        $this->checkCredentials($credentials);
46
47
        $offset = 0;
48
49
        $search = $this->processRequestData($search);
50
51
        $mixed = array();
52
        if (!empty($search)) {
53
            $mixed = $search;
54
        }
55
56
        $search = '';
57
58
        $this->_factoryWebshop($shop_id);
59
60
        $products = array();
61
62
        $area = '';
63
64
        if (!empty($mixed['area'])) {
65
            $area = $mixed['area'];
66
        }
67
68
        $product = new Intraface_modules_product_Gateway($this->webshop->kernel);
69
70
        if (!isset($mixed['use_paging']) || $mixed['use_paging'] == 'true') {
71
            $product->getDBQuery()->usePaging('paging');
72
        }
73
74
        // sublevel has to be used so other searches are not overwritten
75
        $product->getDBQuery()->storeResult('use_stored', 'webshop_' . $area . '_' .  md5($this->credentials['session_id']), 'sublevel');
76
        $debug2 = serialize($mixed);
77
        if (isset($mixed['offset']) and is_numeric($mixed['offset']) and $mixed['offset'] > 0) {
78
            $product->getDBQuery()->useStored(true);
79
            $product->getDBQuery()->setPagingOffset((int)$mixed['offset']);
80
            $debug2 .= 'offset ' . $mixed['offset'];
81
        } elseif (isset($mixed['use_stored']) and array_key_exists('use_stored', $mixed) and $mixed['use_stored'] == 'true') {
82
            $product->getDBQuery()->useStored(true);
83
            $debug2 .= 'use_stored true';
84
        } else {
85
            if (array_key_exists('search', $mixed) and !empty($mixed['search'])) {
86
                $product->getDBQuery()->setFilter('search', $mixed['search']);
87
                $debug2 .= 'search ' . $mixed['search'];
88
            }
89
90
            if (array_key_exists('keywords', $mixed) and !empty($mixed['keywords'])) {
91
                $product->getDBQuery()->setFilter('keywords', $mixed['keywords']);
92
                $debug2 .= 'keyword ' . $mixed['keywords'];
93
            }
94
95
            if (array_key_exists('category', $mixed) and !empty($mixed['category'])) {
96
                $product->getDBQuery()->setFilter('shop_id', $shop_id);
97
                $product->getDBQuery()->setFilter('category', $mixed['category']);
98
                $debug2 .= 'category ' . $mixed['category'];
99
            }
100
101
            if (isset($mixed['ids']) and array_key_exists('ids', $mixed) and is_array($mixed['ids'])) {
102
                $product->getDBQuery()->setFilter('ids', $mixed['ids']);
103
                $debug2 .= 'ids ' . implode(', ', $mixed['ids']);
104
            }
105
106
            if (array_key_exists('sorting', $mixed) and !empty($mixed['sorting'])) {
107
                $product->getDBQuery()->setFilter('sorting', $mixed['sorting']);
108
                $debug2 .= 'sorting ' . $mixed['sorting'];
109
            }
110
        }
111
112
        if (false !== ($currency_gateway = $this->getCurrencyGateway())) {
113
            $currencies = $currency_gateway->findAllWithExchangeRate();
114
        } else {
115
            $currencies = false;
116
        }
117
118
        return $this->prepareResponseData(array(
119
            'parameter' => $mixed,
120
            //'debug2' => $debug2,
121
            'products' => $this->cleanUpProductList($product->getAllProducts('webshop', $currencies)),
122
            'paging' => $product->getDBQuery()->getPaging(),
123
            'search' => array(),
124
        ));
125
    }
126
127
    /**
128
     * Gets a list with products in given category
129
     *

src/Intraface/XMLRPC/Shop/Server0100.php 1 location

@@ 45-128 (lines=84) @@
42
     *
43
     * @return array
44
     */
45
    public function getProducts($credentials, $shop_id, $search = array())
46
    {
47
        $this->checkCredentials($credentials);
48
49
        $offset = 0;
50
51
        $search = $this->processRequestData($search);
52
53
        $mixed = array();
54
        if (!empty($search)) {
55
            $mixed = $search;
56
        }
57
58
        $search = '';
59
60
        $this->_factoryWebshop($shop_id);
61
62
        $products = array();
63
64
        $area = '';
65
66
        if (!empty($mixed['area'])) {
67
            $area = $mixed['area'];
68
        }
69
70
        $product = new Intraface_modules_product_Gateway($this->webshop->kernel);
71
72
        if (!isset($mixed['use_paging']) || $mixed['use_paging'] == 'true') {
73
            $product->getDBQuery()->usePaging('paging');
74
        }
75
76
        // sublevel has to be used so other searches are not overwritten
77
        $product->getDBQuery()->storeResult('use_stored', 'webshop_' . $area . '_' .  md5($this->credentials['session_id']), 'sublevel');
78
        $debug2 = serialize($mixed);
79
        if (isset($mixed['offset']) and is_numeric($mixed['offset']) and $mixed['offset'] > 0) {
80
            $product->getDBQuery()->useStored(true);
81
            $product->getDBQuery()->setPagingOffset((int)$mixed['offset']);
82
            $debug2 .= 'offset ' . $mixed['offset'];
83
        } elseif (isset($mixed['use_stored']) and array_key_exists('use_stored', $mixed) and $mixed['use_stored'] == 'true') {
84
            $product->getDBQuery()->useStored(true);
85
            $debug2 .= 'use_stored true';
86
        } else {
87
            if (array_key_exists('search', $mixed) and !empty($mixed['search'])) {
88
                $product->getDBQuery()->setFilter('search', $mixed['search']);
89
                $debug2 .= 'search ' . $mixed['search'];
90
            }
91
92
            if (array_key_exists('keywords', $mixed) and !empty($mixed['keywords'])) {
93
                $product->getDBQuery()->setFilter('keywords', $mixed['keywords']);
94
                $debug2 .= 'keyword ' . $mixed['keywords'];
95
            }
96
97
            if (array_key_exists('category', $mixed) and !empty($mixed['category'])) {
98
                $product->getDBQuery()->setFilter('shop_id', $shop_id);
99
                $product->getDBQuery()->setFilter('category', $mixed['category']);
100
                $debug2 .= 'category ' . $mixed['category'];
101
            }
102
103
            if (isset($mixed['ids']) and array_key_exists('ids', $mixed) and is_array($mixed['ids'])) {
104
                $product->getDBQuery()->setFilter('ids', $mixed['ids']);
105
                $debug2 .= 'ids ' . implode(', ', $mixed['ids']);
106
            }
107
108
            if (array_key_exists('sorting', $mixed) and !empty($mixed['sorting'])) {
109
                $product->getDBQuery()->setFilter('sorting', $mixed['sorting']);
110
                $debug2 .= 'sorting ' . $mixed['sorting'];
111
            }
112
        }
113
114
        if (false !== ($currency_gateway = $this->getCurrencyGateway())) {
115
            $currencies = $currency_gateway->findAllWithExchangeRate();
116
        } else {
117
            $currencies = false;
118
        }
119
120
        return $this->prepareResponseData(array(
121
            'parameter' => $mixed,
122
            //'debug2' => $debug2,
123
            'products' => $this->cleanUpProductList($product->getAllProducts('webshop', $currencies)),
124
            'paging' => $product->getDBQuery()->getPaging(),
125
            'search' => array(),
126
        ));
127
    }
128
129
    /**
130
     * Gets a list with products in given category
131
     *