Hi David,
I have successfully added an availability field to my prices file using your thread.
I have also added the following to prices.php as I have some products that are in stock, some out of stock and some pre order.
<?php if (empty($product["stock"])): ?>
<?php print translate("Check Retailer"); ?>
<?php elseif ($product["stock"]==1): ?>
<?php print translate("Out of Stock"); ?>
<?php elseif ($product["stock"]==2): ?>
<?php print translate("In Stock"); ?>
<?php elseif ($product["stock"]==3): ?>
<?php print translate("Pre Order"); ?>
<?php else: ?>
<?php print translate("Out of Stock"); ?>
<?php endif; ?>
This is all working fine however, I was wondering if I could in some way sort the listings in prices.php by stock availability?
Many thanks.
Hamish
Hi David,
Thanks for your prompt reply, fast and efficient as always.
I have some feeds that don't have stock info in them, hence why I had a 'Check Retailer' option. Changing the order isn't a problem though.
Also, I am using 12/10A and the line you have highlighted doesn't have the "' ORDER BY price"; option.
Thanks again,
Hamish
Hi Hamish,
Ah - in 12/10A the equivalent will have to go into the cmp() function; which begins at line 49:
function cmp($a, $b)
{
if ($a["price"] == $b["price"])
{
return 0;
}
return ($a["price"] < $b["price"]) ? -1 : 1;
}
...REPLACE that with:
function cmp($a, $b)
{
if ($a["stock"] <> $b["stock"])
{
return ($a["stock"] > $b["stock"]) ? -1 : 1;
}
if ($a["price"] == $b["price"])
{
return 0;
}
return ($a["price"] < $b["price"]) ? -1 : 1;
}
Cheers,
David.
--
PriceTapestry.com
Thats got it, thanks for your help - brilliant!
Cheers,
Hamish
Hi Hamish,
Would it be possible to change the sequence so that 3 = in stock, 2 = pre-order, 1 or else = out of stock as this would map to a logical ORDER BY stock DESC, price in products.php (replacing "ORDER BY price" at line 12).
If you do need to work with those values, it can still be done but would require an SQL CASE statement. Line 12 in the 11/09A distribution is:
$sql = "SELECT * FROM `".$config_databaseTablePrefix."products` WHERE normalised_name = '".database_safe($q)."' ORDER BY price";
...REPLACE with;
$sql = "SELECT *,
CASE stock
WHEN '2' THEN 1
WHEN '3' THEN 2
ELSE 999
END as priority
FROM `".$config_databaseTablePrefix."products` WHERE normalised_name = '".database_safe($q)."' ORDER BY stocksort,price";
Hope this helps!
Cheers,
David.
--
PriceTapestry.com