The information in this thread might be outdated
If the solution did not help, please, check our Help Portal or contact Ecwid Team.
 
 
Thread Tools Display Modes
  #1  
Old 04-28-2012, 11:13 AM
Ejub Bicic @ejubbicic's Avatar
Ejub Bicic @ejubbicic is offline
 
Join Date: May 2011
Location: Sweden
Posts: 12
Smile

Create custom menu using Ecwid Product API


Hi!

Thought I could share the code I've written to create a custom menu using the API, maybe it can be to some help. You can see the menu live on http://groweco.se

What the code does:
1. The code will first retrieve all the root categories.
2. Then it will fetch the sub categories if they exists.
3. If sub categories exists, the code will get one random product from the parent category, which will be shown together with the sub categories in the drop down sub menu. The product will be presented with product image, link, product title, price and the Add to cart button. Every time you refresh/revisit the site a new random product will be shown for the categories that have a sub menu. For load time reason I have cached my wordpress site, so the random product is refreshed once every day, I suggest you do the same. If you are using Wordpress for your site, install a cache plugin like WP Super Cache.

The categories are retrieved in the order that you have set in your Ecwid Control Panel.

The code:
PHP Code:
<?php
include_once "ecwid_product_api.php";
$api = new EcwidProductApi(YOURSTOREID); // initialize the API class
?>

<div id="meny">
<div id="ecwid-menu">

<?php
//get parent categories using the ID
$categories $api->get_subcategories_by_id($parent_category_id 0);
echo 
'<ul>';

    foreach(
$categories as $category) {
echo 
'<li id="parentitem">';                
echo <<<EOT
<a href='{$category["url"]}' style='float: left; width: auto;'>{$category["name"]}</a>
EOT;

//get sub categories if they exist using category ID from parent categories above
$subcategories $api->get_subcategories_by_id($category["id"]); 

        if (
$subcategories) {
echo 
'<ul id="submenu">';
echo 
'<div id="categorytitle">' $category["name"] . '</div>';

//get one random product from each category that has a subcategory
$categorytips $api->get_products_by_category_id($category["id"]);
shuffle($categorytips);
$i=0;

                foreach(
$categorytips as $categorytip) if ($i 1) {
$produktid $categorytip['id'];
echo <<<EOT
<div id="tips">
<strong>Populärast just nu</strong><br>
<a href="
{$categorytip["url"]}" class="productlink">{$categorytip["name"]}<br>
<img src="
{$categorytip["thumbnailUrl"]}"></a><br>
{$categorytip["price"]} SEK<br>
<script type="text/javascript">xAddToBag('productid=
$produktid');</script>
</div>
EOT;
$i +=1;
                }

            foreach(
$subcategories as $subcategory) {                        
echo <<<EOT
<li id="subitem"><a href='{$subcategory["url"]}'>{$subcategory["name"]}</a></li>
EOT;
            }

echo 
'</ul>';
        }

echo 
'</li>';
    }

echo 
'</ul>';
?>

</div>
</div>
Don't forget to change YOURSTOREID with your store ID.

The final result:

Last edited by Ejub Bicic @ejubbicic; 05-12-2012 at 05:24 PM. Reason: Removed my storeID from the code snippet.
The Following 6 Users Say Thank You to Ejub Bicic @ejubbicic For This Useful Post:
Eugene Rimmer (04-30-2012), Kess (05-01-2012), Comic Hunter (05-12-2012), Maya (06-05-2012), swift (07-17-2012), Rick G (03-06-2015)
  #2  
Old 04-29-2012, 07:02 PM
alfalfa's Avatar
alfalfa alfalfa is offline
 
Join Date: Feb 2012
Posts: 16
Default

OUha I'm going to look at it

Thanks man for the source!
The Following User Says Thank You to alfalfa For This Useful Post:
Diane Benzie1 (09-30-2013)
  #3  
Old 05-12-2012, 04:46 PM
Comic Hunter's Avatar
Comic Hunter Comic Hunter is offline
 
Join Date: Apr 2011
Posts: 19
Default

Thanks a ton for posting this. Would be great if more people posted snippets like this. It goes a long way to helping noobs such as myself get started.
  #4  
Old 06-02-2012, 08:30 AM
Ban Bee's Avatar
Ban Bee Ban Bee is offline
Junior Member
 
Join Date: Jun 2012
Posts: 1
Default

Thanks for the source man!

But I'm still kind of new to ecwid, can you share the steps of how did you successfully created this result on your website? Like where should we put this source codes you had provided?

So sorry for the trouble Cheers
  #5  
Old 06-02-2012, 09:29 PM
Comic Hunter's Avatar
Comic Hunter Comic Hunter is offline
 
Join Date: Apr 2011
Posts: 19
Default

It has a lot less to do with ecwid and a lot more to do with programming in general.
  #6  
Old 07-13-2012, 05:05 PM
scv reef's Avatar
scv reef scv reef is offline
Junior Member
 
Join Date: Mar 2012
Posts: 3
Default

Do I edit and plug in here or design CSS?


ecwid-shopping-cart/lib/JSON.php
ecwid-shopping-cart/lib/ecwid_catalog.php
ecwid-shopping-cart/lib/ecwid_product_api.php
  #7  
Old 07-16-2012, 03:50 PM
Eugene Rimmer's Avatar
Eugene Rimmer Eugene Rimmer is offline
Senior Member
 
Join Date: Jan 2011
Location: Ecwid headquarters
Posts: 7,765
Default

Quote:
Originally Posted by scv reef View Post
Do I edit and plug in here or design CSS?


ecwid-shopping-cart/lib/JSON.php
ecwid-shopping-cart/lib/ecwid_catalog.php
ecwid-shopping-cart/lib/ecwid_product_api.php
What are you trying to achieve?
  #8  
Old 07-16-2012, 05:14 PM
scv reef's Avatar
scv reef scv reef is offline
Junior Member
 
Join Date: Mar 2012
Posts: 3
Default

Would like to get the second level categories and third categories to pop up when you hoover over the first category then drop down and to the right.
example http://lllreptile.com/

Thanks

Rob
  #9  
Old 07-16-2012, 05:28 PM
Guitar Hangar's Avatar
Guitar Hangar Guitar Hangar is offline
Junior Member
 
Join Date: Jul 2012
Posts: 4
Default

I'm using wordpress, where would I apply this code to get that result/
  #10  
Old 07-17-2012, 11:17 AM
Maya's Avatar
Maya Maya is offline
Ecwid Team
 
Join Date: Feb 2010
Location: Ecwid headquarter
Posts: 5,876
Default

Quote:
Originally Posted by Guitar Hangar View Post
I'm using wordpress, where would I apply this code to get that result/
You should add this code into the source of your Wordpress template, where categories menu should be shown. You can find the source of your templates in WP Admin.
__________________
Maya N., Ecwid Team

------------------
Welcome to our new Help Center!
The Following User Says Thank You to Maya For This Useful Post:
Vinod Yadav (06-05-2013)
 
The information in this thread might be outdated
If the solution did not help, please, check our Help Portal or contact Ecwid Team.

Tags
api code, tips

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT. The time now is 11:50 AM.
Powered by vBulletin® Version 3.8.11. Copyright ©2000 - 2021, Jelsoft Enterprises Ltd.