Showing posts with label prestashop. Show all posts
Showing posts with label prestashop. Show all posts

Wednesday, March 19, 2014

Prestashop / Tpl file tips

Assign a variable value in controller
$value = "Test value";

$this->context->smarty->assign('variable',$value)

To get the variable value in tpl file
{$variable}

If conditions
{if $value}

your code

{/if}

foreach in tpl
{foreach $val as $k=>$v}

your code

{/foreach}
forloop in tpl
{for $foo=1 to 5}
your code
{/for}

Tuesday, April 23, 2013

Prestashop - Moving customers passwords to new site 1.4.9 to 1.5.x

Read the following steps and do it. 

Step 1:

Edit file ../config/settings.inc.php , and add :


define('_COOKIE_KEY_OLD_', 'YOUR_PS_V.1.4.9_COOKIE_KEY_');

Step 2:
Edit file ../override/classes/Customer.php, and add :

  public function getByEmail_old($email, $passwd = null, $ignore_guest = true)
        {
                if (!Validate::isEmail($email) || ($passwd && !Validate::isPasswd($passwd)))
                        die (Tools::displayError());

                $sql = 'SELECT *
                                FROM `'._DB_PREFIX_.'customer`
                                WHERE `email` = \''.pSQL($email).'\'
                                        '.Shop::addSqlRestriction(Shop::SHARE_CUSTOMER).'
                                        '.(isset($passwd) ? 'AND `passwd` = \''.Tools::encrypt_old($passwd).'\'' : '').'
                                        AND `deleted` = 0'.
                                        ($ignore_guest ? ' AND `is_guest` = 0' : '');

                $result = Db::getInstance()->getRow($sql);

                if (!$result)
                        return false;
                $this->id = $result['id_customer'];
                foreach ($result as $key => $value)
                        if (key_exists($key, $this))
                                $this->{$key} = $value;

                return $this;
        }


Step 3 :
Edit file ../override/classes/Tools.php, and add :

 public static function encrypt_old($passwd)
        {
                return md5(_COOKIE_KEY_OLD_.$passwd);
        }

Step 4:
Edit file ../override/controllers/front/AuthController.php, and add :

 protected function processSubmitLogin()
        {
                Hook::exec('actionBeforeAuthentication');
                $passwd = trim(Tools::getValue('passwd'));
                $email = trim(Tools::getValue('email'));
                if (empty($email))
                        $this->errors[] = Tools::displayError('E-mail address required');
                elseif (!Validate::isEmail($email))
                        $this->errors[] = Tools::displayError('Invalid e-mail address');
                elseif (empty($passwd))
                        $this->errors[] = Tools::displayError('Password is required');
                elseif (!Validate::isPasswd($passwd))
                        $this->errors[] = Tools::displayError('Invalid password');
                else
                {
                        $customer = new Customer();
                        $authentication = $customer->getByEmail(trim($email), trim($passwd));
                        $authentication_old = $customer->getByEmail_old(trim($email), trim($passwd));
                        if ((!$authentication AND !$authentication_old) || !$customer->id)
                                $this->errors[] = Tools::displayError('Authentication failed');
                        else
                        {
                                $this->context->cookie->id_compare = isset($this->context->cookie->id_compare) ? $this->context->cookie->id_compare: CompareProduct::getIdCompareByIdCustomer($customer->id);
                                $this->context->cookie->id_customer = (int)($customer->id);
                                $this->context->cookie->customer_lastname = $customer->lastname;
                                $this->context->cookie->customer_firstname = $customer->firstname;
                                $this->context->cookie->logged = 1;
                                $customer->logged = 1;
                                $this->context->cookie->is_guest = $customer->isGuest();
                                $this->context->cookie->passwd = $customer->passwd;
                                $this->context->cookie->email = $customer->email;
                                
                                // Add customer to the context
                                $this->context->customer = $customer;
                                
                                if (Configuration::get('PS_CART_FOLLOWING') && (empty($this->context->cookie->id_cart) || Cart::getNbProducts($this->context->cookie->id_cart) == 0))
                                        $this->context->cookie->id_cart = (int)Cart::lastNoneOrderedCart($this->context->customer->id);
                                
                                // Update cart address
                                $this->context->cart->id = $this->context->cookie->id_cart;
                                $this->context->cart->setDeliveryOption(null);
                                $this->context->cart->id_address_delivery = Address::getFirstCustomerAddressId((int)($customer->id));
                                
                                $this->context->cart->id_address_invoice = Address::getFirstCustomerAddressId((int)($customer->id));
                                $this->context->cart->secure_key = $customer->secure_key;
                                $this->context->cart->update();
                                $this->context->cart->autosetProductAddress();

                                Hook::exec('actionAuthentication');

                                // Login information have changed, so we check if the cart rules still apply
                                CartRule::autoRemoveFromCart($this->context);
                                CartRule::autoAddToCart($this->context);

                                if (!$this->ajax)
                                {
                                        if ($back = Tools::getValue('back'))
                                                Tools::redirect(html_entity_decode($back));
                                        Tools::redirect('index.php?controller=my-account');
                                }
                        }
                }
                if ($this->ajax)
                {
                        $return = array(
                                'hasError' => !empty($this->errors),
                                'errors' => $this->errors,
                                'token' => Tools::getToken(false)
                        );
                        die(Tools::jsonEncode($return));
                }
                else
                        $this->context->smarty->assign('authentification_error', $this->errors);
        }

Finally
Create csv file to update XX_customer_group table database for all id_customer set group to 3 (customer), and import to your Prestashop database


Done :)

Sunday, April 14, 2013

Send Email in Prestashop

               How to send Email in Prestashop

               Its very simple just follow the following 2 steps

       Step : 1 You should create a email template html file with mail static contents

                     For Dynamic contents You must use {firstname} like this

                    Path for template html file : (root folder )mails/en/test.html

                    Inside the mails folder you will find many language files like en,fr,de,es,it

                    You can put the particular language file at inside particular folder


     Step : 2  Just use the following code to send mail at controller or wherever you want

                            $id_land = $order->id_lang;   // get current language id , if you are in order page you can use this

                           $template_name = 'test';  // this is file name here the file name is test.html                                           $title = "Test Login Details";    // mail title
                            $templateVars['{firstname}'] = "firstname"; 
                            $templateVars['{lastname}'] = 'lastname';
                            $templateVars['{email}'] = "email address";
                            $templateVars['{passwd}'] = "password";
                            $to = "testingto@gmail.com";
                            $toName = "To name";
                            $from = "testingfrom@gmail.com";
                            $fromName = "From Name";

                     
                           // mail function

   Mail::Send($id_land, $template_name, $title, $templateVars, $to, $toName, $from, $fromName);

                Enjoy ...............