function getCustomEmbeddedProductCustomFields($productIds, $tsmart_custom_id = 0, $cartattribute = -1, $forcefront = FALSE) { $app = JFactory::getApplication(); $db = JFactory::getDBO(); $q = tsmartModelCustomfields::getProductCustomSelectFieldList(); static $_customFieldByProductId = array(); $hashCwAttribute = $cartattribute; if ($hashCwAttribute == -1) { $hashCwAttribute = 2; } $productCustomsCached = array(); foreach ($productIds as $k => $productId) { $hkey = (int) $productId . $hashCwAttribute; if (array_key_exists($hkey, $_customFieldByProductId)) { //$productCustomsCached = $_customFieldByProductId[$hkey]; $productCustomsCached = array_merge($productCustomsCached, $_customFieldByProductId[$hkey]); unset($productIds[$k]); } } if (is_array($productIds) and count($productIds) > 0) { $q .= 'WHERE `tsmart_product_id` IN (' . implode(',', $productIds) . ')'; } else { if (!empty($productIds)) { $q .= 'WHERE `tsmart_product_id` = "' . $productIds . '" '; } else { return $productCustomsCached; } } if (!empty($tsmart_custom_id)) { if (is_numeric($tsmart_custom_id)) { $q .= ' AND c.`tsmart_custom_id`= "' . (int) $tsmart_custom_id . '" '; } else { $tsmart_custom_id = substr($tsmart_custom_id, 0, 1); //just in case $q .= ' AND c.`field_type`= "' . $tsmart_custom_id . '" '; } } if (!empty($cartattribute) and $cartattribute != -1) { $q .= ' AND ( `is_cart_attribute` = 1 OR `is_input` = 1) '; } if ($forcefront or $app->isSite()) { $q .= ' AND c.`published` = "1" '; $forcefront = true; } if (!empty($tsmart_custom_id) and $tsmart_custom_id !== 0) { $q .= ' ORDER BY field.`ordering` ASC'; } else { if ($forcefront or $app->isSite()) { //$q .= ' GROUP BY c.`tsmart_custom_id`'; } $q .= ' ORDER BY field.`ordering`,`tsmart_custom_id` ASC'; } $db->setQuery($q); $productCustoms = $db->loadObjectList(); $err = $db->getErrorMsg(); if ($err) { vmError('getCustomEmbeddedProductCustomFields error in query ' . $err); } foreach ($productCustoms as $customfield) { $hkey = (int) $customfield->tsmart_product_id . $hashCwAttribute; $_customFieldByProductId[$hkey][] = $customfield; } $productCustoms = array_merge($productCustomsCached, $productCustoms); if ($productCustoms) { $customfield_ids = array(); $customfield_override_ids = array(); foreach ($productCustoms as $field) { if ($field->override != 0) { $customfield_override_ids[] = $field->override; } else { if ($field->disabler != 0) { $customfield_override_ids[] = $field->disabler; } } $customfield_ids[] = $field->tsmart_customfield_id; } $tsmart_customfield_ids = array_unique(array_diff($customfield_ids, $customfield_override_ids)); foreach ($productCustoms as $k => $field) { if (in_array($field->tsmart_customfield_id, $tsmart_customfield_ids)) { if ($forcefront and $field->disabler) { unset($productCustoms[$k]); } else { tsmartModelCustomfields::bindCustomEmbeddedFieldParams($field, $field->field_type); } } else { unset($productCustoms[$k]); } } return $productCustoms; } else { return array(); } }