Author Topic: ps_product need help with funtion..  (Read 3091 times)

Kruzayn

  • Beginner
  • *
  • Posts: 19
ps_product need help with funtion..
« on: June 27, 2006, 20:08:00 pm »
OK im in need of getting the manufacturer_id from the funtion product_snapshot, to the function image_tag.

I have $mid in product_snapshot which holds the manufactuer, i wanted to set up multiple constructors for image_tag but that doesnt work in php :/

anyway i can get that $mid in image_tag is what I need.  Thanks for any help.


Code: [Select]
function show_snapshot($product_sku, $show_price=true, $show_addtocart=true ) {

echo $this->product_snapshot($product_sku, $show_price, $show_addtocart);

}
/**
* Returns HTML code for a snapshot of a product based on the product sku.
* This was written to provide a quick way to display a product inside of modules
*
* @param string $product_sku The SKU identifying the product
* @param boolean $show_price Show the product price?
* @param boolean $show_addtocart Show the add-to-cart link?
*/
function product_snapshot( $product_sku, $show_price=true, $show_addtocart=true ) {

global $sess, $VM_LANG, $mm_action_url;

$db = new ps_DB;

require_once(CLASSPATH.'ps_product_category.php');
$ps_product_category = new ps_product_category;

$q = "SELECT product_id, product_name, product_parent_id, product_thumb_image FROM #__{vm}_product WHERE product_sku='$product_sku'";
$db->query( $q );
$html = "";
if ($db->next_record()) {

$cid = $ps_product_category->get_cid( $db->f("product_id" ) );
$mid = $this->get_manufacturer_id( $db->f("product_id" ) );

$html .= "<span style=\"font-weight:bold;\">".$db->f("product_name")."</span>\n";
$html .= "<br />\n";

if ($db->f("product_parent_id")) {
$url = "?page=shop.product_details&category_id=$cid&flypage=".$this->get_flypage($db->f("product_parent_id"));
$url .= "&product_id=" . $db->f("product_parent_id");
} else {
$url = "?page=shop.product_details&category_id=$cid&flypage=".$this->get_flypage($db->f("product_id"));
$url .= "&product_id=" . $db->f("product_id");
}
$html .= "<a title=\"".$db->f("product_name")."\" href=\"". $sess->url($mm_action_url. "index.php" . $url)."\">";
$html .= $this->image_tag($db->f("product_thumb_image"), "alt=\"".$db->f("product_name")."\"");
$html .= "</a><br />\n";

if (_SHOW_PRICES == '1' && $show_price) {
// Show price, but without "including X% tax"
$html .= $this->show_price( $db->f("product_id"), true );
}
if (USE_AS_CATALOGUE != 1 && $show_addtocart && !strstr( $html, $VM_LANG->_PHPSHOP_PRODUCT_CALL)) {
$html .= "<br />\n";
$url = "?page=shop.cart&func=cartAdd&product_id=" .  $db->f("product_id");
$html .= "<a title=\"".$VM_LANG->_PHPSHOP_CART_ADD_TO.": ".$db->f("product_name")."\" href=\"". $sess->url($mm_action_url . "index.php" . $url)."\">".$VM_LANG->_PHPSHOP_CART_ADD_TO."</a><br />\n";
}
}

return $html;
}

image_tag function
Code: [Select]
function show_image($image, $args="", $resize=1, $path_appendix="product") {
echo $this->image_tag($image, $args, $resize, $path_appendix);
}

/**
* Returns the img tag for the given product image
*
* @param string $image The name of the imahe OR the full URL to the image
* @param string $args Additional attributes for the img tag
* @param int $resize
* (1 = resize the image by using height and width attributes,
* 0 = do not resize the image)
* @param string $path_appendix The path to be appended to IMAGEURL / IMAGEPATH
* @return The HTML code of the img tag
*/
function image_tag($image, $args="", $resize=1, $path_appendix="product") {
global $mosConfig_live_site;

$border="";
if( !strpos( $args, "border=" ))
$border="border=\"0\"";

if ($image != "") {
// URL
if( substr( $image, 0, 4) == "http" )
$url = $image;

// local image file
else {
if(PSHOP_IMG_RESIZE_ENABLE == '1' && $resize==1)
$url = $mosConfig_live_site."/components/com_virtuemart/show_image_in_imgtag.php?filename=".urlencode($image)."&newxsize=".PSHOP_IMG_WIDTH."&newysize=".PSHOP_IMG_HEIGHT."&fileout=";
else
$url = IMAGEURL.$path_appendix."/".$image;
}
}
else {
$url = IMAGEURL.NO_IMAGE."_".$mid.".jpg";
}
$html_height_width = "";
$height_greater = false;
if( file_exists(IMAGEPATH.$path_appendix."/".$image)) {
$arr = @getimagesize( IMAGEPATH.$path_appendix."/".$image );
$html_height_width = $arr[3];
$height_greater = $arr[0] < $arr[1];
if( (PSHOP_IMG_WIDTH < $arr[0] || PSHOP_IMG_HEIGHT < $arr[1]) && $resize != 0 ) {
if( $height_greater )
$html_height_width = " height=\"".PSHOP_IMG_HEIGHT."\"";
else
$html_height_width = " width=\"".PSHOP_IMG_WIDTH."\"";
}
}
if((PSHOP_IMG_RESIZE_ENABLE != '1') && ($resize==1) ) {
if( $height_greater )
$html_height_width = " height=\"".PSHOP_IMG_HEIGHT."\"";
else
$html_height_width = " width=\"".PSHOP_IMG_WIDTH."\"";
}

return "<img src=\"$url\" $html_height_width $args $border />";

}

Kruzayn

  • Beginner
  • *
  • Posts: 19
Re: ps_product need help with funtion..
« Reply #1 on: June 27, 2006, 23:13:50 pm »
Never mind, i just passed $mid to the function before $image.