Discount Qty

  • Posts: 223
  • Thank you received: 13
3 weeks 1 day ago #370150

-- HikaShop version -- : 6.2.0
-- Joomla version -- : 6.0.2
-- PHP version -- : 8.3

hi
how can i create something like attached image in hikashop ?
the quantity of products in my site is unlimited, but i want sell only 20 of each with discount

i know there is an option in create discounts to limi the number of pacheses, however i want to show how much of that product has been sold with discouns

something like attached image

Attachments:

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

  • Posts: 85113
  • Thank you received: 13880
  • MODERATOR
3 weeks 18 hours ago #370152

Hi,

You can achieve this by adding a small code snippet to your view override of product / listing_img_title.php via the menu Display>Views and a custom product field where you can provide the initial stock of the product.
Assuming your custom field calls its column initial_stock, you can insert the following code where you want the bar to appear (for example, just after the product image div/span):

<?php
// CUSTOM PROGRESS BAR
if(!empty($this->row->initial_stock) && (int)$this->row->initial_stock > 0) {
    $initial = (int)$this->row->initial_stock;
    $current = (int)$this->row->product_quantity;
    // Calculate percentage remaining.
    // To show "percentage sold" instead, use: $percent = 100 - (($current / $initial) * 100);
    $percent = ($current / $initial) * 100;
    $percent = max(0, min(100, $percent)); // Keep between 0-100
?>
    <div class="hikashop_stock_progress" style="margin: 5px 0;">
        <!-- The Bar Container -->
        <div style="background-color: #f3f3f3; height: 10px; border-radius: 5px; overflow: hidden; border: 1px solid #ddd;">
            <div style="background-color: #28a745; height: 100%; width: <?php echo $percent; ?>%;"></div>
        </div>
        <!-- The Text Info -->
        <div style="text-align: center; font-size: 11px; margin-top: 2px; color: #555;">
            <?php echo $current; ?> / <?php echo $initial; ?> items left
        </div>
    </div>
<?php
}
?>

The following user(s) said Thank You: khashiz

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

  • Posts: 223
  • Thank you received: 13
2 weeks 6 days ago #370164

so i have to create a custom field ?

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

  • Posts: 85113
  • Thank you received: 13880
  • MODERATOR
2 weeks 6 days ago #370165

Hi,

Yes, of the table "product", with the column name "initial_stock" so that you can provide the initial stock amount before purchases are made. The normal stock will decrement upon purchase, while this initial stock value will stay the same so that the progress bar can be calculated against it.

The following user(s) said Thank You: khashiz

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

Time to create page: 0.069 seconds
Powered by Kunena Forum