/** * This function will return for any product type the associated reservations ids * * @param $productIds * @param null $attributes * @param null $options * @param bool $useRequired * * @return array */ public static function getReservationProductsArrayIds($productIds, $attributes = null, $options = null, $useRequired = false) { if (!is_array($productIds)) { $productIds = array($productIds); } $newProductIds = array(); foreach ($productIds as $iProduct) { $typeId = ITwebexperts_Payperrentals_Helper_Data::getAttributeCodeForId($iProduct, 'type_id'); if ($typeId == ITwebexperts_Payperrentals_Helper_Data::PRODUCT_TYPE_CONFIGURABLE && !is_null($attributes)) { $childProduct = Mage::getModel('catalog/product_type_configurable')->getProductByAttributes($attributes, ITwebexperts_Payperrentals_Helper_Data::initProduct($iProduct)); if (is_object($childProduct) && $childProduct->getTypeId() != 'simple') { $newProductIds[] = $childProduct->getId(); } } elseif ($typeId == ITwebexperts_Payperrentals_Helper_Data::PRODUCT_TYPE_GROUPED) { $assocArr = ITwebexperts_Payperrentals_Helper_Data::getAssociatedProductIds($iProduct); foreach ($assocArr as $iAssoc) { $iTypeId = ITwebexperts_Payperrentals_Helper_Data::getAttributeCodeForId($iAssoc, 'type_id'); if ($iTypeId == ITwebexperts_Payperrentals_Helper_Data::PRODUCT_TYPE) { $newProductIds[] = $iAssoc; break; //we only allow grouped products with 1 reservation type product } } } elseif ($typeId != ITwebexperts_Payperrentals_Helper_Data::PRODUCT_TYPE_BUNDLE) { $newProductIds[] = $iProduct; } elseif (!is_null($options)) { $product = ITwebexperts_Payperrentals_Helper_Data::initProduct($iProduct); $selections = $product->getTypeInstance(true)->getSelectionsByIds($options, $product); foreach ($selections->getItems() as $selection) { $newProductIds[] = $selection->getProductId(); } } elseif ($useRequired) { $product = ITwebexperts_Payperrentals_Helper_Data::initProduct($iProduct); if ($typeId == ITwebexperts_Payperrentals_Helper_Data::PRODUCT_TYPE_CONFIGURABLE && is_null($attributes)) { $conf = Mage::getModel('catalog/product_type_configurable')->setProduct($product); $simpleCollection = $conf->getUsedProductCollection()->addAttributeToSelect('*')->addFilterByRequiredOptions(); foreach ($simpleCollection as $simpleProduct) { $iTypeId = ITwebexperts_Payperrentals_Helper_Data::getAttributeCodeForId($simpleProduct->getId(), 'type_id'); if ($iTypeId == ITwebexperts_Payperrentals_Helper_Data::PRODUCT_TYPE) { $newProductIds[] = $simpleProduct->getId(); } } } else { $optionCol = $product->getTypeInstance(true)->getOptionsCollection($product); $selectionCol = $product->getTypeInstance(true)->getSelectionsCollection($product->getTypeInstance(true)->getOptionsIds($product), $product); $optionCol->appendSelections($selectionCol); foreach ($optionCol as $option) { if ($option->required) { $selectionsOpt = $option->getSelections(); foreach ($selectionsOpt as $selectionOpt) { $newProductIds[] = $selectionOpt->getProductId(); } } } } } } return $newProductIds; }