Originally Posted by
marcopolo
Is it possible for you to do the code for the stock way, I'm stuck like I said it's returning 0.00 so it's not working or giving me any errors to see why.
The fundraiser has started and I would like to have it display the amount. Below is the way I think it would work:
Check current stock of products_id that = 1200
then subtract that output from 1000
Then multiple that output by 12
Then populate var currentAmount below with the number:
<script type="text/javascript">
var currentAmount = 1367;
</script>
Well, looking over my code from before, I do see that there were two "obvious" issues with it. The while loop doesn't actually step through the process (doesn't increment if it is/was executed, and also there was no variable really to check as part of the beginning).. I was going to ask that some troubleshooting data be added, which I show below; however, it seems that there were some bugs in the code.
Code:
$start_datetime = '2020-03-20 05:00:00";
$end_datetime = date(DATE_TIME_FORMAT, time()); // Is an example of checking up until now although that portion could be left off if a running total was wanted and just need to return all values greater than the start date. Else, put in the end date as desired.
$quantity_sold_query = "SELECT op.products_quantity, op.products_price, op.products_tax, op.final_price, o.currency, o.currency_value FROM " . TABLE_ORDERS_PRODUCTS . " op, " . TABLE_ORDERS . " o WHERE op.products_id = :products_id: AND op.orders_id = o.orders_id AND o.date_purchased > STR_TO_DATE(:start_datetime:, :datetimeformat:) AND o.date_purchased < STR_TO_DATE(:end_datetime:, :datetimeformat:) ORDER BY o.date_purchased ASC";
// ORDER BY ASC provides list with oldest purchase (by date) at the top and newest at the bottom.
$quantity_sold_query = $db->bindVars($quantity_sold_query, ":products_id:", 1200, 'integer');
$quantity_sold_query = $db->bindVars($quantity_sold_query, ":start_datetime:", $start_datetime, 'string');
$quantity_sold_query = $db->bindVars($quantity_sold_query, ":end_datetime:", $end_datetime, 'string');
$quantity_sold_query = $db->bindVars($quantity_sold_query, ":datetimeformat:", DATE_TIME_FORMAT, 'string');
$quantity_sold = $db->Execute($quantity_sold_query);
//Since ZC version is not identified, a generic loop is offered instead of the options available as of ZC 1.5.5 where one can
// loop on foreach instead of while (!$quantity_sold->EOF)
$money = 0;
$subtract_amount = 10;
while (!$quantity_sold->EOF) {
//For troubleshooting uncomment the below:
// trigger_error('Sold Data: ' . print_r($quantity_sold, true), E_USER_WARNING);
// For troubleshooting uncomment the above:. To comment it out again add two forward slashes at the start of the line(s): I.e. //
$amount_sale = $currencies->value($quantity_sold->fields['final_price'] * $quantity_sold->fields['products_quantity'], true, $quantity_sold->fields['currency'], $quantity_sold->fields['currency_value']);
$amount_deducted = $subtract_amount * $quantity_sold->fields['products_quantity'];
$amount_sale -= $currencies->value($amount_deducted, true, DEFAULT_CURRENCY);
// If item was free or some other characteristic caused it to be free, then do not remove more from the funds collected.
if ($amount_sale < 0) {
$amount_sale = 0;
}
$money += $amount_sale;
$quantity_sold->MoveNext();
}
// To display just the number(s) use the below:
echo $money;
// To display as a currency:
// echo $currencies->format($money);
Bookmarks