Advertisement:

Author Topic: Categories/Sub-Category Error in Safari  (Read 1329 times)

ikrougovoi

  • Newbie
  • *
  • Posts: 15
Categories/Sub-Category Error in Safari
« on: March 14, 2014, 07:20:07 am »
Hey guys,

First off, great theme!

I have run into an issue with posting an ad, if a category does not have a subcategory it errors in Safari (works in Chrome).

http://class.mobiletrader.ca/item/new

I'm assuming it's because the PHP renders the following Javascript:
Code: [Select]
            twitter_theme.categories = {} ;
        twitter_theme.categories.id_96 = {
0: { id: 105, slug: "audiovox", name: "Audiovox"} ,
1: { id: 104, slug: "alcatel", name: "ALCATEL"} ,
2: { id: 103, slug: "acer", name: "Acer"} ,
3: { id: 101, slug: "apple", name: "Apple "} ,
4: { id: 102, slug: "blackberry", name: "BlackBerry"} ,
5: { id: 107, slug: "casio", name: "Casio"} ,
6: { id: 106, slug: "benq", name: "BenQ"} ,
7: { id: 108, slug: "dell", name: "Dell"} ,
8: { id: 109, slug: "htc", name: "HTC"} ,
9: { id: 110, slug: "i-mate", name: "i-mate"} ,
10: { id: 111, slug: "lg", name: "LG"} ,
11: { id: 112, slug: "mitsubishi", name: "Mitsubishi"} ,
12: { id: 113, slug: "motorola", name: "Motorola"} ,
13: { id: 114, slug: "nec", name: "NEC"} ,
14: { id: 115, slug: "nokia", name: "Nokia"} ,
15: { id: 116, slug: "palm", name: "Palm"} ,
16: { id: 117, slug: "panasonic", name: "Panasonic"} ,
17: { id: 120, slug: "philips", name: "Philips"} ,
18: { id: 119, slug: "pantech", name: "Pantech"} ,
19: { id: 118, slug: "samsung", name: "Samsung"} ,
20: { id: 121, slug: "sanyo", name: "SANYO"} ,
21: { id: 122, slug: "sharp", name: "Sharp"} ,
22: { id: 123, slug: "siemens", name: "Siemens"} ,
23: { id: 124, slug: "sierra-wireless", name: "Sierra Wireless "} ,
24: { id: 125, slug: "sonim", name: "Sonim"} ,
25: { id: 126, slug: "sony-ericsson", name: "Sony Ericsson "} ,
26: { id: 127, slug: "toshiba", name: "Toshiba"} ,
27: { id: 128, slug: "utstarcom", name: "UTStarcom"} ,
28: { id: 129, slug: "zte", name: "ZTE"} ,
29: { id: 130, slug: "not-specified", name: "Not Specified "}
} ;twitter_theme.categories.phone-accessories = { } ;
twitter_theme.categories.wholesale-lots = { } ;
twitter_theme.categories.replace-parts-tools = { } ;

Notice the last three parent categories are being set to "{ }" so Safari is throwing an error.

Also, it's only going down one subcategory, if anyone can help out with extending this to 3 I would REALLY appreciate it :)

Also Safari is throwing an "undefined" error.
I see that in the check for subcategories the twitter_theme.categories function it is checking if that is returning "undefined", Safari is throwing the following error:
[Error] TypeError: 'undefined' is not an object (evaluating 'twitter_theme.categories["id_" + id]')

ikrougovoi

  • Newbie
  • *
  • Posts: 15
Re: Categories/Sub-Category Error in Safari
« Reply #1 on: March 14, 2014, 07:37:32 am »
UPDATE VERY strange.. I deleted the categories that did not have subcategories, and added them back in. No more error....

EDIT Spoke too soon.. Played around with it for a bit, getting the same error.

Made the following change to functions.php file.. All seems right in the world...
Code: [Select]
    function item_category_select_js() {
        ?>
        <script type="text/javascript">
            twitter_theme.categories = {} ;
        <?php
        $aCategories 
osc_get_categories() ;
        foreach(
$aCategories as $category) {
            if( 
is_array($category['categories']) && (count($category['categories']) > 0) ) {
                echo 
'twitter_theme.categories.id_' $category['pk_i_id'] . ' = {' PHP_EOL ;
                for(
$i 0$i count($category['categories']); $i++) {
                    echo 
$category['categories'][$i]['i_position'] . ': { id: ' $category['categories'][$i]['pk_i_id'] . ', slug: "' addslashes($category['categories'][$i]['s_slug']) . '", name: "' addslashes($category['categories'][$i]['s_name']) . '"' ;
                    if( 
$i == (count($category['categories']) - 1) ) {
                        echo 
'}' PHP_EOL ;
                    } else {
                        echo 
'} ,' PHP_EOL ;
                    }
                }
                echo 
'} ;' PHP_EOL ;
            } else {
                
#COMMENTED THIS LINE OUT!!!!echo 'twitter_theme.categories.' . $category['s_slug'] . ' ;' . PHP_EOL  ;
            
}
        }
        
?>

        </script>
        <?php
    
}
« Last Edit: March 14, 2014, 08:24:53 am by ikrougovoi »

mahesh

  • Full Member
  • ***
  • Posts: 116
Re: Categories/Sub-Category Error in Safari
« Reply #2 on: March 14, 2014, 02:41:56 pm »
Hi ikrougovoi,

By default in osclass we can only post ads in subcategorys only if we want to post the ads in parent category also we need to set the following settings
Go to admin panel -> settings ->General Settings

Check the checkbox under category settings in that page  and save changes

hope this is helpful

ikrougovoi

  • Newbie
  • *
  • Posts: 15
Re: Categories/Sub-Category Error in Safari
« Reply #3 on: March 15, 2014, 02:22:30 am »
Hello mahesh,

Unfortunately that setting was already set. :(

I feel kind of stupid..
The issue is that the s_slug of the category is made "URL Safe" so that you can visit in your browser.
For example "wholesale lots" becomes "wholesale-lots".
JavaScript interprets this as me trying to subtract "wholesale" and "lots".

The fix is to make it render as follows:
twitter_theme.categories['wholesale-lots'] = { } ;

The fix is on line 531 of functions.php:
Code: [Select]
echo "twitter_theme.categories['" . $category["s_slug"] . "'] = {} ;" . PHP_EOL  ;
Thank you for your help mahesh!
« Last Edit: March 15, 2014, 02:47:18 am by ikrougovoi »