Jump to content
  • Checkout
  • Login
  • Get in touch

osCommerce

The e-commerce.

partially matching query fields


Supertex

Recommended Posts

Posted

My product images are named like this

 

p.product_image: "product_1_image-320.jpg"

pi.image: "product_1_image-640.jpg"

 

I'm adding the appropriate fields to the admin/categories.php query to

 

1) Verify large image exists

2) Check that "first" large image name corresponds to image name.

3) Output one of three images to indicate status

 

Should show "cross" for missing large image, "attn" for mismatch, and "check" when large image both exists and corresponds to small image.

 

I don't know how to exclude the last 7 chars of each field in the comparison, so currently will always show "attn.png"

 

   <td align="center">
 <?php
  if (is_null($products['image'])) {
    echo tep_image(DIR_WS_IMAGES . 'cross.png', 10, 10);
   } else {
    if  (($products['image'] != $products['products_image']) && ($products['sort_order'] == '1')); {
    echo tep_image(DIR_WS_IMAGES . 'attn.png', 10, 10);
    } else {
    echo tep_image(DIR_WS_IMAGES . 'check.png', 10, 10);
    }
   }
 ?>

Point me in the right direction?

Posted

You get part of the name like this

substr($products['products_image'], 0, -7);

You should verify the variable exists before doing that. I don't know if the code you show is real code or not but the semi-colon after the second if statement will cause a failure.

Support Links:

For Hire: Contact me for anything you need help with for your shop: upgrading, hosting, repairs, code written, etc.

All of My Addons

Get the latest versions of my addons

Recommended SEO Addons

Posted

@@Jack_mcs

 

Thank you so very much.

 

	 <?php
		 if (is_null($products['image'])) {
			 echo tep_image(DIR_WS_IMAGES . 'cross.png', 10, 10);
		 } else {
			 if ((substr($products['image'], 0, -7)) != (substr($products['products_image'], 0, -7))) {
 echo tep_image(DIR_WS_IMAGES . 'attn.png', 10, 10);
			 } else {
			 echo tep_image(DIR_WS_IMAGES . 'check.png', 10, 10);
			 }
		 }
	 ?>

 

This works. I had to define an exclusion in the query for "WHERE pi.sort_order IS NULL or pi.sort_order <2" in order to prevent duplicate product lines for any product with more than one large image.

 

Is that what you mean by "verify the variable exists"? Or are you talking about another statement? ..."is_set" or something?

 

Forgive me, I'm nowhere near competent for this, really.

Posted

In your first if statement, you check to see if the 'image' variable is empty. In the second if statement, you don't need to check that variable since the first check covers it. But you don't check if 'products_image' is null. It will work as it is but that oversight is the kind that creates problems later on.

Support Links:

For Hire: Contact me for anything you need help with for your shop: upgrading, hosting, repairs, code written, etc.

All of My Addons

Get the latest versions of my addons

Recommended SEO Addons

Posted

<?php
    if (is_null($products['image'])) {
        echo tep_image(DIR_WS_IMAGES . 'cross.png', 10, 10);
    } else {
        if (!isset($products['products_image']) || 
            substr($products['image'], 0, -7) != substr($products['products_image'], 0, -7)) {
                echo tep_image(DIR_WS_IMAGES . 'attn.png', 10, 10);
        } else {
                echo tep_image(DIR_WS_IMAGES . 'check.png', 10, 10);
        }
    }
?>

 

If products_image doesn't exist, it won't try to do a substr() on it ("short circuiting").

Posted

So this should cover me, ya?

 

	 <?php
		 if (is_null($products['products_image'])) {
                       echo tep_image(DIR_WS_IMAGES . 'cross.png', SMALL_IMAGE_STATUS_MISSING, 10, 10);
		 } else {
                       if (is_null($products['image'])) {
                                   echo tep_image(DIR_WS_IMAGES . 'attn.png', LARGE_IMAGE_STATUS_MISSING, 10, 10);
                       } else {
                                  if ((substr($products['image'], 0, -7)) != (substr($products['products_image'], 0, -7))) {
                                                echo tep_image(DIR_WS_IMAGES . 'attn2.png', LARGE_IMAGE_STATUS_MISMATCH, 10, 10);
                                    } else {
                                                echo tep_image(DIR_WS_IMAGES . 'check.png', LARGE_IMAGE_STATUS_GOOD, 10, 10);
                                    }
                        }
		 }
	 ?>

Posted

So this should cover me, ya?

 

It should work, but only you know what you want to accomplish and whether the code is working right. You've changed the logic quite a bit.

  • 3 months later...
Posted

I found a minor bug in this snippet. It seems that when I create a product without an image, NULL is entered in the field. However, when I copy that same product as new (to edit values later) NULL is not entered for that or any following copies. The end result is that my code, which should show me a red "X" when a product's small image is missing, only shows the "X" for the original product.

 

It seems my code only checks for NULL entries and I'm not sure how to have it check for an empty field.

 

I'm assuming something like:

	    <?php
		 if (is_null || ''($products['products_image'])) {
			   echo tep_image(DIR_WS_IMAGES . 'cross.png', SMALL_IMAGE_STATUS_MISSING, 10, 10);
		   } else {
    if (is_null || '' ($products['image'])) {
			    echo tep_image(DIR_WS_IMAGES . 'attn.png', LARGE_IMAGE_STATUS_MISSING, 10, 10);
		    } else {
			    if  ((substr($products['image'], 0, -7)) != (substr($products['products_image'], 0, -7))) {
	 echo tep_image(DIR_WS_IMAGES . 'attn2.png', LARGE_IMAGE_STATUS_MISMATCH, 10, 10);
			    } else {
				 echo tep_image(DIR_WS_IMAGES . 'check.png', LARGE_IMAGE_STATUS_GOOD, 10, 10);
			    }
   }
		   }
	    ?>

 

This, however did not work. What am I doing wrong?

Posted

For anyone else that might use this, this fixed it:

 

<?php
				  if ((is_null($products['products_image'])) || (($products['products_image']==""))) {
					    echo tep_image(DIR_WS_IMAGES . 'cross.png', SMALL_IMAGE_STATUS_MISSING, 10, 10);
					   } else {
						 if (is_null($products['image'])) {
						    echo tep_image(DIR_WS_IMAGES . 'attn.png', LARGE_IMAGE_STATUS_MISSING, 10, 10);
						   } else {
						    if  ((substr($products['image'], 0, -7)) != (substr($products['products_image'], 0, -7))) {
							    echo tep_image(DIR_WS_IMAGES . 'attn2.png', LARGE_IMAGE_STATUS_MISMATCH, 10, 10);
						    } else {
							    echo tep_image(DIR_WS_IMAGES . 'check.png', LARGE_IMAGE_STATUS_GOOD, 10, 10);
						    }
					    }
					   }
				 ?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...