Page 1 of 1

Limit number of products that one can add

Posted: Sat Mar 03, 2012 6:07 pm
by designlabs
Hello,

I have been trying to think on a particular thought, if i could restrict my clients to some particular number of products that they could add. Once they are reaching the same, maybe a notification or a bar showing the number or products added.

Is this possible.

Re: Limit number of products that one can add

Posted: Sat Mar 03, 2012 7:40 pm
by Johnathan
Any reason for doing this? I don't really see an advantage to restricting the number of products.

Re: Limit number of products that one can add

Posted: Sat Mar 03, 2012 7:59 pm
by designlabs
Got a requirement. hence posted the same.

Re: Limit number of products that one can add

Posted: Sat Mar 03, 2012 11:58 pm
by Johnathan
Ah, got it. It would probably be easiest to just hide the "Insert" button when there are a certain number of products. You should be able to do it with something like this:

Code: Select all

IN:
/admin/view/template/catalog/product_list.tpl

REPLACE:
<a onclick="location = '<?php echo $insert; ?>'" class="button"><?php echo $button_insert; ?></a>

WITH:
<?php $this->load->model('catalog/product'); if ($this->model_catalog_product->getTotalProducts() <= 20) { ?>
<a onclick="location = '<?php echo $insert; ?>'" class="button"><?php echo $button_insert; ?></a>
<?php } ?>
Replace "20" with whatever number you need.

Re: Limit number of products that one can add

Posted: Sun Mar 04, 2012 12:08 am
by designlabs
Hello,

Yes this would be a easy way on this. A more practical approach it is. Thanks for this. However as a customer when I think, suppose if we were to forget that this setting is done. Then it could be mistaken for an error. I suggest a small thing as well to add up. A count of products added beside the insert button. Hence when I see 20 of 20 shown then, then any layman would understand the limit is set.

Any idea on what code we need to set in to show the counter of added products to the number of allowed products. What's your opinion.

Do let me know if this can be done.

Re: Limit number of products that one can add

Posted: Sun Mar 04, 2012 12:28 am
by Johnathan
Just take the value returned by $this->model_catalog_product->getTotalProducts(), and subtract it from the value you want, then display it next to the button.

Re: Limit number of products that one can add

Posted: Sun Mar 04, 2012 12:38 am
by designlabs
Thanks for ur answer.. However I am not a programmer bro.. Just a designer. Till now was just designing and integrating the cart. However had a peculiar request and I was stuck. Is it possible for you to tell me what could be the code. And also let me know ur skype I'd. Maybe customization projects I could send it across. What say. Could u help me with this for now.

Re: Limit number of products that one can add

Posted: Sun Mar 04, 2012 1:37 am
by Johnathan
Unfortunately I'm already overbooked with work, so I don't have time for any new projects. I recommend you post a request in the Commercial Support forum, where you might find some takers for projects.

Best of luck

Re: Limit number of products that one can add

Posted: Sun Mar 04, 2012 2:36 am
by designlabs
hey thats cool.. but thanks for your help.. really appreciate the same..

Re: Limit number of products that one can add

Posted: Sun Apr 15, 2012 4:19 pm
by wappdesign
I was looking for the same thing. Based on the comments in this thread I made an vqmod extension:

http://www.opencart.com/index.php?route ... on_id=5973

Re: Limit number of products that one can add

Posted: Wed May 30, 2018 5:43 am
by usersk
I have problem to make work this in opencart 3.0.20 , I need your help, thanks!

Code: Select all

<?xml version="1.0" encoding="utf-8"?>
<modification>
    <file path="admin/controller/catalog/product.php">
        <operation>
            <search><![CDATA[
            $product_total = $this->model_catalog_product->getTotalProducts($filter_data);
            ]]></search>
            <add position="after"><![CDATA[
            $data['br_produkti'] = $this->model_catalog_product->getTotalProducts($filter_data);
            ]]></add>
        </operation>
    </file>

<file path="admin/view/template/catalog/product_list.twig">
	<operation>
	<search><![CDATA[
	<a href="{{ add }}" data-toggle="tooltip" title="{{ button_add }}" class="btn btn-primary"><i class="fa fa-plus"></i></a>
	]]></search>
	<add position="replace"><![CDATA[
		<?php if ($br_produkti<a href="{{ add }}" data-toggle="tooltip" title="{{ button_add }}" class="btn btn-primary"><i class="fa fa-plus"></i></a>
	]]></add>
	</operation>
</file>

	
</modification>