Zen Cart Logo
Forums / Templates, Stylesheets, Page Layout / Editing function- Need a bit of help

Editing function- Need a bit of help

Locked

Views: 3,583

Results 1 to 20 of 22
This thread is locked. New replies are disabled.
13 Feb 2008, 12:20 AM
#1
amp avatar

amp

New Zenner

Join Date:
Feb 2008
Posts:
12
Plugin Contributions:
0

Editing function- Need a bit of help

Hi,
I am trying to edit the function zen_get_products_stock in functions_lookups.php to check the products url before determining the stock. I think I have it mostly done. The thing I need help with is looking up the products url. The function provides $products_id and what I need is a line of code to go inside the function which will use the $products_id to return the URL stored for the product and put it into the variable $producturl. The URL I am referring to is the one entered when creating the product. Its probably very simple I just don't know php but I know other programming languages so I've been able to do most stuff I need to.

It would be brilliant :smile: if someone could give me the line of code I need. Been trying to work it out all night.

Thanks.

All the best.

13 Feb 2008, 12:25 AM
#2
drbyte avatar

drbyte

Sensei

Join Date:
Jan 2004
Posts:
63,513
Plugin Contributions:
177

Re: Editing function- Need a bit of help

If you're trying to lookup the products_url value for a product, you can use a built-in function, like this:

$myvar = zen_products_lookup($products_id, 'products_url');
13 Feb 2008, 5:15 PM
#3
amp avatar

amp

New Zenner

Join Date:
Feb 2008
Posts:
12
Plugin Contributions:
0

Re: Editing function- Need a bit of help

Hi,

Thanks for the reply. Unfortunately it doesn't seem to work. I've tested every bit of my code and the only thing not working is looking up the url. I tried testing to see if the url look up was returning anything and as far as I can tell it doesn't. I think it just doesn't work for products_url. Although it doesn't produce an error either, instead it works as if the url returned is nothing. Is there any other way it could be done?

Thanks.

14 Feb 2008, 5:13 AM
#4
drbyte avatar

drbyte

Sensei

Join Date:
Jan 2004
Posts:
63,513
Plugin Contributions:
177

Re: Editing function- Need a bit of help

I suspect you're not passing a valid $products_id then.
I just tested it, and it works fine for me.

ie: with the Demo products installed on a fresh v1.3.8 site:```
echo zen_products_lookup(3, 'products_url');

15 Feb 2008, 1:12 AM
#5
amp avatar

amp

New Zenner

Join Date:
Feb 2008
Posts:
12
Plugin Contributions:
0

Re: Editing function- Need a bit of help

Hi,
Its definately not the passing of the $products_id as I have tested it by just putting a products id directly into the function. I have tested it in every way I can and it just doesn't seem to be passing the url. Here is the code (the other function it relates to works fine as I have tested by inputting the url).

  function zen_get_products_stock($products_id) {
    global $db;
    $products_id = zen_get_prid($products_id);//not sure if i need this so been testing with and without
    $siteurl = zen_products_lookup($products_id, 'products_url');//I have tested it with one particular products id as well
    $recip = "Stock"; // Search for this word
    if (backlinkCheck_stock($siteurl, $recip)) {
//I have tested by putting the url straight in here instead of $siteurl and it works fine
	return "0";

    } else {

	return "10";

//I am either getting an error some ways I've tried it or getting 10 as the outcome when in this case it should be 0
    }
  }

I've been working on it for ages and just can't seem to find what wrong. Any ideas?

Thanks.

15 Feb 2008, 3:59 PM
#6
drbyte avatar

drbyte

Sensei

Join Date:
Jan 2004
Posts:
63,513
Plugin Contributions:
177

Re: Editing function- Need a bit of help

try adding this line after you set $siteurl:

die('Found URL: ' . $siteurl);

What happens?

15 Feb 2008, 6:59 PM
#7
amp avatar

amp

New Zenner

Join Date:
Feb 2008
Posts:
12
Plugin Contributions:
0

Re: Editing function- Need a bit of help

It comes up with a white screen and the text "Found URL: " and thats it. I'm still trying all sorts of other ways to get it to work but no luck yet.

15 Feb 2008, 8:20 PM
#9
drbyte avatar

drbyte

Sensei

Join Date:
Jan 2004
Posts:
63,513
Plugin Contributions:
177

Re: Editing function- Need a bit of help

yellow1912:

Turn on the debug:
https://www.zen-cart.com/tutorials/index.php?article=82

The debug isn't going to help ... you're not having fatal crash problems.

15 Feb 2008, 8:21 PM
#10
drbyte avatar

drbyte

Sensei

Join Date:
Jan 2004
Posts:
63,513
Plugin Contributions:
177

Re: Editing function- Need a bit of help

change the previous "die" statement to this instead:

die('Using $products_id: ' . $products_id . '<br />Found URL: ' . $siteurl);

What happens?

15 Feb 2008, 9:40 PM
#11
amp avatar

amp

New Zenner

Join Date:
Feb 2008
Posts:
12
Plugin Contributions:
0

Re: Editing function- Need a bit of help

Yeah I didn't think debug was going to help. Thanks yellow1912 for posting anyway.

Ok, with the addition it outputs

Using $products_id: 379
Found URL: 

This is the correct product id. And I have checked and rechecked that there is a url stored for the product, and I have tried with different urls as well to make sure it wasn't that messing it up.

15 Feb 2008, 10:22 PM
#12
drbyte avatar

drbyte

Sensei

Join Date:
Jan 2004
Posts:
63,513
Plugin Contributions:
177

Re: Editing function- Need a bit of help

Is this on the admin side or the storefront?

What happens if you create a new file, perhaps called "test_url.php" and upload it to the same folder as your Zen Cart storefront's index.php, containing just this:```

<?php include('includes/application_top.php'); echo zen_products_lookup(379, 'products_url'); //EOF ``` and then access the test_url.php via your browser.
15 Feb 2008, 10:43 PM
#13
amp avatar

amp

New Zenner

Join Date:
Feb 2008
Posts:
12
Plugin Contributions:
0

Re: Editing function- Need a bit of help

Displays a completely blank page.

I'm checking this when adding a product to the shopping cart. I want to make it so that it checks a webpage for certain text to decide the quantity in stock before someone makes a purchase. Works great if the url would appear.

Could I possibly create another input value for the products and use this instead as the url seems to have decided to go missing. Or would this be quite difficult to do? Just an idea.

19 Feb 2008, 1:48 AM
#14
amp avatar

amp

New Zenner

Join Date:
Feb 2008
Posts:
12
Plugin Contributions:
0

Re: Editing function- Need a bit of help

Hi again,

After more experimenting I have found why it worked for you and not me. I installed a new zen cart with the code I'm trying to get working. The only other change I made was the url for one of the products. I tested it and it didn't work. So i then put in the following bit of code:

die('Using $products_id: ' . $products_id . '<br />Found URL: ' . $siteurl);

When I tried it again to see what this code would display I found what the problem was. It displayed the correct product id but displayed the orginal url stored for the product. I checked it and it was definately a different url entered. It seems its only returning for the orginal url stored and so when creating new products it doesn't have anything stored as the orginal.

Any ideas why its not fully updating the url? Is it maybe stored twice under different names?

Thanks.

19 Feb 2008, 3:01 AM
#15
drbyte avatar

drbyte

Sensei

Join Date:
Jan 2004
Posts:
63,513
Plugin Contributions:
177

Re: Editing function- Need a bit of help

Amp:

It displayed the correct product id but displayed the orginal url stored for the product. I checked it and it was definately a different url entered. It seems its only returning for the orginal url stored and so when creating new products it doesn't have anything stored as the orginal.

Any ideas why its not fully updating the url? Is it maybe stored twice under different names?What do you mean by "original url" vs "different url" ?

19 Feb 2008, 1:57 PM
#16
amp avatar

amp

New Zenner

Join Date:
Feb 2008
Posts:
12
Plugin Contributions:
0

Re: Editing function- Need a bit of help

What do you mean by "original url" vs "different url" ?

I mean the "original url" as in the one which was already there when I installed the zen cart with the test products. I had changed the url stored to a "different url". Although the link changed on the products page, when using this function it did not return the "different url" but the "original url" as if I had never changed it.

 $siteurl = zen_products_lookup($products_id, 'products_url');
 die('Using $products_id: ' . $products_id . '<br />Found URL: ' . $siteurl);
19 Feb 2008, 4:58 PM
#17
drbyte avatar

drbyte

Sensei

Join Date:
Jan 2004
Posts:
63,513
Plugin Contributions:
177

Re: Editing function- Need a bit of help

So, by "different url", are you simply saying that you entered a new url for the product? Or did you add another database field for a 2nd URL that you're trying to extract? Or is the "different url" generated from some other function/resource?

19 Feb 2008, 5:11 PM
#18
amp avatar

amp

New Zenner

Join Date:
Feb 2008
Posts:
12
Plugin Contributions:
0

Re: Editing function- Need a bit of help

All I did was enter a new url for the product. I didn't make any code changes or anything like that.

The different url worked when clicking on "For more information, please visit this product's webpage." but when using the code you originally gave me to find the product url it just gave me the url that was there before I entered a new one.

19 Feb 2008, 5:36 PM
#19
drbyte avatar

drbyte

Sensei

Join Date:
Jan 2004
Posts:
63,513
Plugin Contributions:
177

Re: Editing function- Need a bit of help

Amp:

All I did was enter a new url for the product. I didn't make any code changes or anything like that.

The different url worked when clicking on "For more information, please visit this product's webpage." but when using the code you originally gave me to find the product url it just gave me the url that was there before I entered a new one.

This suggests that you must be hitting a different database ... because if you updated the database with the new url, then all Zen Cart knows about is the new url. It doesn't remember "what it used to be".

How many languages do you have enabled in your site?

19 Feb 2008, 7:58 PM
#20
amp avatar

amp

New Zenner

Join Date:
Feb 2008
Posts:
12
Plugin Contributions:
0

Re: Editing function- Need a bit of help

There is no other database, just the one I'm using for my current shop. What I was thinking was that maybe the database had ended up having 2 fields for product url. One with a slightly different name. But I've been looking through the code and cannot find anything that would support this theory.
There is only one language on my website.