Post by Mirbrou » Tue Oct 16, 2018 6:25 am

In my store, I sell fabrics and products related to sewing. The fabrics are displayed in decimal as 1.5 meters and the various products in units. I use an "if" function with categories.
This code works well when using categories to find a product. But when using the search function, the product loses its category. And we get, for example, for "button" = 0.25 m! It is a problem!

You can go to the situation: cotonflanelle.com
For example, search: READY SEWING KIT

Code: Select all

<div class="cart">
	<div class="add-to-cart clearfix">
			          <p><label class="control-label" for="input-quantity"><?php echo $entry_qty; ?></label>
			              <div class="quantity" style="padding: 7px 10px 5px 0px;">
                    <?php if (($category_id=="51")or($category_id=="55")or($category_id=="109")or($category_id=="265")or($category_id=="282")or($category_id=="283")or($category_id=="292")or($category_id=="294")or($category_id=="306")or($category_id=="186")or($category_id=="187")or($category_id=="188")or($category_id=="189")or($category_id=="190")) { ?>
                                           <input type="text" name="quantity" id="quantity_wanted" size="4" value="1" type="number" step="1" />

                                        <script>
                                          $(document).ready(function() {
                                          $("#quantity").change(function() {
                                          $(this).val(Math.ceil($(this).val()));
                                          });
                                          });
                                        </script>
                  <?php } else { ?>
                   <select id="quantity" name="quantity">
                      <option value="0.25">0.25 m</option>
                      <option value="0.50">0.50 m</option>
                      <option value="0.75">0.75 m</option>
                      <option value="1.00">1 m</option>
                      <option value="1.25">1.25 m</option>
                      <option value="1.50">1.50 m</option>
                      <option value="1.75">1.75 m</option>
                      <option value="2.00">2 m</option>
                      <option value="2.25">2.25 m</option>
                      <option value="2.50">2.50 m</option>
                      <option value="2.75">2.75 m</option>
                      <option value="3.00">3 m</option>
                      <option value="3.25">3.25 m</option>
                      <option value="3.50">3.50 m</option>
                      <option value="3.75">3.75 m</option>
                      <option value="4.00">4 m</option>
                      <option value="4.25">4.25 m</option>
                      <option value="4.50">4.50 m</option>
                      <option value="4.75">4.75 m</option>
                      <option value="5.00">5 m</option></select>
                  <?php } ?>
            </div>
			          </p>
		    
			          <input type="hidden" name="product_id" size="1" value="<?php echo $product_id; ?>" />
			          &nbsp;
						<?php if($theme_options->get( 'display_add_to_cart' ) != '0' ) { ?>
							<div class="cart-holder">
								<input type="button" value="<?php if($theme_options->get( 'add_to_cart_text', $config->get( 'config_language_id' ) ) != '') { echo $theme_options->get( 'add_to_cart_text', $config->get( 'config_language_id' ) ); } else { echo 'Add to cart'; } ?>" id="button-cart" rel="<?php echo $product_id; ?>" class="button" />
								<a href="<?php echo "https://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]"; ?>" class="button" id="button-more-details"><?php if($theme_options->get( 'more_details_text', $config->get( 'config_language_id' ) ) != '') { echo html_entity_decode($theme_options->get( 'more_details_text', $config->get( 'config_language_id' ) )); } else { echo 'More details'; } ?></a>
							</div>
						<?php } ?>
</div>
How to make sure the product keeps its category?

I had thought of using the tag, but this way seems more complicated to me. Would there be a module that could do what I want?

Thank you for your help !
Last edited by Mirbrou on Tue Oct 16, 2018 9:43 pm, edited 1 time in total.

https://cotonflanelle.com in OC2.3.0.2
Kingstorepro - ThemeGlobal
Advanced SEO - Webkul
Product Preorder Pro - Webkul
Webkul Quickbook Connector - Webkul
Customers Also Viewed / Purchased
opencart-2-x-export-import-multilingual-3-12 - J. Neuhoff


Newbie

Posts

Joined
Tue Jun 27, 2017 6:25 am

Post by straightlight » Tue Oct 16, 2018 6:30 am

Posted in wrong forum section.

The most generated errors being found on Opencart forum originates from contributed programming. The increased post counters are caused by redundancies of the same solutions that were already provided prior.


Regards,
Straightlight
Opencart.com Administrator / Quality Assurance Analyst / Programmer


Administrator

Posts

Joined
Mon Nov 14, 2011 11:38 pm
Location - Canada, ON

Post by Mirbrou » Tue Oct 16, 2018 7:03 am

How to change or delete ?

https://cotonflanelle.com in OC2.3.0.2
Kingstorepro - ThemeGlobal
Advanced SEO - Webkul
Product Preorder Pro - Webkul
Webkul Quickbook Connector - Webkul
Customers Also Viewed / Purchased
opencart-2-x-export-import-multilingual-3-12 - J. Neuhoff


Newbie

Posts

Joined
Tue Jun 27, 2017 6:25 am

Post by paulfeakins » Tue Oct 16, 2018 5:42 pm

Mirbrou wrote:
Tue Oct 16, 2018 7:03 am
How to change or delete ?
Moved to OC2 support.

For quick, professional OpenCart support please email info@antropy.co.uk


User avatar
Expert Member

Posts

Joined
Mon Aug 22, 2011 11:01 pm
Location - Reigate, Surrey, United Kingdom

Post by Mirbrou » Tue Oct 16, 2018 9:57 pm

Thank you, the message has been moved!

So, do you have an idea for my problem?
:)

https://cotonflanelle.com in OC2.3.0.2
Kingstorepro - ThemeGlobal
Advanced SEO - Webkul
Product Preorder Pro - Webkul
Webkul Quickbook Connector - Webkul
Customers Also Viewed / Purchased
opencart-2-x-export-import-multilingual-3-12 - J. Neuhoff


Newbie

Posts

Joined
Tue Jun 27, 2017 6:25 am

Post by selmark.advertising » Tue Feb 26, 2019 6:24 am

$category_id seems to be valid only for categories. Does it trigger an error on search?

I guess that your problem is not that you don't know what category you're in on the product page after searching, you actually don't know what categories the product is part of. This applies to search and specials and manufacturers if i'm correct.

catalog/controller/product/product.php
add before $data['images'] = array(); this code:

Code: Select all

$check_array = array(51,55,109,265,282,283,292,294,306,186,187,188,189,190);
$product_categories_ids = $this->model_catalog_product->getCategories($result['product_id']);
$check = false;
foreach( $product_categories_ids as $id ) {
if( in_array($id, $check_array) ) {
$check = true;
}
}
$data['show_decimal'] = $check;
Now replace your check in the tpl file:

Code: Select all

<?php if (($category_id=="51")or($category_id=="55")or($category_id=="109")or($category_id=="265")or($category_id=="282")or($category_id=="283")or($category_id=="292")or($category_id=="294")or($category_id=="306")or($category_id=="186")or($category_id=="187")or($category_id=="188")or($category_id=="189")or($category_id=="190")) { ?>
with this:

Code: Select all

<?pnp if( $show_decimal == true ) { ?>
You may extend my example to specials and manufacturers if my untested code is correct. Cheers!


Posts

Joined
Mon Feb 25, 2019 6:53 pm

Post by straightlight » Tue Feb 26, 2019 10:41 am

Code: Select all

$check_array = array(51,55,109,265,282,283,292,294,306,186,187,188,189,190);

$product_categories_ids = $this->model_catalog_product->getCategories($result['product_id']);

$p2c_intersect = array_intersect($product_categories_ids, $check_array);

$data['show_decimal'] = ($p2c_intersect ? true : false);
No need to create a loop statement between two arrays especially due to the array size that may be returned from database queries.

The most generated errors being found on Opencart forum originates from contributed programming. The increased post counters are caused by redundancies of the same solutions that were already provided prior.


Regards,
Straightlight
Opencart.com Administrator / Quality Assurance Analyst / Programmer


Administrator

Posts

Joined
Mon Nov 14, 2011 11:38 pm
Location - Canada, ON
Who is online

Users browsing this forum: No registered users and 51 guests