private function delete($hash, $count, $del_list = false) { $collection = new shopProductsCollection(implode('/', $hash)); // check rights to prevent infinite ajax-polling $types = $this->getModel('type')->getTypes(false); if (is_array($types)) { if (empty($types)) { $this->response['rest_count'] = 0; $this->response['count'] = $count; return true; } else { $collection->addWhere('p.type_id IN (' . implode(',', array_keys($types)) . ')'); } } if ($count) { $product_ids = array_keys($collection->getProducts('*', 0, $count, false)); $this->deleteProducts($product_ids); // DECREASE count. // Ignoring this case for dynamic set lead to tricky BUG, result of which in worst case is deleting ALL products $info = $collection->getInfo(); if ($hash[0] == 'set' || $hash[0] == 'category' || $hash[0] == 'type') { $model = $this->getModel($hash[0]); $model->updateById($hash[1], array('count' => max($info['count'] - $count, 0))); } } $rest_count = $collection->count(); $this->response['rest_count'] = $rest_count; $this->response['count'] = $count; if ($rest_count == 0) { $this->response['lists'] = $this->getLists(); if ($del_list) { return $this->deleteList($hash); } } return true; }
/** * Returns products identified as cross-selling items for current product. * * @param int $limit Maximum number of items to be returned * @param bool $available_only Whether only products with positive or unlimited stock count must be returned * * @return array Array of cross-selling products' data sub-arrays */ public function crossSelling($limit = 5, $available_only = false) { $cross_selling = $this->getData('cross_selling'); // upselling on (usign similar settting for type) if ($cross_selling == 1 || $cross_selling === null) { $type = $this->getType(); if ($type['cross_selling']) { $collection = new shopProductsCollection($type['cross_selling'] . ($type['cross_selling'] == 'alsobought' ? '/' . $this->getId() : '')); if ($available_only) { $collection->addWhere('(p.count > 0 OR p.count IS NULL)'); } if ($type['cross_selling'] != 'alsobought') { $collection->orderBy('RAND()'); } $result = $collection->getProducts('*', $limit); if (isset($result[$this->getId()])) { unset($result[$this->getId()]); } return $result; } else { return array(); } } elseif (!$cross_selling) { return array(); } else { $collection = new shopProductsCollection('related/cross_selling/' . $this->getId()); if ($available_only) { $collection->addWhere('(p.count > 0 OR p.count IS NULL)'); } return $collection->getProducts('*', $limit); } }