/** * Lists all child/sister products of the given product * * @param int $product_id * @return string HTML code with Items, attributes & price */ function list_attribute_list($product_id, $display_use_parent, $child_link, $display_type, $cls_sfuffix, $child_ids, $dw, $aw, $display_header, $product_list_type, $product_list) { global $CURRENCY_DISPLAY, $mm_action_url; require_once CLASSPATH . 'ps_product.php'; $ps_product = new ps_product(); require_once CLASSPATH . 'ps_product_type.php'; $ps_product_type = new ps_product_type(); $Itemid = vmGet($_REQUEST, 'Itemid', ""); $category_id = vmGet($_REQUEST, 'category_id', ""); $curr_product = vmGet($_REQUEST, 'product_id', ""); $db = new ps_DB(); $db_sku = new ps_DB(); $db_item = new ps_DB(); $tpl = vmTemplate::getInstance(); $price = $ps_product->get_adjusted_attribute_price($product_id); $tpl->set("cls_suffix", $cls_sfuffix); $tpl->set("product_id", $product_id); $tpl->set("display_header", $display_header); $tpl->set("display_product_type", $product_list_type); $tpl->set("product_price", $price['product_price']); $html = ''; // Get list of children $pp = $ps_product->parent_has_children($product_id); if ($pp) { $q = "SELECT product_id,product_name,product_parent_id,product_sku,product_in_stock,product_full_image,product_thumb_image FROM #__{vm}_product WHERE product_publish='Y' AND product_parent_id='{$product_id}' "; } else { $q = "SELECT product_id,product_name,product_parent_id,product_sku,product_in_stock,product_full_image,product_thumb_image FROM #__{vm}_product WHERE product_publish='Y' AND product_id='{$product_id}' "; } if ($child_ids) { $ids = explode(",", $child_ids); $child_array = array(); $parent_array = array(); foreach ($ids as $extra_id) { if ($ps_product->parent_has_children($extra_id)) { $parent_array[] = $extra_id; } else { $child_array[] = $extra_id; } } $parent_ids = implode(',', $parent_array); $child_ids = implode(',', $child_array); if ($child_ids) { $q .= "UNION ALL SELECT product_id,product_name,product_parent_id,product_sku,product_in_stock,product_full_image,product_thumb_image FROM #__{vm}_product WHERE product_publish='Y' AND product_id IN ({$child_ids}) "; } if ($parent_ids) { $q .= "UNION ALL SELECT product_id,product_name,product_parent_id,product_sku,product_in_stock,product_full_image,product_thumb_image FROM #__{vm}_product WHERE product_publish='Y' AND product_parent_id IN ({$parent_ids})"; } } $db->query($q); if ($pp) { $master_id = $product_id; } else { $master_id = $db->f("product_id"); } $main_master = $master_id; $master_child_count = 0; if ($db->num_rows() < 1) { // Try to Get list of sisters & brothers $q = "SELECT product_parent_id FROM #__{vm}_product WHERE product_id='{$product_id}'"; $db->setQuery($q); $db->query(); $child_id = $product_id; $product_id = $db->f("product_parent_id") ? $db->f("product_parent_id") : $product_id; $parent_id = $db->f("product_parent_id"); $q = "SELECT product_id,product_name,product_parent_id,product_sku,product_in_stock FROM #__{vm}_product WHERE product_parent_id='" . $db->f("product_parent_id") . "' AND product_parent_id<>0 AND product_publish='Y'"; $db->query($q); } if ($db->num_rows() > 0) { $products = array(); $headings = array(); $i = 0; $attrib_heading = array(); $ci = 0; while ($db->next_record()) { $parent_id = $db->f("product_parent_id"); if ($db->f("product_id") != $curr_product && @$child_id) { continue; } // Start row for this child $q = "SELECT product_id, attribute_name FROM #__{vm}_product_attribute_sku "; $q .= "WHERE product_id='" . $db->f("product_parent_id") . "' ORDER BY attribute_list ASC"; $db_sku->query($q); $attrib_value = array(); while ($db_sku->next_record()) { $q = "SELECT attribute_name,attribute_value "; $q .= "FROM #__{vm}_product_attribute WHERE "; $q .= "product_id='" . $db->f("product_id") . "' AND "; $q .= "attribute_name='" . $db_sku->f("attribute_name") . "'"; $db_item->setQuery($q); $db_item->query(); while ($db_item->next_record()) { if ($ci == 0) { $attrib_heading[] = $db_item->f("attribute_name"); $tpl->set('headings', $attrib_heading); } $attrib_value[] = $db_item->f("attribute_value"); } } if ($main_master == $parent_id) { $master_child_count++; } $tpl->set('desc_width', $dw); $tpl->set('attrib_width', $aw); // End show Header Row if ($ci % 2) { $bgcolor = "vmRowOne"; } else { $bgcolor = "vmRowTwo"; } $products[$ci]['bgcolor'] = $bgcolor; $products[$ci]['product_id'] = $db->f("product_id"); $products[$ci]["category_id"] = $category_id; $products[$ci]["Itemid"] = $Itemid; // If this is a child of a parent set the correct product_id for page return if (@$child_id && $pp) { $products[$ci]['parent_id'] = $db->f("product_id"); } else { $master_id = $parent_id; $products[$ci]['parent_id'] = $parent_id; } $flypage = $ps_product->get_flypage($products[$ci]['parent_id']); $products[$ci]["flypage"] = $flypage; // Images // If it is item get parent: $product_parent_id = $db->f("product_parent_id"); if ($product_parent_id != 0) { $dbp = new PS_db(); $dbp->query("SELECT product_full_image,product_thumb_image,product_name,product_s_desc FROM #__{vm}_product WHERE product_id='{$product_parent_id}'"); $dbp->next_record(); } $product_full_image = $parent_id != 0 && !$db->f("product_full_image") ? $dbp->f("product_full_image") : $db->f("product_full_image"); // Change $product_thumb_image = $parent_id != 0 && !$db->f("product_thumb_image") ? $dbp->f("product_thumb_image") : $db->f("product_thumb_image"); // Change $productData = $db->get_row(); $productArray = get_object_vars($productData); $productArray["product_id"] = $db->f("product_id"); $productArray["product_full_image"] = $product_full_image; // to display the full image on flypage $productArray["product_thumb_image"] = $product_thumb_image; $tpl->set('productArray', $productArray); foreach ($productArray as $property => $value) { $tpl->set($property, $value); } // Assemble the thumbnail image as a link to the full image // This function is defined in the theme (theme.php) $product_image = $tpl->vmBuildFullImageLink($productArray); $products[$ci]['product_image'] = $product_image; //Product Description $link = ""; if ($child_link == "Y" && !@$child_id) { $link = "<input type=\"hidden\" id=\"index_id" . $db->f("product_id") . "\" value=\"" . $db->f("product_id") . "\" />\n"; // If content plugins are enabled, reload the whole page; otherwise, use ajax if (VM_CONTENT_PLUGINS_ENABLE == '1') { $link .= "<a name=\"" . $db->f("product_name") . $db->f("product_id") . "\" onclick=\"var id = \$('index_id" . $db->f("product_id") . "').value; if(id != '') { document.location = '" . $mm_action_url . "index.php?option=com_virtuemart&page=shop.product_details&flypage={$flypage}&Itemid={$Itemid}&category_id={$category_id}&product_id=' + id; }\" >"; } else { $link .= "<a name=\"" . $db->f("product_name") . $db->f("product_id") . "\" onclick=\"var id = \$('index_id" . $db->f("product_id") . "').value; if(id != '') { loadNewPage( 'vmMainPage', '" . $mm_action_url . "index2.php?option=com_virtuemart&page=shop.product_details&flypage={$flypage}&Itemid={$Itemid}&category_id={$category_id}&product_id=' + id ); }\" >"; } $tpl->set('child_link', true); } else { $tpl->set('child_link', false); } $html1 = $db->f("product_name"); if ($child_link == "Y" && !@$child_id) { $html1 .= "</a>"; } $products[$ci]['product_title'] = $link . $html1; // For each child get attribute values by looping through attribute list foreach ($attrib_value as $attribute) { $products[$ci]['attrib_value'][] = $attribute; } //Show the quantity Box $products[$ci]['quantity_box'] = $this->show_quantity_box($master_id, $db->f("product_id"), $product_list, $display_use_parent); // Attributes for this item are done. // Now get item price $price = $ps_product->get_price($db->f("product_id")); $price["product_price"] = $GLOBALS['CURRENCY']->convert($price["product_price"], $price["product_currency"]); $actual_price = $ps_product->get_adjusted_attribute_price($db->f("product_id")); $actual_price["product_price"] = $GLOBALS['CURRENCY']->convert($actual_price["product_price"], $actual_price["product_currency"]); if ($_SESSION["auth"]["show_price_including_tax"] == 1) { $tax_rate = 1 + $ps_product->get_product_taxrate($db->f("product_id")); $price['product_price'] *= $tax_rate; $actual_price['product_price'] *= $tax_rate; } $products[$ci]['price'] = $CURRENCY_DISPLAY->getFullValue($price["product_price"]); $products[$ci]['actual_price'] = $CURRENCY_DISPLAY->getFullValue($actual_price["product_price"]); // Ouput Product Type if ($db->f("product_parent_id") != $product_id) { $product_id = $db->f("product_parent_id"); } $product_type = ""; if ($product_id != 0 && !$ps_product_type->product_in_product_type($db->f("product_id"))) { $product_type = $ps_product_type->list_product_type($product_id); } else { $product_type = $ps_product_type->list_product_type($db->f("product_id")); } $products[$ci]['product_type'] = $product_type; // Child stock if ($display_use_parent == 'Y' && !empty($master_id)) { $id = $master_id; } else { $id = $db->f("product_id"); } $products[$ci]['product_in_stock'] = ps_product::get_field($id, 'product_in_stock'); // Output Advanced Attributes $products[$ci]['advanced_attribute'] = $this->list_advanced_attribute($db->f("product_id")); $products[$ci]['custom_attribute'] = $this->list_custom_attribute($db->f("product_id")); $ci++; } if ($display_type == "radio") { $list_type = "radio"; } else { $list_type = "list"; } // Get template and fill $tpl->set('products', $products); $master_child_count = $master_child_count == 0 ? 1 : $master_child_count; $tpl->set('child_count', $master_child_count); if ($product_list == "Y") { $html = $tpl->fetch('product_details/includes/addtocart_list_single.tpl.php'); } else { $list_type = "multi"; $html = $tpl->fetch('product_details/includes/addtocart_list_multi.tpl.php'); } } else { $html = "<input type=\"hidden\" name=\"product_id\" value=\"{$product_id}\" />\n"; $html .= "<input type=\"hidden\" name=\"prod_id[]\" value=\"{$product_id}\" />\n"; // This function lists the "advanced" simple attributes $html .= $this->list_advanced_attribute($product_id); // This function lists the "custom" simple attributes $html .= $this->list_custom_attribute($product_id); $html .= '<br />'; $list_type = "drop"; } return array($html, $list_type); }
$bgcolor = 'row1'; } $t = $dbt->f("product_quantity") * $dbt->f("product_final_price"); // Check if it's a downloadable product $downloadable = false; $files = array(); $dbd->query('SELECT product_id, attribute_name FROM `#__{vm}_product_attribute` WHERE product_id=' . $dbt->f('product_id') . ' AND attribute_name=\'download\''); if ($dbd->next_record()) { $downloadable = true; $dbd->query('SELECT product_id, end_date, download_max, download_id, file_name FROM `#__{vm}_product_download` WHERE product_id=' . $dbt->f('product_id') . ' AND order_id=\'' . $order_id . '\''); while ($dbd->next_record()) { $files[] = $dbd->get_row(); } } ?> <tr class="<?php echo $bgcolor; ?> " valign="top"> <?php $ps_order_change_html->html_change_delete_item($dbt->f("order_item_id")); ?> <?php $ps_order_change_html->html_change_item_quantity($dbt->f("order_item_id"), $dbt->f("product_quantity")); ?> <td width="30%" align="left"> <?php
/** * Returns an array holding all the files and images of the specified product * $files['files'] holds all files as objects * $files['images'] holds all images as objects * * @param unknown_type $pid * @return unknown */ function getFilesForProduct($pid) { $db = new ps_DB(); $files['images'] = array(); $files['files'] = array(); $db->query("SELECT * FROM `#__{vm}_product_files` WHERE `file_product_id`=" . intval($pid) . " AND `file_published`=1"); while ($db->next_record()) { switch ($db->f('file_is_image')) { case 0: $files['files'][] = $db->get_row(); break; case 1: $files['images'][] = $db->get_row(); break; } } return $files; }
} $recent_products = $ps_product->recentProducts($product_id, $tpl->get_cfg('showRecent', 5)); /** * This has changed since VM 1.1.0 * Now we have a template object that can use all variables * that we assign here. * * Example: If you run * $tpl->set( "product_name", $product_name ); * The variable "product_name" will be available in the template under this name * with the value of $product_name * * */ // This part allows us to copy ALL properties from the product table // into the template $productData = $db_product->get_row(); $productArray = get_object_vars($productData); $productArray["product_id"] = $product_id; $productArray["product_full_image"] = $product_full_image; // to display the full image on flypage $productArray["product_thumb_image"] = $product_thumb_image; $productArray["product_name"] = shopMakeHtmlSafe($productArray["product_name"]); $tpl->set('productArray', $productArray); foreach ($productArray as $property => $value) { $tpl->set($property, $value); } // Assemble the thumbnail image as a link to the full image // This function is defined in the theme (theme.php) $product_image = $tpl->vmBuildFullImageLink($productArray); $tpl->set("product_id", $product_id); $tpl->set("product_name", $product_name);
/** * Returns an array holding all the files and images of the specified product * $files['files'] holds all files as objects * $files['images'] holds all images as objects * $files['product_id] holds the product_id of the child or parent that holds files as objects * Query has to be done twice, because parent could old either/or files/images. Must allow inheritance of both * @param unknown_type $pid * @return unknown */ function getFilesForProduct($pid) { $db = new ps_DB(); $files['images'] = array(); $files['files'] = array(); // Query for images if child doesn't have them check for parents $db->query("SELECT * FROM `#__{vm}_product_files` WHERE `file_product_id`=" . intval($pid) . " AND `file_is_image`=1 AND `file_published`=1"); if (!$db->next_record()) { $db->query("SELECT product_parent_id FROM #__{vm}_product WHERE product_id=" . intval($pid)); $db->query("SELECT * FROM `#__{vm}_product_files` WHERE `file_product_id`=" . $db->f("product_parent_id") . " AND `file_is_image`=1 AND `file_published`=1"); } $db->reset(); while ($db->next_record()) { $files['images'][] = $db->get_row(); } // Query for files if child doesn't have them check for parent $files['product_id'] = intval($pid); $db->query("SELECT * FROM `#__{vm}_product_files` WHERE `file_product_id`=" . intval($pid) . " AND `file_is_image`=0 AND `file_published`=1"); if (!$db->next_record()) { $db->query("SELECT product_parent_id FROM #__{vm}_product WHERE product_id='{$pid}'"); // Parent has files so set files['product_id'] to parent id $files['product_id'] = intval($db->f("product_parent_id")); $db->query("SELECT * FROM `#__{vm}_product_files` WHERE `file_product_id`=" . $db->f("product_parent_id") . " AND `file_is_image`=0 AND `file_published`=1"); } $db->reset(); while ($db->next_record()) { $files['files'][] = $db->get_row(); } return $files; }