Filter products and hide sale code

12 posts by 2 authors in: Forums > CMS Builder
Last Post: September 20, 2012   (RSS)

By Mohaukla - September 19, 2012 - edited: September 19, 2012

I have a list of products that comes from clicking a category button. The link works fine and looks like this:
http://2tinker.com.r15.millsys.org/category.php?categories=Yard%20and%20Garden
Please check it out to see what I am seeing.

There are 3 spots that have trouble:

1. when I title the page with what category was clicked. In the example above its "Yard and Garden"
In 2 places it should show that title but I am getting error code back about my "join" statement.

2. The product list should be filtered by what is clicked but that is showing all products.

UPDATE - I was able to fix this
3. I need an "if statement" that looks at the 'saletag' field (Checkbox) and sees if it says 'no' ... if it says no then it will show the regular price and skip the code for the sale price.
At present nothing is showing at all and I am wondering what I did wrong.



<?php header('Content-type: text/html; charset=utf-8'); ?>
<?php

$libraryPath = 'cmsAdmin/lib/viewer_functions.php';
$dirsToCheck = array('D:/HostingSpaces/2tinker/2tinker.com/wwwroot/','','../','../../','../../../');
foreach ($dirsToCheck as $dir) { if (@include_once("$dir$libraryPath")) { break; }}
if (!function_exists('getRecords')) { die("Couldn't load viewer library, check filepath in sourcecode."); }

list($footer_site_wideRecords, $footer_site_wideMetaData) = getRecords(array(
'tableName' => 'footer_site_wide',
'where' => '', // load first record
'loadUploads' => true,
'allowSearch' => false,
'limit' => '1',
));
$footer_site_wideRecord = @$footer_site_wideRecords[0]; // get first record
if (!$footer_site_wideRecord) { dieWith404("Record not found!"); } // show error message if no record found

// load records from 'products'
list($productsRecords, $productsMetaData) = getRecords(array(
'tableName' => 'products',
'perPage' => '5',
'loadUploads' => true,
'allowSearch' => false,
));


$categories = mysql_select ('categories');

?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">


<div class="breadcrumb">
<div class="container">
<h1><?php echo join(', ', $record['categories:labels']); ?></h1>
</div>

<div id="breadcrumbs">
<div class="container">
<div class="bread-1">
<a href="index.php">Home</a>
</div>
<div class="bread-2">&nbsp;</div>

<div class="bread-1">
<?php echo join(', ', $record['categories:labels']); ?>
</div>


</div><!-- << container >> -->
</div><!-- << breadcrumbs >> -->

</div>






<div class="product-list">
<?php foreach ($productsRecords as $record): ?>
<div>
<div class="product_outside_border">
<div class="product_outside">
<div class="product_inside">

<div class="right">
<div class="price">
<!-- Need "If Statement ... If not on sale - 'saletag'=no - Regular Price will show here--> <?php if ($record['saletag'] == 'no'): ?>$<?php echo htmlencode($record['price']) ?> <!-- Else show the rest--><?php else: ?>
<div class="product_sale_category">
<div class="sale-middle">Sale</div>
</div>
<span class="price-old">$<?php echo htmlencode($record['price']) ?></span>
<span class="price-new">$<?php echo htmlencode($record['sale_price']) ?></span>
<!-- END IF Statement --> <?php endif ?>
<br />
</div>
<div>&nbsp;</div>
</div>
<div class="left">
<?php foreach ($record['images'] as $index => $upload): ?><?php if ($index >= 1) { continue; } // limit uploads shown ?>
<div class="image">
<a href="<?php echo $record['_link'] ?>"><img src="<?php echo $upload['thumbUrlPath2'] ?>" width="<?php echo $upload['thumbWidth2'] ?>" height="<?php echo $upload['thumbHeight2'] ?>" alt="" /></a><br /><br />
</div>

<div class="name">
<a href="<?php echo $record['_link'] ?>"><?php echo htmlencode($record['name']) ?></a>
</div>

<div class="description">
<?php echo $record['summary']; ?>
</div>
<p>
<?php endforeach ?>
</p>
</div>
</div>
</div><!-- << product outside >> -->
</div><!-- << product outside border >> -->
</div>
<?php endforeach ?>
</div><!-- << product list >> -->


I need help with these 3 areas ...

Thanks
Michael
Michael Moyers



Owner of Just Rite Design Inc. A growing network of professionals in web design, graphic design, flash development, programming, and audio & video productions.



"Due to budget constraints, the Light at the end of the tunnel will be temporarily out!"

Re: [justritedesign] Filter products and hide sale code

Hi,

Thanks for you question. I've gone through each problem one by one below:

1) The reason you are getting an error about your join statement is because at that point the $record variable doesn't exist. It is created in the foreach loop after this point. If the categories are for each product you need to add this into the foreach loop. Or you need to get the variables you need from your database first as set it to $records.

2) I think the problem here is that you have allowSearch option in your getRecords function set to false for products. If you change it to true in the products getRecords function this should fix the problem.

// load records from 'products'
list($productsRecords, $productsMetaData) = getRecords(array(
'tableName' => 'products',
'perPage' => '5',
'loadUploads' => true,
'allowSearch' => true,
));


3) The final problem is that $record['salesTag'] is not a variable that contains either yes or no, but 0 or 1. You need to change the if statement to one of the following:

<!-- The saletag yes and no variables are stored in saletag:text -->
<?php if ($record['saletag:text'] == 'no'): ?>


or

<!-- $record['saletag'] contains 0 or 1. With 0 being no and 1 being yes The if statement below would work if ['saletag'] was set to 1 -->
<?php if ($record['saletag'] > 0): ?>


Let me know if any of these don't work.

Thanks!
Greg Thomas







PHP Programmer - interactivetools.com

Re: [greg] Filter products and hide sale code

1. I was hoping that the value came from the link and was enough ...

/category.php?categories=Yard%20and%20Garden

I need to know know what to add to the foreach loop so that it knows how to filter the list.

2. I changed the false to true for the allowsearch and now nothing in the list is showing
sorry

3. I did fix that as I realized that needed a different value. I just added a similar checklist and made sure that values were correct to make the argument
Thanks for that!
Michael Moyers



Owner of Just Rite Design Inc. A growing network of professionals in web design, graphic design, flash development, programming, and audio & video productions.



"Due to budget constraints, the Light at the end of the tunnel will be temporarily out!"

Re: [justritedesign] Filter products and hide sale code

Hi,

It would help if I was able to see how your tables are set up so I can suggest changes. Could you change allowSearch back to false again and then run showme($productsRecords[0]); exit; afterwards. This will output a record onto your page. If you could paste into the forum the result that gets returned I can get a better picture of what the problem might be for point two.

<?php header('Content-type: text/html; charset=utf-8'); ?>
<?php

$libraryPath = 'cmsAdmin/lib/viewer_functions.php';
$dirsToCheck = array('D:/HostingSpaces/2tinker/2tinker.com/wwwroot/','','../','../../','../../../');
foreach ($dirsToCheck as $dir) { if (@include_once("$dir$libraryPath")) { break; }}
if (!function_exists('getRecords')) { die("Couldn't load viewer library, check filepath in sourcecode."); }

list($footer_site_wideRecords, $footer_site_wideMetaData) = getRecords(array(
'tableName' => 'footer_site_wide',
'where' => '', // load first record
'loadUploads' => true,
'allowSearch' => false,
'limit' => '1',
));
$footer_site_wideRecord = @$footer_site_wideRecords[0]; // get first record
if (!$footer_site_wideRecord) { dieWith404("Record not found!"); } // show error message if no record found

// load records from 'products'
list($productsRecords, $productsMetaData) = getRecords(array(
'tableName' => 'products',
'perPage' => '5',
'loadUploads' => true,
'allowSearch' => false,
));
showme(productsRecords[0]);
exit;


The following might fix point one if the mysql_select function is returning an array. If you change your code this for the breadcrumbs section to something like this:

<div class="breadcrumb">
<div class="container">
<h1><?php echo @$_REQUEST['categories']; ?></h1>
</div>

<div id="breadcrumbs">
<div class="container">
<div class="bread-1">
<a href="index.php">Home</a>
</div>

<?php foreach($categories $key => $record): ?>
<div class="<?php echo $key+2; ?>">
<?php echo $record['nameFieldGoesHere']; ?> ?>
</div>
<?php endforeach ?>


</div><!-- << container >> -->
</div><!-- << breadcrumbs >> -->

</div>

You can also use the showme() function to see if the $categories variable contains an array of categories and what each one is called.

Thanks!
Greg Thomas







PHP Programmer - interactivetools.com

Re: [greg] Filter products and hide sale code

));
showme(productsRecords[0]);
exit;


Is that correct? I added the "$" and the code seemed correct but came up with an error anyway.

It is there now so you can see ...
Parse error: syntax error, unexpected '[' in D:\HostingSpaces\2tinker\2tinker.com\wwwroot\category.php on line 30

My Code:
// load records from 'products'
list($productsRecords, $productsMetaData) = getRecords(array(
'tableName' => 'products',
'perPage' => '5',
'loadUploads' => true,
'allowSearch' => false,
));

$categories = mysql_select ('categories');
$showme(productsRecords[0]);
exit;
?>

Michael Moyers



Owner of Just Rite Design Inc. A growing network of professionals in web design, graphic design, flash development, programming, and audio & video productions.



"Due to budget constraints, the Light at the end of the tunnel will be temporarily out!"

Re: [justritedesign] Filter products and hide sale code

Sorry! Your correct, I forgot to add a dollar sign in there. It should have been:

// load records from 'products'
list($productsRecords, $productsMetaData) = getRecords(array(
'tableName' => 'products',
'perPage' => '5',
'loadUploads' => true,
'allowSearch' => false,
));

$categories = mysql_select ('categories');
showme($productsRecords[0]);
exit;
?>

Greg Thomas







PHP Programmer - interactivetools.com

Re: [greg] Filter products and hide sale code

Here is what I got:

Array
(
[_filename] =>
[_link] => products.php?4
[_tableName] => products
[button_code] => <form target="paypal" action="https://www.paypal.com/cgi-bin/webscr" method="post"><br/>
<input type="hidden" name="cmd" value="_s-xclick"><br/>
<input type="hidden" name="hosted_button_id" value="5ULH8L7D9P6QY"><br/>
<input type="image" src="https://www.paypalobjects.com/en_US/i/btn/btn_cart_SM.gif" border="0" name="submit" alt="PayPal - The safer, easier way to pay online!"><br/>
<img alt="" border="0" src="https://www.paypalobjects.com/en_US/i/scr/pixel.gif" width="1" height="1"><br/>
</form><br/>

[categories] => 1
[categories:labels] => Array
(
[0] => Yard and Garden
)

[categories:values] => Array
(
[0] => 1
)

[createdByUserNum] => 1
[createdDate] => 2012-09-13 02:27:01
[description] => <p>Cover that ugly well pipe or just add to the decor of your yard or garden. This mushroom is constructed of durable fiberglass. It becomes more realistic year after year (The pictured item is 10 years old), as the surface ages. Approximately 24" high X 24" in diameter.</p>
[dragSortOrder] => 90
[in_stock] => 1
[in_stock:text] => Yes
[name] => Decorative Mushroom
[num] => 4
[price] => 142.50
[product_id_sku] =>
[sale_price] => 125.00
[seo_keywords] => yard, mushroom, decorative, fiberglass
[show_on_sale] => no
[show_on_sale:label] => No
[summary] => <p>Cover that ugly well pipe or just add to the ...</p>
[updatedByUserNum] => 1
[updatedDate] => 2012-09-19 17:00:42
[images] => Array
(
[0] => Array
(
[num] => 5
[order] => 1
[createdTime] => 2012-09-14 21:30:19
[tableName] => products
[fieldName] => images
[recordNum] => 4
[preSaveTempId] =>
[filePath] => D:\HostingSpaces\2tinker\2tinker.com\wwwroot\cmsAdmin\uploads/mushroom_png.png
[urlPath] => /cmsadmin/uploads/mushroom_png.png
[width] => 400
[height] => 400
[thumbFilePath] => D:\HostingSpaces\2tinker\2tinker.com\wwwroot\cmsAdmin\uploads/thumb/mushroom_png.png
[thumbUrlPath] => /cmsadmin/uploads/thumb/mushroom_png.png
[thumbWidth] => 400
[thumbHeight] => 400
[thumbFilePath2] => D:\HostingSpaces\2tinker\2tinker.com\wwwroot\cmsAdmin\uploads/thumb2/mushroom_png.png
[thumbUrlPath2] => /cmsadmin/uploads/thumb2/mushroom_png.png
[thumbWidth2] => 150
[thumbHeight2] => 150
[thumbFilePath3] => D:\HostingSpaces\2tinker\2tinker.com\wwwroot\cmsAdmin\uploads/thumb3/mushroom_png.png
[thumbUrlPath3] => /cmsadmin/uploads/thumb3/mushroom_png.png
[thumbWidth3] => 50
[thumbHeight3] => 50
[thumbFilePath4] =>
[thumbUrlPath4] =>
[thumbWidth4] => 0
[thumbHeight4] => 0
[info1] => Decorative Mushroom
[info2] => Cover that ugly well pump
[info3] =>
[info4] =>
[info5] =>
[_tableName] => uploads
[filename] => mushroom_png.png
[extension] => png
[isImage] => 1
[hasThumbnail] => 1
)

[1] => Array
(
[num] => 13
[order] => 2
[createdTime] => 2012-09-17 22:01:41
[tableName] => products
[fieldName] => images
[recordNum] => 4
[preSaveTempId] =>
[filePath] => D:\HostingSpaces\2tinker\2tinker.com\wwwroot\cmsAdmin\uploads/001.jpg
[urlPath] => /cmsadmin/uploads/001.jpg
[width] => 600
[height] => 450
[thumbFilePath] => D:\HostingSpaces\2tinker\2tinker.com\wwwroot\cmsAdmin\uploads/thumb/001.jpg
[thumbUrlPath] => /cmsadmin/uploads/thumb/001.jpg
[thumbWidth] => 400
[thumbHeight] => 300
[thumbFilePath2] => D:\HostingSpaces\2tinker\2tinker.com\wwwroot\cmsAdmin\uploads/thumb2/001.jpg
[thumbUrlPath2] => /cmsadmin/uploads/thumb2/001.jpg
[thumbWidth2] => 150
[thumbHeight2] => 113
[thumbFilePath3] => D:\HostingSpaces\2tinker\2tinker.com\wwwroot\cmsAdmin\uploads/thumb3/001.jpg
[thumbUrlPath3] => /cmsadmin/uploads/thumb3/001.jpg
[thumbWidth3] => 50
[thumbHeight3] => 38
[thumbFilePath4] =>
[thumbUrlPath4] =>
[thumbWidth4] => 0
[thumbHeight4] => 0
[info1] => DECORATIVE MUSHROOM
[info2] =>
[info3] =>
[info4] =>
[info5] =>
[_tableName] => uploads
[filename] => 001.jpg
[extension] => jpg
[isImage] => 1
[hasThumbnail] => 1
)

[2] => Array
(
[num] => 14
[order] => 3
[createdTime] => 2012-09-17 22:01:43
[tableName] => products
[fieldName] => images
[recordNum] => 4
[preSaveTempId] =>
[filePath] => D:\HostingSpaces\2tinker\2tinker.com\wwwroot\cmsAdmin\uploads/003.jpg
[urlPath] => /cmsadmin/uploads/003.jpg
[width] => 600
[height] => 450
[thumbFilePath] => D:\HostingSpaces\2tinker\2tinker.com\wwwroot\cmsAdmin\uploads/thumb/003.jpg
[thumbUrlPath] => /cmsadmin/uploads/thumb/003.jpg
[thumbWidth] => 400
[thumbHeight] => 300
[thumbFilePath2] => D:\HostingSpaces\2tinker\2tinker.com\wwwroot\cmsAdmin\uploads/thumb2/003.jpg
[thumbUrlPath2] => /cmsadmin/uploads/thumb2/003.jpg
[thumbWidth2] => 150
[thumbHeight2] => 113
[thumbFilePath3] => D:\HostingSpaces\2tinker\2tinker.com\wwwroot\cmsAdmin\uploads/thumb3/003.jpg
[thumbUrlPath3] => /cmsadmin/uploads/thumb3/003.jpg
[thumbWidth3] => 50
[thumbHeight3] => 38
[thumbFilePath4] =>
[thumbUrlPath4] =>
[thumbWidth4] => 0
[thumbHeight4] => 0
[info1] => DECORATIVE MUSHROOM
[info2] =>
[info3] =>
[info4] =>
[info5] =>
[_tableName] => uploads
[filename] => 003.jpg
[extension] => jpg
[isImage] => 1
[hasThumbnail] => 1
)

[3] => Array
(
[num] => 15
[order] => 4
[createdTime] => 2012-09-17 22:01:45
[tableName] => products
[fieldName] => images
[recordNum] => 4
[preSaveTempId] =>
[filePath] => D:\HostingSpaces\2tinker\2tinker.com\wwwroot\cmsAdmin\uploads/004.jpg
[urlPath] => /cmsadmin/uploads/004.jpg
[width] => 600
[height] => 450
[thumbFilePath] => D:\HostingSpaces\2tinker\2tinker.com\wwwroot\cmsAdmin\uploads/thumb/004.jpg
[thumbUrlPath] => /cmsadmin/uploads/thumb/004.jpg
[thumbWidth] => 400
[thumbHeight] => 300
[thumbFilePath2] => D:\HostingSpaces\2tinker\2tinker.com\wwwroot\cmsAdmin\uploads/thumb2/004.jpg
[thumbUrlPath2] => /cmsadmin/uploads/thumb2/004.jpg
[thumbWidth2] => 150
[thumbHeight2] => 113
[thumbFilePath3] => D:\HostingSpaces\2tinker\2tinker.com\wwwroot\cmsAdmin\uploads/thumb3/004.jpg
[thumbUrlPath3] => /cmsadmin/uploads/thumb3/004.jpg
[thumbWidth3] => 50
[thumbHeight3] => 38
[thumbFilePath4] =>
[thumbUrlPath4] =>
[thumbWidth4] => 0
[thumbHeight4] => 0
[info1] => DECORATIVE MUSHROOM
[info2] =>
[info3] =>
[info4] =>
[info5] =>
[_tableName] => uploads
[filename] => 004.jpg
[extension] => jpg
[isImage] => 1
[hasThumbnail] => 1
)

)

[createdBy.num] => 1
[createdBy.createdDate] => 2012-09-11 20:34:40
[createdBy.createdByUserNum] => 0
[createdBy.updatedDate] => 2012-09-11 20:34:40
[createdBy.updatedByUserNum] => 0
[createdBy.fullname] => Michael Moyers
[createdBy.email] => mikemoyers@justritedesign.com
[createdBy.username] => justrite
[createdBy.lastLoginDate] => 2012-09-19 19:07:40
[createdBy.expiresDate] => 0000-00-00 00:00:00
[createdBy.neverExpires] => 1
[createdBy.isAdmin] => 1
[createdBy.disabled] => 0
[createdBy.accessList] =>
[createdBy._filename] =>

Michael Moyers



Owner of Just Rite Design Inc. A growing network of professionals in web design, graphic design, flash development, programming, and audio & video productions.



"Due to budget constraints, the Light at the end of the tunnel will be temporarily out!"

Re: [justritedesign] Filter products and hide sale code

Thanks for that. It's helped me understand the structure of your tables a little better.

Did you have a chance to see if the changes I suggested for point one worked at all? Do you know if the categories array is returning anything from the categories table?

I think the reason that allowSearch is returning no results is because it isn't looking for the title but for the category values. So instead of categories=Yard%20And%20Garden being passed in your url you need to pass the number. So in this case of it would be categories=1. If you remove:
$showme(productsRecords[0]);
exit;


and put allowSearch back to true again. The url below should then filter out yard and garden items.

http://2tinker.com.r15.millsys.org/category.php?categories=1

Thanks
Greg Thomas







PHP Programmer - interactivetools.com

Re: [greg] Filter products and hide sale code

OK Great that works ... so what do I do with the title tags:
<?php echo @$_REQUEST['categories']; ?>

these are now returning the 'num' instead of the title text
Michael Moyers



Owner of Just Rite Design Inc. A growing network of professionals in web design, graphic design, flash development, programming, and audio & video productions.



"Due to budget constraints, the Light at the end of the tunnel will be temporarily out!"