Page 1 of 2 12 LastLast
Results 1 to 10 of 17
  1. #1
    Join Date
    Oct 2010
    Posts
    27
    Plugin Contributions
    0

    Default crash with my custom function zen_get_products_model()

    I made a function file and i put in extra_functions in cart side
    I made a function make some friendly URL for o particular picture and ..
    when i user $model = zen_get_products_model($products_id) ; zen crash.

    i make ca copy of the function zen_get_products_model in my file ( i rename it ) and it works
    .. i try with try catch .. i don`t see what is the error.

    maybe is a bug .. Check .. and see..

    ZenCart 1.5

  2. #2
    Join Date
    Jan 2007
    Location
    Australia
    Posts
    3,946
    Plugin Contributions
    1

    Default Re: crash with my custom function zen_get_products_model()

    Hmmm, I think this is because the extra_functions folder is for extra functions, and not intended to replace existing functions, so what is happening is that PHP/Zen is trying to load two functions with the same name, and this will always cause a server error.

    Solution#1: Comment out (or rename) the original function.
    Solution#2: Keep your renamed function and update any code that calls the original function.

    Cheers
    Rod

  3. #3
    Join Date
    Oct 2010
    Posts
    27
    Plugin Contributions
    0

    Default Re: crash with my custom function zen_get_products_model()

    Quote Originally Posted by RodG View Post
    Hmmm, I think this is because the extra_functions folder is for extra functions, and not intended to replace existing functions, so what is happening is that PHP/Zen is trying to load two functions with the same name, and this will always cause a server error.

    Solution#1: Comment out (or rename) the original function.
    Solution#2: Keep your renamed function and update any code that calls the original function.

    Cheers
    Rod
    The problem is that

    Code:
        $category = zen_get_products_category_id($id_products); // Works
        $category = zen_get_categories_name($category); // Works
        $name = zen_get_products_name($id_products); // Works
        $model = zen_get_products_model($id_products); //Crash Not Works
    So is just for this one .. zen_get_products_model($id_products)

  4. #4
    Join Date
    Jan 2007
    Location
    Australia
    Posts
    3,946
    Plugin Contributions
    1

    Default Re: crash with my custom function zen_get_products_model()

    Hmm, OK, try this.

    First make sure you've got a backup of your custom zen_get_products_model($id_products) function.

    Next, replace your custom code with a copy of the original function.

    Does it still crash? If so, there is something amiss with your code.
    If not, there is something amiss with the function not being able to work from its new location.

    This may not provide the solution, but it'll narrow down the possible causes.

    Oh. Very important. Do NOT keep backups of files in either of the relevent folders (or if you do, you must ensure they don't have a .php file extension). Such files will also cause a server crash.

    Other than this, I'm pretty much out of ideas as to the next course of action. Possibly attach a debugger and step through the code to find the exact point of failure? (I use Netbeans for this).

    Cheers
    Rod

  5. #5
    Join Date
    Oct 2010
    Posts
    27
    Plugin Contributions
    0

    Default Re: crash with my custom function zen_get_products_model()

    The code is below.

    PHP Code:
    define("IMO_JPG_CHEIE","Products");
    if(
    ENABLE_SSL == 'true'){ define("IMO_MEDIA_URL",HTTPS_SERVER.DIR_WS_HTTPS_CATALOG);}
    else{ 
    define("IMO_MEDIA_URL",HTTP_SERVER.DIR_WS_CATALOG);}

    function 
    imo_load_image($id_products=0,$alt,$atribut="default") {
        
    $category zen_get_products_category_id($id_products);
        
    $category zen_get_categories_name($category);
        
    $name zen_get_products_name($id_products);
        
    $model imo_get_products_model($id_products);
        
    $link IMO_Make_fake_jpg($category,$name,$model,$atribut);

       return 
    sprintf('<img alt="%s" src="%s">',$alt,IMO_MEDIA_URL.IMO_JPG_CHEIE.$link);

    }


    /*
     * Functie responsabila cu conceperea linkului fake pentru poze
     */
    function IMO_Make_fake_jpg($Category="",$Nume="",$Model=""$Atribut="",$term="png") {

        
    $Nume removeCharacters($Nume);
        
    $Category removeCharacters($Category);

        return  
    "/" str_replace(" ","-",$Category) . "/".str_replace(" ","-",$Nume)."_".$Atribut."_".$Model.".".$term;
    }


    function 
    removeCharacters($string) {
        
    $removeCharacters = array("&","?","'",'"',"#",";");
        foreach(
    $removeCharacters as $val) {
            
    $string str_replace($val,"",$string);
        }
        return 
    $string;
    }

    function 
    imo_get_products_model($id_products){
        global 
    $db;

        
    $check $db->Execute("select products_model
                        from " 
    TABLE_PRODUCTS "
                        where products_id='" 
    . (int)$id_products "'");

        return 
    $check->fields['products_model'];

    It still crash. when i using zen_... instead of imo_....
    Because zen-cart don`t come with a easy way to use multiple picture for each attribute i have to port my old implementation from 1.38 to this version and normal to make an upgrade. All the comment are in Romana .. sorry for that.
    When i have time i will test to see where is the problem.

    Because zen-cart is a modular system it must in future version to have a override system for function like zen_image .. or zen_href ...
    Last edited by CaDyMaN; 7 May 2012 at 07:00 PM.

  6. #6

    Default Re: crash with my custom function zen_get_products_model()

    Have you looked in the debug logs of your zencart? There may be something useful to point you in the right direction in there
    http://www.zen-cart.com/content.php?124

  7. #7
    Join Date
    Jan 2007
    Location
    Australia
    Posts
    3,946
    Plugin Contributions
    1

    Default Re: crash with my custom function zen_get_products_model()

    Quote Originally Posted by CaDyMaN View Post

    -----------------------------------------------
    function imo_load_image($id_products=0,$alt,$atribut="default") {
    $category = zen_get_products_category_id($id_products);
    $category = zen_get_categories_name($category);
    $name = zen_get_products_name($id_products);
    $model = $this->imo_get_products_model($id_products);
    $link = IMO_Make_fake_jpg($category,$name,$model,$atribut);

    return sprintf('<img alt="%s" src="%s">',$alt,IMO_MEDIA_URL.IMO_JPG_CHEIE.$link);

    }
    ------------------------------------------------------------------
    See the text I've added above (in red)? Make the same addition to your code. Let me know how it goes. (You may need to add the same to other parts of your code.. I've only tested for the $model variable since that is the one you've reported a problem with).

    BTW, whats the deal with the $category variable? It looks like your setting it to one thing, then immedialty resetting to another.. or was that just to demonstrate that both methods are functional?

    Cheers
    Rod

  8. #8
    Join Date
    Jan 2007
    Location
    Australia
    Posts
    3,946
    Plugin Contributions
    1

    Default Re: crash with my custom function zen_get_products_model()

    Here ya go :)

    PHP Code:
    function IMO_Make_fake_jpg($Category="",$Nume="",$Model=""$Atribut="",$term="png") {

        
    $Nume $this->removeCharacters($Nume);
        
    $Category $this->removeCharacters($Category);

        return  
    "/" str_replace(" ","-",$Category) . "/".str_replace(" ","-",$Nume)."_".$Atribut."_".$Model.".".$term;
    }

    function 
    imo_load_image($id_products=0,$alt,$atribut="default") {
        
    $category zen_get_products_category_id($id_products);
        
    $category zen_get_categories_name($category);
        
    $name zen_get_products_name($id_products);
        
    $model $this->imo_get_products_model($id_products);
        
    $link $this->IMO_Make_fake_jpg($category,$name,$model,$atribut);

       return 
    sprintf('<img alt="%s" src="%s">',$alt,IMO_MEDIA_URL.IMO_JPG_CHEIE.$link);

    }


    function 
    removeCharacters($string) {
        
    $removeCharacters = array("&","?","'",'"',"#",";");
        foreach(
    $removeCharacters as $val) {
            
    $string str_replace($val,"",$string);
        }
        return 
    $string;
    }

    function 
    imo_get_products_model($id_products){
        global 
    $db;

        
    $check $db->Execute("select products_model
                        from " 
    TABLE_PRODUCTS "
                        where products_id='" 
    . (int)$id_products "'");

        return 
    $check->fields['products_model'];

    Cheers
    Rod

    ps. If this works, feel free to buy the zencart dev team (not me) a coffee :)

  9. #9
    Join Date
    Oct 2010
    Posts
    27
    Plugin Contributions
    0

    Default Re: crash with my custom function zen_get_products_model()

    I think you don`t understand

    this code return a blank page

    PHP Code:

    function imo_load_image($id_products=0,$alt,$atribut="default") {
        
    $category zen_get_products_category_id($id_products);
        
    $category zen_get_categories_name($category);
        
    $name zen_get_products_name($id_products);
        
    $model zen_get_products_model($id_products); // if i comment this will work if not .. error
        
    return $category."/".$name."/".$model;
    }

    echo 
    imo_load_image(1); //load image for product with id 1 
    And from what is know $this is used in class methods i don`t use a class ...hmmm

  10. #10
    Join Date
    Jan 2007
    Location
    Australia
    Posts
    3,946
    Plugin Contributions
    1

    Default Re: crash with my custom function zen_get_products_model()

    Quote Originally Posted by CaDyMaN View Post
    I think you don`t understand
    Actually I do (As a result of pasting your code into a suitable part of my test store, getting the same blank page, and then stepping through the code to find the cause and solution.

    Quote Originally Posted by CaDyMaN View Post
    this code return a blank page

    PHP Code:

    function imo_load_image($id_products=0,$alt,$atribut="default") {
        
    $category zen_get_products_category_id($id_products);
        
    $category zen_get_categories_name($category);
        
    $name zen_get_products_name($id_products);
        
    $model zen_get_products_model($id_products); // if i comment this will work if not .. error
        
    return $category."/".$name."/".$model;
    }

    echo 
    imo_load_image(1); //load image for product with id 1 
    Yes, it will. I made one small omission to the update code I provided. Actually it wasn't the code itself, but the way in which you are calling the function (which wasn't in the code that you provided).

    Using the code you've just posted, you just need to change

    echo imo_load_image(1); //load image for product with id 1

    To
    echo $this->imo_load_image(1); //load image for product with id 1

    In other words, *all* calls to your imo_xxxxxx functions need to use the "$this->" syntax.

    Quote Originally Posted by CaDyMaN View Post
    And from what is know $this is used in class methods
    This is true.

    Quote Originally Posted by CaDyMaN View Post
    i don`t use a class ...hmmm
    That's the problem. You are NOT using class methods, but ZenCart *is*. :)

    Cheers
    Rod

 

 
Page 1 of 2 12 LastLast

Similar Threads

  1. Products With Attributes Crash In Shopping Cart - URL rewrites
    By awiss in forum All Other Contributions/Addons
    Replies: 5
    Last Post: 20 Dec 2011, 06:58 PM
  2. Replies: 3
    Last Post: 11 Jan 2011, 02:53 AM
  3. Site crash with express enabled
    By wccomp in forum PayPal Express Checkout support
    Replies: 10
    Last Post: 15 Jul 2007, 11:29 PM
  4. Adding custom function, calling custom code from pages.
    By madteckhead in forum General Questions
    Replies: 6
    Last Post: 14 Jun 2007, 08:24 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •