LemonStand Forum: Integrating output of Partials into views in other applications (XML) - LemonStand Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

Integrating output of Partials into views in other applications (XML)

#1 User is offline   nickdunn 

  • Member
  • Group: Members
  • Posts: 3
  • Joined: 11-January 10

Posted 17 January 2010 - 01:37 PM

A hypothetical question, since Lemonstand looks perfect for an upcoming project in a few months.

I will be building a site using Symphony CMS (XSLT-based) which will have an online store attached (Lemonstand). I'm imagining Lemonstand to sit at /shop/ and for the Symphony build to be in the root. However across the *entire* site I'm going to want the user's login status and mini cart in the header.

In playing around I can easily create a simple Page, with a Template that contains some container XML, that includes the shop:mini_cart Partial. Sweet! I can call this via Symphony CMS and include it in my page.

Not so sweet is that this will probably be called with a file_get_contents. Which loses all session context, since the file_get_contents or cURL will not pass the session across.

Can you think of a solution to enable me to get this basic information via a URL spitting out XML into Views of another application (whether it be a Symphony CMS site, or a Zend MVC site, or a RoR app), while maintaining session context?

Would I need to simply pass "phpsessionid=" in the URL to my Lemonstand page when getting the HTML?

This post has been edited by nickdunn: 17 January 2010 - 01:39 PM

0

#2 User is offline   Aleksey 

  • Co-Founder
  • Group: +Administrators
  • Posts: 3,626
  • Joined: 31-October 09

Posted 17 January 2010 - 03:38 PM

Hi, nickdunn!

Thank you for a good question. There was no way to pass the authentication information via URL to LemonStand, but I just added it. It will be possible to build a website which you described.

You will need to build a simple page in LemonStand which will contain only a mini cart and the login information (perhaps, 2 pages). Then you can render the mini cart inside your website by accessing a corresponding URL using the file_get_contents or cURL in the following way:

file_get_contents('http://my_domain/shop/mini_cart?ls_frontend_ticket='.$ticket_value);


To obtain the $ticket_value variable value you will need to read a cookie with the 'eCommerce' name (the cookie name is configurable in LemonStand):

file_get_contents('http://my_domain/shop/mini_cart?ls_frontend_ticket='.$_COOKIE['eCommerce']);


(you will also need to check whether the cookie with the 'eCommerce' name is presented in the $_COOKIE arrray)

This feature is not published yet, but it will be published very soon.

Aleksey

#3 User is offline   nickdunn 

  • Member
  • Group: Members
  • Posts: 3
  • Joined: 11-January 10

Posted 19 January 2010 - 03:39 AM

Bravo! This is exactly what I was after. Thank you Aleksey :-)

I'm one step closer to choosing Lemonstand. The technical build for the project won't start until April, but we're hoping to choose the platform by early March so I'm hoping Lemonstand will be out of beta by then. Is there an ETA?
0

#4 User is offline   Aleksey 

  • Co-Founder
  • Group: +Administrators
  • Posts: 3,626
  • Joined: 31-October 09

Posted 19 January 2010 - 03:51 AM

Quote

But we're hoping to choose the platform by early March so I'm hoping Lemonstand will be out of beta by then. Is there an ETA?


We have no ETA at the moment, but we can consider your (and similar) cases individually and provide the release license before we launch the public release. I believe that we will have all planed features implemented by the end of February.

Thank you! :-)

#5 User is offline   PowderSeeker 

  • Member
  • Group: Members
  • Posts: 20
  • Joined: 12-November 10
  • LocationStow, MA

Posted 12 November 2010 - 09:52 PM

The following is a bit of an older post. I don't see anything in the online doc about this. Did this feature get released, or is there something similar I can use to get a "header fragment" across php apps within a site?

Thanks!

-PowderSeeker

Quote

Hi, nickdunn!

Thank you for a good question. There was no way to pass the authentication information via URL to LemonStand, but I just added it. It will be possible to build a website which you described.

You will need to build a simple page in LemonStand which will contain only a mini cart and the login information (perhaps, 2 pages). Then you can render the mini cart inside your website by accessing a corresponding URL using the file_get_contents or cURL in the following way:

file_get_contents('http://my_domain/shop/mini_cart?ls_frontend_ticket='.$ticket_value);


To obtain the $ticket_value variable value you will need to read a cookie with the 'eCommerce' name (the cookie name is configurable in LemonStand):

file_get_contents('http://my_domain/shop/mini_cart?ls_frontend_ticket='.$_COOKIE['eCommerce']);


(you will also need to check whether the cookie with the 'eCommerce' name is presented in the $_COOKIE arrray)

This feature is not published yet, but it will be published very soon.

Aleksey

0

#6 User is offline   Aleksey 

  • Co-Founder
  • Group: +Administrators
  • Posts: 3,626
  • Joined: 31-October 09

Posted 12 November 2010 - 11:02 PM

Hi, PowderSeeker!

You wrote "within a site". Do you meant that the both application will run in a single domain/subdomain? Cookies are domain-specific, and if the both applications run in a single domain, you should not take any additional measures for passing cookie information between applications.

The ls_frontend_ticket feature is published already. It is a low level stuff, so it is not added to the documentation yet. You can try it and check whether it works.

Thank you

#7 User is offline   Eric 

  • Developer
  • PipPipPip
  • Group: Members
  • Posts: 1,290
  • Joined: 04-August 10
  • LocationVancouver, Canada

Posted 12 November 2010 - 11:18 PM

Hi,

I'm also going to mention that you should also be able to use the JS frontend to send an AJAX request to a LS sub-directory to get partials such as shop:mini_cart.
0

#8 User is offline   PowderSeeker 

  • Member
  • Group: Members
  • Posts: 20
  • Joined: 12-November 10
  • LocationStow, MA

Posted 13 November 2010 - 04:35 AM

Quote

Hi, PowderSeeker!

You wrote "within a site". Do you meant that the both application will run in a single domain/subdomain? Cookies are domain-specific, and if the both applications run in a single domain, you should not take any additional measures for passing cookie information between applications.

The ls_frontend_ticket feature is published already. It is a low level stuff, so it is not added to the documentation yet. You can try it and check whether it works.

Thank you


Yes, I have a site that will use wordpress and LS together, so cross domain is not an issue (it will be on the same server/subdomain). I want to implement a unified header across all pages which can show logged in/out and cart status for guest/logged in users. I'll try some things later today...

Thanks for a quick response. I appreciate that.

-PowerSeeker
0

#9 User is offline   PowderSeeker 

  • Member
  • Group: Members
  • Posts: 20
  • Joined: 12-November 10
  • LocationStow, MA

Posted 13 November 2010 - 01:10 PM

OK, so I got most of this working today. I have created a partial and template which can be called as it's own url e.g.

http://mysite.com/shop/external-header

The weird thing I can't sort out now is that this partial works great in LS, but when called via file_get_contents(http://mysite.com/store/external-heade) will always act as if the cart is empty.

Any idea why this is happening?

The page does: $this->render_partial('basket_header')

The template does: $this->render_page()

And the partial looks like:

<p class="cart-extra"><a href="/store/cart" class="cart-extra cart" title="Shopping Basket">
  <p>Hello <?= $customer = $this->customer;
    if($customer)
      h($customer->name);
    else
      echo "Guest";
    ?>, you have </p>
  <? $active_items = Shop_Cart::list_active_items(); ?>
  <? if ($active_items): ?>
    <p class="mini_cart" id="mini_cart"><?= Shop_Cart::get_item_total_num() ?> item(s) in your basket.</p>
<img class="cart-extra" src="/store/resources/images/full_basket64.png" />
  <? endif ?>
  <? if (!$active_items): ?>
  <p class="mini_cart" id="mini_cart">(0) items in your basket.</p>
<img class="cart-extra" src="/store/resources/images/empty_basket64.png" />
  <? endif ?>
</a>
</p>



TIA.

-PowderSeeker
0

#10 User is offline   Eric 

  • Developer
  • PipPipPip
  • Group: Members
  • Posts: 1,290
  • Joined: 04-August 10
  • LocationVancouver, Canada

Posted 13 November 2010 - 01:46 PM

Hi PowderSeeker,

Have you tried ls_frontend_ticker, posted above?
0

#11 User is offline   mweichert 

  • Member
  • Group: Members
  • Posts: 23
  • Joined: 20-September 10

Posted 14 November 2010 - 06:44 AM

Very cool!

Quote

Hi, PowderSeeker!

You wrote "within a site". Do you meant that the both application will run in a single domain/subdomain? Cookies are domain-specific, and if the both applications run in a single domain, you should not take any additional measures for passing cookie information between applications.

The ls_frontend_ticket feature is published already. It is a low level stuff, so it is not added to the documentation yet. You can try it and check whether it works.

Thank you

0

#12 User is offline   PowderSeeker 

  • Member
  • Group: Members
  • Posts: 20
  • Joined: 12-November 10
  • LocationStow, MA

Posted 14 November 2010 - 08:02 PM

Quote

Hi PowderSeeker,

Have you tried ls_frontend_ticker, posted above?


Eric,

I can't see any cookie with the name of eCommerce (and can't tell where that's configured in LS). When I dump $_COOKIE after I put things in a cart I only see PHPSESSID and PHPROAD. I have tried the following and none of these work:

- ?ls_frontend_ticket='.$_COOKIE['PHPSESSID']
- ?ls_frontend_ticket='.$_COOKIE['eCommerce']
- ?ls_frontend_ticket='.$_COOKIE['PHPROAD']

I can provide some urls if that might help.

Thx.

-PowderSeeker
0

#13 User is offline   Aleksey 

  • Co-Founder
  • Group: +Administrators
  • Posts: 3,626
  • Joined: 31-October 09

Posted 14 November 2010 - 08:25 PM

Hi, PowderSeeker!

This approach may not work if LemonStand and the other website are in different domains/subdomains. The original request by nickdunn described a situation when LemonStand is running in a subdirectory of a domain. In this case, cookies created by LemonStand could be accessed by scripts running in the domain root. I'm not sure what is your website layout, but you should remember that cookies work only within a domain/subdomain.

Thank you

#14 User is offline   PowderSeeker 

  • Member
  • Group: Members
  • Posts: 20
  • Joined: 12-November 10
  • LocationStow, MA

Posted 14 November 2010 - 08:57 PM

Quote

Hi, PowderSeeker!

This approach may not work if LemonStand and the other website are in different domains/subdomains. The original request by nickdunn described a situation when LemonStand is running in a subdirectory of a domain. In this case, cookies created by LemonStand could be accessed by scripts running in the domain root. I'm not sure what is your website layout, but you should remember that cookies work only within a domain/subdomain.

Thank you


Aleksey,

My site is in the same domain/sub-domain. I have LC in /store which is a sub dir of the main site. I also put a test into the LC page/url to check what it thinks the cookies are and I don't see the one listed above. I used print_r($_COOKIE) to do this.

The LS shop is here:

http://green.airtaxi.net/store/

The header url used for the other site headers inside LS is:

http://green.airtaxi...xternal-header/

I have the cookie array dump state also on the other header pages...

http://green.airtaxi.net/

Thx.
0

#15 User is offline   Aleksey 

  • Co-Founder
  • Group: +Administrators
  • Posts: 3,626
  • Joined: 31-October 09

Posted 14 November 2010 - 09:24 PM

Hi!

Please try the following. In the external website pass the PHPSESSID cookie variable to the external-header LemonStand's page. Prototype:

http://green.airtaxi.net/store/external-header/?session = $_COOKIE['PHPSESSID']


In the external-header page code, before you render the cart partial, do the following:

session_destroy();
session_id(Phpr::$request->getField('session')); // Use a name of the GET session parameter here
session_start();


I hope this helps.

Thank you

#16 User is offline   PowderSeeker 

  • Member
  • Group: Members
  • Posts: 20
  • Joined: 12-November 10
  • LocationStow, MA

Posted 15 November 2010 - 08:18 AM

Aleksey,

That worked! Thanks for the help. Much appreciated.

Now on to other things to get ready to use LC. :)

-PowderSeeker
0

#17 User is offline   Eric 

  • Developer
  • PipPipPip
  • Group: Members
  • Posts: 1,290
  • Joined: 04-August 10
  • LocationVancouver, Canada

Posted 12 January 2012 - 10:16 AM

View PostAleksey, on 14 November 2010 - 09:24 PM, said:

http://green.airtaxi.net/store/external-header/?session = $_COOKIE['PHPSESSID']



Note: you may have the session name set to something differently in your php.ini or .htaccess. In my installation it's FWCSESSID.
0

#18 User is offline   Eric 

  • Developer
  • PipPipPip
  • Group: Members
  • Posts: 1,290
  • Joined: 04-August 10
  • LocationVancouver, Canada

Posted 12 January 2012 - 11:03 AM

View PostEric, on 12 January 2012 - 10:16 AM, said:

Note: you may have the session name set to something differently in your php.ini or .htaccess. In my installation it's FWCSESSID.


Although, I found that PHPSESSID (FWCSESSID) isn't actually used. $ticket['id'] is the base64 encoded ID of the customer OR user, based on which cookie you pass. PHPROAD for backend user, eCommerce for frontend customer. Here is a more thorough example:

<?

$is_backend_user = isset($_COOKIE['PHPROAD']);

if($is_backend_user)
	$session = $_COOKIE['PHPROAD'];
else
	$session = $_COOKIE['eCommerce'];

if(!empty($session)) {
	$ticket = Phpr::$security->validateTicket($session);
	
	if(!empty($ticket['user'])) {
		$id = base64_decode($ticket['user']);
	}
}

if($id)
	echo 'Logged in ' . ($is_backend_user ? 'user' : 'customer') . ' ID: ' . $id;

0

Share this topic:


Page 1 of 1

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users