Author Topic: Cart has to many $ signs Please help  (Read 4200 times)

spignataro

  • Beginner
  • *
  • Posts: 33
Cart has to many $ signs Please help
« on: May 08, 2006, 21:14:10 pm »
http://dev.designinnovations.net/paradise/index.php/index.php/component/page,shop.product_details/flypage,shop.flypage/product_id,17/category_id,6/manufacturer_id,0/option,com_virtuemart/Itemid,1/

Just add some stuff on the attributes...then click add to cart and boom..you will see alot of screwed up dollar signs...some are $ $ $ attrbute name or $ 2 $

it is really weird and quite random. Here is my changed code for the advanced attributes:

Code: [Select]
function list_advanced_attribute($product_id) {
global $CURRENCY_DISPLAY;
$db = new ps_DB;
$auth = $_SESSION['auth'];

$q = "SELECT product_id, attribute FROM #__{vm}_product WHERE product_id='$product_id'";
$db->query($q);
$db->next_record();

$advanced_attribute_list=$db->f("attribute");
if ($advanced_attribute_list) {
$has_advanced_attributes=1;
$fields=explode(";",$advanced_attribute_list);
$html = "";
foreach($fields as $field) {

$base=explode(",",$field);
$title=array_shift($base);
$titlevar=str_replace(" ","_",$title);
$titlevar1=strip_tags($titlevar);
$html .= "<div class=\"shopping-product_attributes\">\n\n";
$html .= "<label for=\"".$titlevar1."_field\">$title</label>:</div>\n\n";
$html .= "<div class=\"shopping-product_attribute_details\">\n\n";
foreach ($base as $base_value) {
// the Option Text
$attribtxt=substr($base_value,0,strrpos($base_value, '['));
if( $attribtxt != "") {
$vorzeichen=substr($base_value,strrpos($base_value, '[')+1,1); // negative, equal or positive?
if( $_SESSION["auth"]["show_price_including_tax"] == 1 ) {
$price = floatval(substr($base_value,strrpos($base_value, '[')+2))*(1+ @$_SESSION['product_sess'][$product_id]['tax_rate']); // calculate Tax
}
else {
$price = floatval(substr($base_value,strrpos($base_value, '[')+2));
}
// Apply shopper group discount
$price *= 1 - ($auth["shopper_group_discount"]/100);

if ($price=="0") {
$attribut_hint = "test";
}
$base_var=str_replace("_"," ",$base_value);
$html.="<input style=\"shopping-product_radio\" id=\"".$titlevar1."_field\" name=\"$titlevar1\" type=\"radio\" value=\"$base_var\" >$attribtxt ( ".$vorzeichen." ".$CURRENCY_DISPLAY->getFullValue($price)." )<br />\n\n";
}
else {
$base_var=str_replace("_"," ",$base_value);
$html.="<input style=\"shopping-product_radio\" type=\"radio\" value=\"$base_var\">$base_value\n\n";
}
}
$html.="</div><br style=\"clear:both;\" />\n\n";
}
//$html.="</table>";
}

if ($advanced_attribute_list) {
return $html;
}
}

Soeren

  • Administrator
  • Sr. Member
  • *
  • Posts: 3106
  • VirtueMart Starter
    • virtuemart.net
Re: Cart has to many $ signs Please help
« Reply #1 on: May 08, 2006, 21:19:38 pm »
Is that a fix or your code to be reviewed?

ciao, Soeren
The future of eCommerce: VirtueMart & Joomla!
http://virtuemart.net

spignataro

  • Beginner
  • *
  • Posts: 33
Re: Cart has to many $ signs Please help
« Reply #2 on: May 08, 2006, 21:21:35 pm »
This is code to reviewed and yeah it also could be considered a hack.

The code above changes the attributes from a drop down box to radio buttons. But the problem is it doesnt display the $ signs in the cart properly.

spignataro

  • Beginner
  • *
  • Posts: 33
Re: Cart has to many $ signs Please help
« Reply #3 on: May 08, 2006, 21:28:35 pm »
Also on a side note there is a fix within the code I have placed above. Depending on how you write your attributes it can display extremly crazy....because I like to use html in my attributes nothing was working. So i added a extra line to and changed the code around a little.

Code: [Select]
$base=explode(",",$field);
$title=array_shift($base);
$titlevar=str_replace(" ","_",$title);
$titlevar1=strip_tags($titlevar);

I added the titlevar1 and striped the tags and changed everything that was titlevar to titlevar1. This made things read quicker and easier as well as stripped all that html out for me.

Now the other hack that I did was changing the _ location for the base_value

$base_var=str_replace("_"," ",$base_value);

The problem was when i went to the cart it would throw in _ between the words. That is because the replace string was in the wrong location. So by doing it this way you got spaces instead of _

That is another one of my fixes.

Hope these can be put to good use and i know 1.0.5 is to late but i think this is a very important visual issue.

And back to the $ sign issue. Any suggestions on that?

spignataro

  • Beginner
  • *
  • Posts: 33
Re: Cart has to many $ signs Please help
« Reply #4 on: May 09, 2006, 16:24:19 pm »
Here is the final code for radio buttons:

Open adminstrator/components/com_virtuemart/classes/ps_product_attribute.php

Very far down around line: 286 replace the function with the below function:

Code: [Select]
function list_advanced_attribute($product_id) {
global $CURRENCY_DISPLAY;
$db = new ps_DB;
$auth = $_SESSION['auth'];

$q = "SELECT product_id, attribute FROM #__{vm}_product WHERE product_id='$product_id'";
$db->query($q);
$db->next_record();

$advanced_attribute_list=$db->f("attribute");
if ($advanced_attribute_list) {
$has_advanced_attributes=1;
$fields=explode(";",$advanced_attribute_list);
$html = "";
foreach($fields as $field) {

$base=explode(",",$field);
$title=array_shift($base);
$titlevar=str_replace(" ","_",$title);
$titlevar1=strip_tags($titlevar);
$html .= "<div class=\"shopping-product_attributes\">\n\n";
$html .= "<label for=\"".$titlevar1."_field\">$title</label>:</div>\n\n";
$html .= "<div class=\"shopping-product_attribute_details\">\n\n";
foreach ($base as $base_value) {
// the Option Text
$attribtxt=substr($base_value,0,strrpos($base_value, '['));
if( $attribtxt != "") {
$vorzeichen=substr($base_value,strrpos($base_value, '[')+1,1); // negative, equal or positive?
if( $_SESSION["auth"]["show_price_including_tax"] == 1 ) {
$price = floatval(substr($base_value,strrpos($base_value, '[')+2))*(1+ @$_SESSION['product_sess'][$product_id]['tax_rate']); // calculate Tax
}
else {
$price = floatval(substr($base_value,strrpos($base_value, '[')+2));
}
// Apply shopper group discount
$price *= 1 - ($auth["shopper_group_discount"]/100);

if ($price=="0") {
$attribut_hint = "test";
}
$base_var=str_replace("_"," ",$base_value);
$html.="<input style=\"shopping-product_radio\" id=\"".$titlevar1."_field\" name=\"$titlevar\" type=\"radio\" value=\"$base_var\" checked>$attribtxt ( ".$vorzeichen." ".$CURRENCY_DISPLAY->getFullValue($price)." )<br />\n\n";
}
else {
$base_var=str_replace("_"," ",$base_value);
$html.="<input style=\"shopping-product_radio\" id=\"".$titlevar1."_field\" name=\"$titlevar\" type=\"radio\" value=\"$base_var\" checked>$base_value\n\n";
}
}
$html.="</div><br style=\"clear:both;\" />\n\n";
}
//$html.="</table>";
}

if ($advanced_attribute_list) {
return $html;
}
}

This will take your advanced attributes and display them as radio buttons instead of drop downs.

Known things:
With checked as a defined in the loop the last thing displayed will be checked in the radio button. So have this as your lowest price option or 0 dollar option.

Known issues:
When shopping it will take you to the cart and place in front of the items a dollar amount with mulitple dollar signs or what ever sign you use. This has yet to be resolved.

I hope you like this hack.