Exemplo n.º 1
0
 public function getProducts($currentProductId)
 {
     $result = array();
     $api = new EcwidProductApi(self::$storeId);
     $product = $api->get_product($currentProductId);
     if (!isset($product["categories"])) {
         return $result;
     }
     // find "Related" category
     $categoryId = null;
     foreach ($product["categories"] as $category) {
         if (strpos($category["name"], self::RELATED_PEFIX) === 0) {
             $categoryId = $category["id"];
             break;
         }
     }
     if ($categoryId === null) {
         return $result;
     }
     // get products data
     $products = $api->get_products_by_category_id($categoryId);
     if (!$products) {
         return $result;
     }
     // exclude current product
     foreach ($products as $i => $product) {
         if ($product["id"] == $currentProductId) {
             unset($products[$i]);
             break;
         }
     }
     // get detail info for products
     $params = array();
     foreach ($products as $i => $product) {
         $params[$i] = array("alias" => "p" . $i, "action" => "product", "params" => array("id" => $product["id"]));
     }
     $batchResult = $api->get_batch_request($params);
     if (!$batchResult) {
         return $result;
     }
     // find real category (for real url to related product)
     foreach ($products as $i => $product) {
         $res = $batchResult["p" . $i];
         $realCategory = null;
         foreach ($res["categories"] as $category) {
             if (strpos($category["name"], self::RELATED_PEFIX) !== 0) {
                 $realCategory = $category;
                 break;
             }
         }
         $products[$i]["realCategory"] = $realCategory;
         $products[$i]["details"] = $res;
         $products[$i]["siteProductUrl"] = self::getProductUrl($products[$i]);
     }
     $result = $products;
     return $result;
 }
function ecwid_is_api_enabled($ecwid_store_id)
{
    $ecwid_store_id = intval($ecwid_store_id);
    $api = new EcwidProductApi($ecwid_store_id);
    return $api->is_api_enabled();
}
function ecwid_options_do_page()
{
    $store_id = get_ecwid_store_id();
    $ecwid_enable_minicart = get_option('ecwid_enable_minicart');
    $ecwid_show_categories = get_option('ecwid_show_categories');
    $ecwid_show_search_box = get_option('ecwid_show_search_box');
    $ecwid_pb_categoriesperrow = get_option('ecwid_pb_categoriesperrow');
    $ecwid_pb_productspercolumn_grid = get_option('ecwid_pb_productspercolumn_grid');
    $ecwid_pb_productsperrow_grid = get_option('ecwid_pb_productsperrow_grid');
    $ecwid_pb_productsperpage_list = get_option('ecwid_pb_productsperpage_list');
    $ecwid_pb_productsperpage_table = get_option('ecwid_pb_productsperpage_table');
    $ecwid_pb_defaultview = get_option('ecwid_pb_defaultview');
    $ecwid_pb_searchview = get_option('ecwid_pb_searchview');
    $ecwid_mobile_catalog_link = get_option('ecwid_mobile_catalog_link');
    $ecwid_default_category_id = get_option('ecwid_default_category_id');
    $ecwid_noscript_seo_catalog = get_option('ecwid_noscript_seo_catalog');
    $ecwid_enable_ssl = get_option('ecwid_enable_ssl');
    $ecwid_page_id = get_option("ecwid_store_page_id");
    $ecwid_sso_secret_key = get_option("ecwid_sso_secret_key");
    $ecwid_noscript_seo_catalog_disabled = false;
    $ecwid_noscript_seo_catalog_message = '<a href="http://kb.ecwid.com/Inline-SEO-Catalog" target="_blank">How it works</a>';
    $ecwid_settings_message = false;
    if ($store_id == 1003) {
        $ecwid_noscript_seo_catalog_disabled = true;
        $ecwid_noscript_seo_catalog_message = 'This option requires using Ecwid Product API. In order to enable it, please set up your Store ID first. Please note, that API is available for the <a href="http://www.ecwid.com/compare-plans.html" target="_blank">paid Ecwid accounts</a> only.';
        if (!empty($ecwid_noscript_seo_catalog)) {
            update_option('ecwid_noscript_seo_catalog', '');
            $ecwid_noscript_seo_catalog = '';
        }
    } else {
        if ($store_id != 1003 && empty($ecwid_noscript_seo_catalog)) {
            $ecwid_noscript_seo_catalog_message = '<a href="http://kb.ecwid.com/Inline-SEO-Catalog" target="_blank">How Inline Seo Catalog works</a>. This option requires using Ecwid API which is available for the <a href="http://www.ecwid.com/compare-plans.html" target="_blank">paid accounts</a> only.';
        } else {
            if ($store_id != 1003 && !empty($ecwid_noscript_seo_catalog)) {
                include_once ABSPATH . 'wp-content/plugins/ecwid-shopping-cart/lib/ecwid_product_api.php';
                $api = new EcwidProductApi($store_id);
                if (!empty($api)) {
                    $store_profile = $api->get_profile();
                    if ($api->error_code == 403) {
                        #free account, consider upgrade
                        $ecwid_noscript_seo_catalog_disabled = true;
                        $ecwid_noscript_seo_catalog_message = 'This option requires using Ecwid API which is available for the <a href="http://www.ecwid.com/compare-plans.html" target="_blank">paid accounts</a> only. Please consider upgrading your account to use it.';
                        update_option('ecwid_noscript_seo_catalog', '');
                        $ecwid_noscript_seo_catalog = '';
                        $ecwid_settings_message = 'The "Inline HTML catalog" option requires using Ecwid API which is available for the <a href="http://www.ecwid.com/compare-plans.html" target="_blank">paid accounts</a> only. Please consider upgrading your account to use it.';
                    } else {
                        if ($api->error_code == 404) {
                            $ecwid_noscript_seo_catalog_message = 'We cannot connect to Ecwid servers using your Store ID. Is it correct?';
                            $ecwid_settings_message = 'We cannot connect to Ecwid servers using your Store ID. Is it correct?';
                        } else {
                            if ($api->error_code != '') {
                                $ecwid_noscript_seo_catalog_message = 'Connection to Ecwid servers failed. Error code: ' . $api->error_code;
                                $ecwid_settings_message = 'Connection to Ecwid servers failed. Error code: ' . $api->error_code;
                                if ($api->error_code == 0) {
                                    $ecwid_noscript_seo_catalog_message .= '&nbsp;' . $api->error;
                                    $ecwid_settings_message .= '&nbsp;' . $api->error;
                                }
                            }
                        }
                    }
                } else {
                    $ecwid_settings_message = 'We cannot include some essential files of Ecwid Shopping Cart module. It looks like it\'s corrupted. Try to re-install the module and contact Ecwid Team if it doesn\'t help.';
                }
            }
        }
    }
    $_tmp_page = null;
    $disabled = false;
    if (!empty($ecwid_page_id) and $ecwid_page_id > 0) {
        $_tmp_page = get_page($ecwid_page_id);
        $content = $_tmp_page->post_content;
        if (strpos($content, "[ecwid_productbrowser]") === false && strpos($content, "xProductBrowser") !== false) {
            $disabled = true;
        }
    }
    if ($disabled) {
        $disabled_str = 'disabled = "disabled"';
    } else {
        $disabled_str = "";
    }
    ?>
    <div class="wrap">
    		<?php 
    if ($ecwid_settings_message) {
        echo "<div id='' class='updated fade'><p><strong>Error.</strong>&nbsp;{$ecwid_settings_message}</p></div>";
    }
    ?>
        <h2>Ecwid settings</h2>
        <form method="post" action="options.php">
            <?php 
    settings_fields('ecwid_options_page');
    ?>
            <table class="form-table">
            <tr><th colspan="2" style="padding:0px;margin:0px;"><h3 style="padding:0px;margin:0px;">General</h3></th></tr>
                            <tr><th scope="row"><a href="http://kb.ecwid.com/Instruction-on-how-to-get-your-free-Store-ID-(for-WordPress)" target="_blank">Store ID</a></th>
                    <td><input type="text" name="ecwid_store_id" value="<?php 
    if ($store_id != 1003) {
        echo $store_id;
    }
    ?>
" />
                    <?php 
    if ($store_id == 1003) {
        echo '&nbsp;&nbsp;&nbsp;&nbsp;<img src="//www.ecwid.com/wp-content/uploads/ecwid_wp_attention.gif" alt="">&nbsp;The Store ID isn\'t set up. Please enter your Store ID to assign your site with your Ecwid store and show your products. <a href="http://kb.ecwid.com/Instruction-on-how-to-get-your-free-Store-ID-(for-WordPress)" target="_blank">How to get this free ID</a>.';
    }
    ?>
                    </td>
		    </tr>
		        <tr><th scope="row">
    <label for="ecwid_show_categories">Show horizontal categories?</label> </th>
    <td><input type="checkbox" id="ecwid_show_categories" name="ecwid_show_categories" <?php 
    if (!empty($ecwid_show_categories)) {
        echo "checked=\"checked\"";
    }
    echo $disabled_str;
    ?>
 />
</td>
            </tr>
    <tr><th scope="row">
    <label for="ecwid_show_search_box">Show search box?</label> </th>
        <td><input type="checkbox" id="ecwid_show_search_box" name="ecwid_show_search_box" <?php 
    if (!empty($ecwid_show_search_box)) {
        echo "checked=\"checked\"";
    }
    ?>
 <?php 
    echo $disabled_str;
    ?>
 />
</td>
            </tr>
         
    <tr><th scope="row">
<label for="ecwid_enable_minicart">Enable minicart attached to horizontal categories?</label></th>
    <td><input type="checkbox" name="ecwid_enable_minicart" id="ecwid_enable_minicart" <?php 
    if (!empty($ecwid_enable_minicart) && !empty($ecwid_show_categories)) {
        echo "checked=\"checked\"";
    }
    ?>
 
<?php 
    if (empty($ecwid_show_categories)) {
        echo 'disabled = "disabled"';
    } else {
        echo $disabled_str;
    }
    ?>
 />
&nbsp;&nbsp;&nbsp;&nbsp;<img src="//www.ecwid.com/wp-content/uploads/ecwid_wp_attention.gif" alt="">&nbsp;If you added minicart to your blog's sidebar, please disable this option.

</td>
            </tr>

	
            <tr><th colspan="2" style="padding:0px;margin:0px;"><h3 style="padding:0px;margin:0px;">Appearance</h3></th></tr>

                            <tr><th scope="row"><label for="ecwid_pb_categoriesperrow">Categories per row</label></th>
                            <td><input type="text" id="ecwid_pb_categoriesperrow" name="ecwid_pb_categoriesperrow" value="<?php 
    echo $ecwid_pb_categoriesperrow;
    ?>
" <?php 
    echo $disabled_str;
    ?>
 /></td>
            </tr>

                            <tr><th scope="row"><label for="ecwid_pb_productspercolumn_grid">Products per column in grid mode</th>
                            <td><input type="text" id="ecwid_pb_productspercolumn_grid" name="ecwid_pb_productspercolumn_grid" value="<?php 
    echo $ecwid_pb_productspercolumn_grid;
    ?>
" <?php 
    echo $disabled_str;
    ?>
 /></td>
            </tr>                            
            
            <tr><th scope="row"><label for="ecwid_pb_productsperrow_grid">Products per row in grid mode</label></th>
                            <td><input type="text" id="ecwid_pb_productsperrow_grid" name="ecwid_pb_productsperrow_grid" value="<?php 
    echo $ecwid_pb_productsperrow_grid;
    ?>
" <?php 
    echo $disabled_str;
    ?>
 /></td>
            </tr>                        

    <tr><th scope="row"><label for="ecwid_pb_productsperpage_list">Products per page in list mode</label></th>
                            <td><input type="text" id="ecwid_pb_productsperpage_list" name="ecwid_pb_productsperpage_list" value="<?php 
    echo $ecwid_pb_productsperpage_list;
    ?>
" <?php 
    echo $disabled_str;
    ?>
 /></td>
            </tr>

                            <tr><th scope="row"><label for="ecwid_pb_productsperpage_table">Products per page in table mode</label></th>
                            <td><input type="text" id="ecwid_pb_productsperpage_table" name="ecwid_pb_productsperpage_table" value="<?php 
    echo $ecwid_pb_productsperpage_table;
    ?>
" <?php 
    echo $disabled_str;
    ?>
 /></td>
            </tr>


                            <tr><th scope="row"><label for="ecwid_pb_defaultview">Default view mode on product pages</label></th>
                            <td>
				<select id="ecwid_pb_defaultview" name="ecwid_pb_defaultview" <?php 
    echo $disabled_str;
    ?>
 >
					<option value="grid" <?php 
    if ($ecwid_pb_defaultview == 'grid') {
        echo 'selected="selected"';
    }
    ?>
 >Grid mode</option>
					<option value="list" <?php 
    if ($ecwid_pb_defaultview == 'list') {
        echo 'selected="selected"';
    }
    ?>
 >List mode</option>
					<option value="table" <?php 
    if ($ecwid_pb_defaultview == 'table') {
        echo 'selected="selected"';
    }
    ?>
 >Table mode</option>
				</select>
</td>
            </tr>

                            <tr><th scope="row"><label for="ecwid_pb_searchview">Default view mode on search results</label></th>
                            <td>
				<select id="ecwid_pb_searchview" name="ecwid_pb_searchview" <?php 
    echo $disabled_str;
    ?>
 >
					<option value="grid" <?php 
    if ($ecwid_pb_searchview == 'grid') {
        echo 'selected="selected"';
    }
    ?>
 >Grid mode</option>
					<option value="list" <?php 
    if ($ecwid_pb_searchview == 'list') {
        echo 'selected="selected"';
    }
    ?>
 >List mode</option>
					<option value="table" <?php 
    if ($ecwid_pb_searchview == 'table') {
        echo 'selected="selected"';
    }
    ?>
 >Table mode</option>
				</select>
</td>
            </tr>
	

         <tr><th colspan="2" style="padding:0px;margin:0px;"><h3 style="padding:0px;margin:0px;">SEO</h3></th></tr>

                <tr><th scope="row"><label for="ecwid_noscript_seo_catalog">
Enable the inline plain-HTML catalog(better SEO)</label>
</th>
    <td><input id="ecwid_noscript_seo_catalog" type="checkbox" name="ecwid_noscript_seo_catalog" <?php 
    if (!empty($ecwid_noscript_seo_catalog)) {
        echo "checked=\"checked\"";
    }
    if (!empty($ecwid_noscript_seo_catalog_disabled)) {
        echo "disabled=\"disabled\"";
    }
    ?>
 />
&nbsp;&nbsp;&nbsp;&nbsp;<img src="//www.ecwid.com/wp-content/uploads/ecwid_wp_attention.gif" alt="">&nbsp; <?php 
    echo $ecwid_noscript_seo_catalog_message;
    ?>

</td>            </tr>    
                                      <tr><th scope="row"><label for="ecwid_mobile_catalog_link">
Full link to your mobile catalog</label>
</th>
    <td><input id="ecwid_mobile_catalog_link" type="text" name="ecwid_mobile_catalog_link" value="<?php 
    echo $ecwid_mobile_catalog_link;
    ?>
" />
&nbsp;&nbsp;&nbsp;&nbsp;<img src="//www.ecwid.com/wp-content/uploads/ecwid_wp_attention.gif" alt="">&nbsp;For example <em>http://mdemo.ecwid.com</em>.&nbsp;<a href="http://kb.ecwid.com/Mobile-Catalog" target="_blank">Information about Ecwid and mobile catalogs.</a>

</td>            </tr>
            
                        <tr><th colspan="2" style="padding:0px;margin:0px;"><h3 style="padding:0px;margin:0px;">Advanced</h3></th></tr>       
                <tr><th scope="row"><label for="ecwid_enable_ssl">
Single Sign-on Secret Key: </label>
</th>
    <td>
<table>
<tr>
<td style="padding-top:0;padding-left:0;vertical-align:top;">
<input id="ecwid_sso_secret_key" type="text" name="ecwid_sso_secret_key" value="<?php 
    echo $ecwid_sso_secret_key;
    ?>
" />
</td>
<td style="padding:0;vertical-align:top;">
<img src="//www.ecwid.com/wp-content/uploads/ecwid_wp_attention.gif" alt="">&nbsp;This feature allows your customers to sign into your WordPress site and fully use your store without having to sign into Ecwid. I.e. if a customer is logged in to your site, he/she is logged in to your store automatically, even if he/she didn't have an account in your store before. In order to enable this feature you should set the secret key that can be found on the "System Settings > API > Single Sign-on API" page in your Ecwid control panel. Please note that this API is available only to <a href="http://www.ecwid.com/compare-plans.html">paid users</a>.
</td>
</tr>
</table>

</td>            </tr>

 
                <tr><th scope="row"><label for="ecwid_enable_ssl">
Enable the following option, if you use Ecwid on a secure HTTPS page</label>
</th>
    <td><input id="ecwid_enable_ssl" type="checkbox" name="ecwid_enable_ssl" <?php 
    if (!empty($ecwid_enable_ssl)) {
        echo "checked=\"checked\"";
    }
    ?>
 />
&nbsp;&nbsp;&nbsp;&nbsp;<img src="//www.ecwid.com/wp-content/uploads/ecwid_wp_attention.gif" alt="">&nbsp;<a href="http://kb.ecwid.com/SSL-HTTPS" target="_blank">Information about Ecwid and SSL/HTTPS</a>

</td>            </tr>
            
           
                           <tr><th scope="row"><label for="ecwid_default_category_id">
Default category ID</label>
</th>
    <td><input id="ecwid_default_category_id" type="text" name="ecwid_default_category_id" value="<?php 
    echo $ecwid_default_category_id;
    ?>
"/>
&nbsp;&nbsp;&nbsp;&nbsp;<img src="//www.ecwid.com/wp-content/uploads/ecwid_wp_attention.gif" alt="">&nbsp;<a href="http://kb.ecwid.com/Default-category-for-product-browser" target="_blank">What is it?</a>

</td>            </tr>
           
            
            </table>
            <p class="submit">
            <input type="submit" class="button-primary" value="<?php 
    _e('Save Changes');
    ?>
" />
            </p>

    <style>
        ul#ecwid-instruction-ul li, ul#ecwid-need-manual-editing-ul li {
            padding-bottom:10px;
        }
    </style> 


<?php 
    if ($disabled) {
        ?>

<div id="ecwid-need-manual-editing" >
</div> 


<?php 
    }
    ?>

<?php 
    if ($store_id == '1003') {
        ?>
    <div id="ecwid-instruction" >
<h4>Instruction on how to get your free Store ID</h4>
<ul style="padding-left:30px;list-style-type:disc;" id="ecwid-instruction-ul">
    <li>Go to the <a target="_blank" href="https://my.ecwid.com/cp/#register">Ecwid control panel</a>. Open this URL: <a target="_blank" href="https://my.ecwid.com/cp/#register">https://my.ecwid.com/cp/#register</a>. You will get to 'Sign In or Register' form.</li>
    <li>Register an account at Ecwid. Use section &quot;Using Ecwid account&quot; for that. The registration is free.
    <p>Or you can log in using your account at Gmail, Facebook, Twitter, Yahoo, or another provider. Choose one from the list of the providers (click on 'More providers' if you don't see your provider there). Click on the provider logo, you will be redirected to the account login page. Submit your username/password there to login to your Ecwid.</p>
    <p>Note: the login might take several seconds. Please, be patient.</p>
    </li>
    <li>Look at the right bottom corner of the page.</li>
    <li>You will see the&nbsp;<span style="background-color:#d3e9e9;">&quot;Store ID: <strong>NNNNNN</strong>&quot;</span> text, where <strong>NNNNNN</strong> is your <strong>Store ID</strong>.<br />
    <p>For example if the text is&nbsp;<span style="background-color:#d3e9e9;">Store ID:</span> <strong><span style="background-color:#d3e9e9;">1003</span></strong>, your Store ID is <strong>1003</strong>. &nbsp;</p><br />
    You will also get your Store ID by email.
    </li>
</ul>
<p>If you have any questions, feel free to ask them on <a href="http://www.ecwid.com/forums/">Ecwid forums</a> or <a href="http://www.ecwid.com/contact-us.html">contact Ecwid team</a>.</p>
 </div>
 <?php 
    }
    ?>
        </form>



    </div>
    <?php 
}
function ecwid_is_api_enabled($ecwid_store_id)
{
    include_once "ecwid_product_api.php";
    $ecwid_store_id = intval($ecwid_store_id);
    $api = new EcwidProductApi($ecwid_store_id);
    return $api->is_api_enabled();
}
    //Required: storeid parameter
    if (!isset($_GET['storeid'])) {
        echo "Failed - you must pass a storeID at the end of the url";
        exit;
    }
    if (!is_numeric($_GET['storeid'])) {
        echo "ERROR: storeid may only be a number.";
        exit;
    }
    $storeid = $_GET['storeid'];
}
//Optional: menudelim (1 character) parameter, default ">"
//Optional: filedelim (1 character) parameter, default ","
//Ex1: ecwid_export_categories.php?storeid=123&menudelim=/&filedelim=;
include 'ecwid_product_api.php';
$api = new EcwidProductApi($_GET['storeid']);
$categories = $api->get_all_categories();
function escape_csv_value($value)
{
    $value = str_replace('"', '""', $value);
    // First off escape all " and make them ""
    if (preg_match('/,/', $value) or preg_match("/\n/", $value) or preg_match('/"/', $value)) {
        return '"' . $value . '"';
        // If I have new lines or commas escape them
    } else {
        return $value;
        // If no new lines or commas just return the value
    }
}
//Build Breadcrumb Description Array
$breadcrumbs = '';