Coded something up in Couch in an interesting way? Have a snippet or shortcode to share? Post it here for the community to benefit.
25 posts Page 2 of 3
I would personally implement it with a separate template, but there certainly is no such requirement. We can perform some small modifications so one does not get sent to a different page and optionally display the wishlist on the page-view as well:
Code: Select all
<cms:template title='Products' clonable='1' dynamic_folders='1'/>

<cms:if k_is_page>
   <cms:no_cache/>

   <cms:set cookie_ids="<cms:get_cookie name='wishlist'/>"/>
   <cms:set new_ids=cookie_ids scope='global'/>

   <cms:set add="<cms:gpc 'add' method='get'/>"/>
   <cms:set remove="<cms:gpc 'remove' method='get'/>"/>
   <cms:set get_id="<cms:gpc 'id' method='get'/>" scope='global'/>
   <!-- optional - if you want to display the wishlist --><cms:set current_page_link=k_page_link scope='global'/>

   <cms:if add>
      <cms:set new_ids=get_id scope='global'/>

      <cms:each var=cookie_ids as='id' sep=','>
         <cms:if id != get_id>
            <cms:set new_ids="<cms:show new_ids/>,<cms:show id/>" scope='global'/>
         </cms:if>
      </cms:each>
   </cms:if>

   <cms:if remove>
      <cms:set new_ids='' scope='global'/>

      <cms:each var=cookie_ids as='id' sep=','>
         <cms:if id != get_id>
            <cms:set new_ids="<cms:if new_ids><cms:show new_ids/>,</cms:if><cms:show id/>" scope='global'/>
         </cms:if>
      </cms:each>
   </cms:if>

   <cms:each var=new_ids as='id' sep=','>
      <cms:if id == k_page_id>
         <cms:set is_wishlist='1' scope='global'/>
      </cms:if>

      <!-- optional cms:pages tag - if you want to display the wishlist -->
      <cms:pages id=id limit='1'>
         <a href="<cms:show k_page_link/>"><cms:show k_page_title/></a><br/>
         <a href="<cms:show current_page_link/>?remove=1&amp;id=<cms:show k_page_id/>">Remove</a><br/><br/>
      </cms:pages>
   </cms:each>

   <cms:if new_ids != cookie_ids>
      <cms:set_cookie name='wishlist' value=new_ids expire='0'/>
   </cms:if>

   <br/><br/><a href="<cms:show k_page_link/>"><cms:show k_page_title/></a><br/>
   <cms:if is_wishlist>
      <a href="<cms:show k_page_link/>?remove=1&amp;id=<cms:show k_page_id/>">Remove</a>
   <cms:else/>
      <a href="<cms:show k_page_link/>?add=1&amp;id=<cms:show k_page_id/>">Add</a>
   </cms:if>
</cms:if>
Hi Guys,

Can this be used as an "Add Favourite" instead of wishlist? conceptually its the same but instead of using a cookie we would be saving to a members profile. The use case would for a visitor wanting to save a page to their profile so that they can access it directly.

Basically, it would work as follows.

1. There is a list of pages with a "+" next to each page
2. User clicks the "+" and adds the page to their favourite list
3. When user visits the favourite list, there is the listing of all the pages.
4. On favourites page, user has the option to delete/remove pages

Regards
Said
Yes it would be somewhat similar @said. You could use a relation field for the members template. Do create another topic if you run into any trouble implementing this feature.
@ Cheesypoof, Thanks for the reply, will look at implementing and if there any issues I will post in separate topic

Regards
Said
Hi Said,

I think the answer is here http://www.couchcms.com/forum/viewtopic.php?f=4&t=7971
I load frameworks and write bugs on top of them, after that I rearrange the code so that it looks like a cool product.
Thanks Tomarnst,

I did have a look at that topic and coupled with Cheesypoof's should be able to come up with what I need

Regards
Said
Hi guys, I managed to create shopping bag functionality with the code provided by @cheesypoof on the previous page.

I am wondering is there a way to include product thumbnail image in this cookie variable?
I would need both the product name and the thumbnail to be added to shopping bag.
@madebym
Store only the ids in the wishlist/shopping-bag.
You can, as mentioned by cheesypoof, always use the id to get the full data of the page it represents (e.g. the thumbnail you mentioned) -
Code: Select all
<!-- optional cms:pages tag - if you want to display the wishlist -->
<cms:pages id=id limit='1'>
    ... all editable regions of the page in wishlist available here ..
</cms:pages>
Thanks KK! I missed that part :)
@cheesypoof As I said I managed to implement the shopping bag functionality using the code you provided. It works flawlessly :)

I was just wondering is there a way for user to stay on the same page after adding to shopping bag. Maybe some AJAX like you did for cart items?

I know you provided a modified version of the code in this thread, that keeps the user on the same page, but I am using a separate template to show the shopping bag items, so that code doesn't work in my case. It stays on the same page, but the shopping bag page doesn't get populated, of course, beacuse the href attribute is now pointing to the current page we are on.

Edit:
I tried to solve it like this, but it doesn't work.

Code: Select all
     $('.add-to-design-board').click(function(){
         $.post("<cms:link 'design-board.php'/>?add=1&amp;id=<cms:show k_page_id/>",function(data){
         // I should probably do something here, but not sure what to do :)
     });
    return false;
       })
25 posts Page 2 of 3
cron