Jump to content

Feature request: store the shopping cart in DB to keep it between sessions in logged users


Recommended Posts

Hello,

I´d like to say that a nice feature would be to store the shopping cart items of the logged users in the DB so if the quickly close and come back another day, they still have their items in the shopping cart. If an user is surfing anonimously and then login to the system, the shopping cart must be persisted as well.

Thx,
Pedro

PS: I´ll start working on this feature as I think is something really needed.

Link to comment
Share on other sites

I´ve seen that it´s already stored in the DB. But it just check if the visitor has a cookie to load the old cart. I believe that it should check if the user is logged in if he has an old cart and in that case merge both and update the db. This should be called from init.php and add a Merge method to the cart class to merge two shopping cart. Does it sound right?

thx,
Pedro

Link to comment
Share on other sites

It was easier than I though, it is all already implmented but I didn´t find the option to enable it from the back end, so I added that to the cart module. The file that I modified is located in prestashop/modules/bockcart/blockcart.php from the stable release 1.1. After that going to Modules / Cart Block Configure you can enable the option to reload the cart after login.

I modified these three methods:

public function getContent()
{
$output = '

'.$this->displayName.'

';
if (Tools::isSubmit('submitBlockCart'))
{
$ajax = Tools::getValue('ajax');
$redisplay = Tools::getValue('redisplay');
if ($ajax != 0 AND $ajax != 1)
{
$output .= '
'.$this->l('Ajax : Invalid choice.').'
';
}
if ($redisplay != 0 AND $redisplay != 1)
{
$output .= '
'.$this->l('Cart re-display : Invalid choice.').'
';
}
else
{
Configuration::updateValue('PS_BLOCK_CART_AJAX', intval($ajax));
Configuration::updateValue('PS_CART_FOLLOWING', intval($redisplay));
}
$output .= '
ok.gifl('Confirmation').'" />'.$this->l('Settings updated').'
';
}
return $output.$this->displayForm();
}

public function displayForm()
{
return '
<form action="'.$_SERVER['REQUEST_URI'].'" method="post">

_path.'logo.gif" alt="" title="" />'.$this->l('Settings').'

'.$this->l('Ajax cart').'

<input type="radio" name="ajax" id="ajax_on" value="1" '.(Tools::getValue('ajax', Configuration::get('PS_BLOCK_CART_AJAX')) ? 'checked="checked" ' : '').'/>
enabled.gifl('Enabled').'" title="'.$this->l('Enabled').'" />
<input type="radio" name="ajax" id="ajax_off" value="0" '.(!Tools::getValue('ajax', Configuration::get('PS_BLOCK_CART_AJAX')) ? 'checked="checked" ' : '').'/>
disabled.gifl('Disabled').'" title="'.$this->l('Disabled').'" />

'.$this->l('Activate AJAX mode for cart (compatible with the default theme)').'




'.$this->l('Cart re-display at login').'

<input type="radio" name="redisplay" id="redisplay_on" value="1" '.(Tools::getValue('redisplay', Configuration::get('PS_CART_FOLLOWING')) ? 'checked="checked" ' : '').'/>
enabled.gifl('Enabled').'" title="'.$this->l('Enabled').'" />
<input type="radio" name="redisplay" id="redisplay_off" value="0" '.(!Tools::getValue('ajax', Configuration::get('PS_CART_FOLLOWING')) ? 'checked="checked" ' : '').'/>
disabled.gifl('Disabled').'" title="'.$this->l('Disabled').'" />

'.$this->l('After customer logs in, recall and display contents of his/her last shopping cart').'




<input type="submit" name="submitBlockCart" value="'.$this->l('Save').'" class="button" />


</form>';
}

function install()
{
if
(
parent::install() == false
OR $this->registerHook('rightColumn') == false
OR Configuration::updateValue('PS_BLOCK_CART_AJAX', 1) == false
OR Configuration::updateValue('PS_CART_FOLLOWING') == false
)
return false;
return true;
}
Link to comment
Share on other sites

×
×
  • Create New...