Show number of products in created status

  • Posts: 171
  • Thank you received: 9
9 years 5 months ago #235856

-- HikaShop version -- : 2.6.1.

Hi!

As sometimes our stock number is not correct because of technical problems, and we also serve out our customers in our real shop personally, we would like to show the number of products only from orders which are set to 'created' status in the backend's Hikashop > Product page.

So for example to be clear: we sell ProductX in our shop. In admin, on ProductX's page we need a line, which shows a number: 0 or higher.
That number should count this ProductX from all the orders which status is created.

Any advice would be really appreciated.

Please Log in or Create an account to join the conversation.

  • Posts: 84310
  • Thank you received: 13701
  • MODERATOR
9 years 5 months ago #235871

Hi,

So you'll want to edit the file "form" of the view "product" for the backend template via the menu Display>Views and add custom code for that there. You'll need to run a MySQL query on the hikashop_order_product table based on the product_id to sum the order_product_quantity with a join on the hikashop_order table to only take into account orders with the order_status column set to "created".

The following user(s) said Thank You: pepecortez

Please Log in or Create an account to join the conversation.

  • Posts: 171
  • Thank you received: 9
9 years 4 months ago #238932

If anyone need, maybe helps, this is my solution:

<p style="margin:9px 0 0 0">
<?php echo JText::_('In created status:'); ?>
<?php
$db = JFactory::getDbo();
$query = $db->getQuery(true);
$product_id = @$this->product->product_id;
$query
->select(array('a.*', 'b.*'))
->from($db->quoteName('#__hikashop_order_product', 'a'))
->join('INNER', $db->quoteName('#__hikashop_order', 'b') . ' ON (' . $db->quoteName('a.order_id') . ' = ' . $db->quoteName('b.order_id') . ')')
->where($db->quoteName('b.order_status') . ' = \'created\' AND a.product_id = ' . $product_id);
$db->setQuery($query);
$column = $db->loadColumn(3);
$ossz = array_sum ($column);
echo $ossz;
$ws = @$this->product->product_quantity;
$szabad = $ws-$ossz;
echo ' piece(s)';
?>
</p>
<p style="color: <?php if ($szabad > 0){echo '#378137';} else {echo '#ff0000';} ?>;">
Free quantity:
<?php if ($szabad < 0){echo '0';}else{ echo $szabad;} echo ' piece(s)'; ?>
</p>

Please Log in or Create an account to join the conversation.

Time to create page: 0.056 seconds
Powered by Kunena Forum