Hi all,
I'm fighting with OC and I learned a lot - but it's a lot of new stuff for a non-programmer. So I hope you guys can help me once more (and yes, I searched and found a lot of posts, but without a solution):
It's easy to hide the "add to cart" part in product.tpl in general. It would be easy to put this in an if-statement - if i would know how and where to ask for the category_id for a given product_id. It must be something like
$this->db->query("SELECT category_id FROM" . DB_PREFIX . ..........
in model/catalog/product.php, right? How to create the right select statement and define a variable with the answer, so that I can use it as a condition in products.tpl
Thank you for hints,
Michael
I'm fighting with OC and I learned a lot - but it's a lot of new stuff for a non-programmer. So I hope you guys can help me once more (and yes, I searched and found a lot of posts, but without a solution):
It's easy to hide the "add to cart" part in product.tpl in general. It would be easy to put this in an if-statement - if i would know how and where to ask for the category_id for a given product_id. It must be something like
$this->db->query("SELECT category_id FROM" . DB_PREFIX . ..........
in model/catalog/product.php, right? How to create the right select statement and define a variable with the answer, so that I can use it as a condition in products.tpl
Thank you for hints,
Michael
Create a new function for the purpose.
Add the following function to "catalog/model/catalog/product.php":-
Then, in "catalog/controller/product.php", somewhere around line 165, insert the following:-
Then you can use a conditional in "catalog/view/theme/YOUR_TEMPLATE/product/product.tpl" (lines 93 to 97), eg.:
Add the following function to "catalog/model/catalog/product.php":-
Code: Select all
public function getProductCategory($product_id) {
$query = $this->db->query("SELECT DISTINCT category_id FROM " . DB_PREFIX . "product_to_category WHERE product_id = '" . (int)$product_id . "'");
return $query->row['category_id'];
}
Code: Select all
$this->data['product_category'] = $this->model_catalog_product->getProductCategory($this->request->get['product_id']);
Code: Select all
<?php if ($product_category != '999') { ?>
<div class="content"><?php echo $text_qty; ?>
<input type="text" name="quantity" size="3" value="1" />
<a onclick="$('#product').submit();" id="add_to_cart" class="button"><span><?php echo $button_add_to_cart; ?></span></a></div>
<div><input type="hidden" name="product_id" value="<?php echo $product_id; ?>" />
<input type="hidden" name="redirect" value="<?php echo str_replace('&', '&', $redirect); ?>" /></div>
<?php } ?>
Modules for OpenCart 2.3.0.2
Homepage Module [Free - since OpenCart 0.7.7]
Multistore Extensions
Store Manager Multi-Vendor/Multi-Store management tool
If you're not living on the edge ... you're taking up too much space!
Hi, I'm trying to do the exact same thing, but in Open cart 3.0.2.0, I've tried following these instructions but I've a feeling I'm missing something due to the changes in OC 3x
Any chance someone could provide the same code as above but for version 3.0.2.0
Cheers
Any chance someone could provide the same code as above but for version 3.0.2.0
Cheers
if you need hide "add to cart" button in product page in OC3.0.2 you can try this...
In catalog/controller/product/product.php finde:
(line approx. 157) after add:
in In catalog/model/product/product.php add new function:
in catalog/view/theme/YOUR-THEME/template/product/product.twig find:
replace with:
this should hide add to cart button for products in category_id=999
My suggestion to make this using OCMOD
Cheers
In catalog/controller/product/product.php finde:
Code: Select all
$this->load->model('catalog/product');
Code: Select all
$data['product_category'] = $this->model_catalog_product->getProductCategory($product_id);
Code: Select all
public function getProductCategory($product_id) {
$query = $this->db->query("SELECT DISTINCT category_id FROM " . DB_PREFIX . "product_to_category WHERE product_id = '" . (int)$product_id . "'");
return $query->row['category_id'];
}
Code: Select all
<button type="button" id="button-cart" data-loading-text="{{ text_loading }}" class="btn btn-primary btn-lg btn-block">{{ button_cart }}</button>
Code: Select all
{% if (product_category != ' 999' ) %}
<button type="button" id="button-cart" data-loading-text="{{ text_loading }}" class="btn btn-primary btn-lg btn-block">{{ button_cart }}</button>
{% endif %}
My suggestion to make this using OCMOD
Cheers
Custom OpenCart modules and solutions. You can write PM with additional questions... Extensions you can find here
Who is online
Users browsing this forum: No registered users and 128 guests