Page 1 of 1

Problem with displaying in decimal quantities after a product search

Posted: Tue Oct 16, 2018 6:25 am
by Mirbrou
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 !

Re: Problem with displaying in decimal quantities after a product search

Posted: Tue Oct 16, 2018 6:30 am
by straightlight
Posted in wrong forum section.

Re: Problem with displaying in decimal quantities after a product search

Posted: Tue Oct 16, 2018 7:03 am
by Mirbrou
How to change or delete ?

Re: Problem with displaying in decimal quantities after a product search

Posted: Tue Oct 16, 2018 5:42 pm
by paulfeakins
Mirbrou wrote:
Tue Oct 16, 2018 7:03 am
How to change or delete ?
Moved to OC2 support.

Re: Problem with displaying in decimal quantities after a product search

Posted: Tue Oct 16, 2018 9:57 pm
by Mirbrou
Thank you, the message has been moved!

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

Re: Problem with displaying in decimal quantities after a product search

Posted: Tue Feb 26, 2019 6:24 am
by selmark.advertising
$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!

Re: Problem with displaying in decimal quantities after a product search

Posted: Tue Feb 26, 2019 10:41 am
by straightlight

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.