/** * 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); } }