Sort Control Customisation- Sorting by Product Reference

Miscellaneous Actinic / SellerDeck patches and anything not covered above.
Post Reply
mirage23
Posts: 7
Joined: Sun Feb 28, 2010 7:17 pm

Sort Control Customisation- Sorting by Product Reference

Post by mirage23 »

I would like to customise Sort Control to sort my items in Products & Search by Actinic Product Reference number (in ascending & decending order). Because my site auto-generates the product references they are in ascending order of the date of entry so I was thinking I could use this as a Date-Added sorter.
I understand it envolves editing the sortsupport.js file in site 1 but I'm not too good with Java Script . Any ideas/ code will be greatly appreciated.
Last edited by mirage23 on Mon Mar 01, 2010 4:10 pm, edited 1 time in total.
norman
Site Admin
Posts: 1252
Joined: Sat Feb 07, 2004 9:55 pm

Re: Sort Control Customisation- Sorting by Product Reference

Post by norman »

There's a ReadMe suppplied with this add-on that talks you through how to do this. Look in your Site folder for file "Sorting Products by a User Variable.txt" and also "Sorting Sections by a Products User Variable.txt". These show you how to add sorting on a variable called Author. To amend this to use the product reference, just follow the ReadMe but replace any occurences of:

Code: Select all

<actinic:variable encoding="html" name="Author" />
with:

Code: Select all

<actinic:variable encoding="html" name="ProductReference" />
And also change all "author" for "reference".

You may also want to check that product reference is always ascending. I'm not sure what happens if you delete products, purge and compact the database and then add a new product. There's a possibility that it gets re-allocated an older reference. I don't know if this happens or not, so you'd need to experiment.
Norman
mirage23
Posts: 7
Joined: Sun Feb 28, 2010 7:17 pm

Re: Sort Control Customisation- Sorting by Product Reference

Post by mirage23 »

Norman,

I've noticed that my product references are not in exact ascending order, that some more recently added products have been assigned a lower product ref number so I don't think sorting by this method is possible.
However, I did spot a field in the Products table called 'sCreate Date' which lists the exact date and time when a product is added. Question is, Can I some-how grab this 'sCreate Date' data from the products table and use it within Actinic? either by a Variable or some other method? If it is possible it would be a nice solution for sort products by Date Added.

thanks for all your help.
norman
Site Admin
Posts: 1252
Joined: Sat Feb 07, 2004 9:55 pm

Re: Sort Control Customisation- Sorting by Product Reference

Post by norman »

This sCreateDate variable is not available within the Actinic layouts. You'd have to use PHP and SQL to interrogate the product table using the product ID and extract the value.

Demo unsupported code below:

Code: Select all

<actinic:block php="true">
	$connect = odbc_pconnect("ActinicCatalog<actinic:variable name="ECMajorVersion" selectable="false" />","","", SQL_CUR_USE_ODBC); 
	$result = odbc_exec($connect, "SELECT `sCreateDate` FROM Product WHERE `Product Reference` = '<actinic:variable name="ProductID" selectable="false" />'"); 
	$sCreateDate = odbc_result($result, 1);
	echo $sCreateDate;
	odbc_close_all();   
</actinic:block>
Note that this will probably be very inefficient!

An Actinic problem, really. Try searching on community.actinic.com as I recall something being posted there and it may be a better method.
Norman
mirage23
Posts: 7
Joined: Sun Feb 28, 2010 7:17 pm

Re: Sort Control Customisation- Sorting by Product Reference

Post by mirage23 »

Thanks Norman,

I have now created a variable and populated it with the details from 'sCreateDate' via Access.
So I now have what I wanted which is a variable with the date information I require for each product. I want actinic to be able to sort by it so I am editing the sortedproductsupport.js, I have tried adding it the same way as a text variable but it didn't work and actinic put up a coding error.

The variable I have created is called 'Date Of Release' and the date info in it is in the format of DD/MM/YYYY.

I have succesfully created a 'sort by' for a variable for a text variable called 'Label' in the past, as you can see in this snipped from the sortedproductsupport.js:

if ( seqtype == 'lowhigh' ) searchlines.sort(function(a,b){return a.price - b.price});
if ( seqtype == 'highlow' ) searchlines.sort(function(a,b){return b.price - a.price});
if ( seqtype == 'default' ) searchlines.sort(function(a,b){return a.seq - b.seq});
if ( seqtype == 'alpha' ) searchlines.sort(function(a,b){return (a.pname <= b.pname) ? -1 : 1;});
if ( seqtype == 'reverse' ) searchlines.sort(function(a,b){return (b.pname <= a.pname) ? -1 : 1;});
if ( seqtype == 'Label' ) searchlines.sort(function(a,b){return (a.Label <= b.Label) ? -1 : 1;});
if ( seqtype == 'LabelRev' ) searchlines.sort(function(a,b){return (b.Label <= a.Label) ? -1 : 1;});

Question is, What would I need to add to the bottom of the above script to sort search by the 'Date Of Release' variable..

any help would be greatly appreciated, have got so far but have now hit a stumbling block!
norman
Site Admin
Posts: 1252
Joined: Sat Feb 07, 2004 9:55 pm

Re: Sort Control Customisation- Sorting by Product Reference

Post by norman »

The easiest way to do this is to save your dates in YYYY/MM/DD format so that they can be sorted in exactly the same way as you are doing for Label.

If your data is already populated the wrong way or it's easier to keep it in DD/MM/YYYY format, then rearrange by PHP when you store it in the <span id="sortline_..... data.

E.g. Replace:

Code: Select all

 dateofrelease="<actinic:variable encoding="html" name="Date Of Release" />"
With:

Code: Select all

 dateofrelease="<actinic:block php="true">
	$dmy = '<actinic:variable encoding="perl" selectable="false" name="Date Of Release" />';
	$ymd = substr($dmy, 6, 4) . '/' . substr($dmy, 3, 2) . '/' . substr($dmy, 0, 2);
	echo $ymd;
</actinic:block>"
Note. Demo code given. Untested.
Norman
Post Reply