/** * Return all available variant IDs of this product * * @return int[]|false */ public function getVariantIds() { if (null === $this->arrVariantIds) { $this->arrVariantIds = array(); // Nothing to do if we have no variants if (!$this->hasVariants()) { return $this->arrVariantIds; } $time = time(); $blnHasProtected = false; $blnHasGroups = false; $strQuery = "SELECT id, protected, groups FROM tl_iso_product WHERE pid=" . $this->getProductId() . " AND language='' AND published='1' AND (start='' OR start<{$time}) AND (stop='' OR stop>{$time})"; if (BE_USER_LOGGED_IN !== true) { $arrAttributes = $this->getVariantAttributes(); $blnHasProtected = in_array('protected', $arrAttributes); $blnHasGroups = in_array('groups', $arrAttributes); // Hide guests-only products when logged in if (FE_USER_LOGGED_IN === true && in_array('guests', $arrAttributes)) { $strQuery .= " AND (guests=''" . ($blnHasProtected ? " OR protected='1'" : '') . ")"; } elseif (FE_USER_LOGGED_IN !== true && $blnHasProtected) { $strQuery .= " AND protected=''"; } } /** @type object $objVariants */ $objVariants = \Database::getInstance()->query($strQuery); while ($objVariants->next()) { if ($blnHasProtected && $objVariants->protected) { $groups = $blnHasGroups ? deserialize($objVariants->groups) : ''; if (empty($groups) || !is_array($groups) || !count(array_intersect($groups, \FrontendUser::getInstance()->groups))) { continue; } } $this->arrVariantIds[] = $objVariants->id; } // Only show variants where a price is available if (!empty($this->arrVariantIds) && $this->hasVariantPrices()) { if ($this->hasAdvancedPrices()) { $objPrices = ProductPrice::findAdvancedByProductIdsAndCollection($this->arrVariantIds, Isotope::getCart()); } else { $objPrices = ProductPrice::findPrimaryByProductIds($this->arrVariantIds); } if (null === $objPrices) { $this->arrVariantIds = array(); } else { $this->arrVariantIds = $objPrices->fetchEach('pid'); } } } return $this->arrVariantIds; }