| 1 | # ------------------------------------------------------------------------------------- | ||
| 2 | # flo::plugin::Shop::Basket | ||
| 3 | # ------------------------------------------------------------------------------------- | ||
| 4 | # Author : Jean-Michel Hiver <jhiver@mkdoc.com>. | ||
| 5 | # Copyright : (c) MKDoc Holdings Ltd, 2003 | ||
| 6 | # | ||
| 7 | # This MKDoc plugin adds an item into someones' shopping basket. | ||
| 8 | # If the client sent a cookie, then this cookie is used to fetch the existing basket. | ||
| 9 | # | ||
| 10 | # Otherwise, this module creates a new shopping basket and sends a cookie to the | ||
| 11 | # client for future retrieval. | ||
| 12 | # ------------------------------------------------------------------------------------- | ||
| 13 | package flo::plugin::Shop::Basket; | ||
| 14 | use strict; | ||
| 15 | use warnings; | ||
| 16 | |||
| 17 | use base qw /MKDoc::Core::Plugin/; | ||
| 18 | |||
| 19 | |||
| 20 | sub activate | ||
| 21 | { | ||
| 22 | my $self = shift; | ||
| 23 | my $session = MKDoc::Session->load() || return $self->SUPER::activate (@_); | ||
| 24 | my $saveme = 0; | ||
| 25 | $session->{basket} ||= do { $saveme = 1; new MKDoc::ECommerce::Basket() }; | ||
| 26 | $session->{country} ||= do { $saveme = 1; $ENV{ECOMMERCE_COUNTRY} || 'United Kingdom' }; | ||
| 27 | |||
| 28 | $session->save() if ($saveme); | ||
| 29 | |||
| 30 | return $self->SUPER::activate (@_); | ||
| 31 | } | ||
| 32 | |||
| 33 | |||
| 34 | 1; | ||
| 35 | |||
| 36 | |||
| 37 | __END__ |