Wednesday, October 05, 2016

PrestaShop: Adding Fields to Admin Area Lists

No comments:
When clients (or accountants ;->) call with questions about a particular order, they don't always have the order id or order reference numbers. In these cases, it's handy to be able to search by other fields.

The PrestaShop override mechanism make it easy to add fields to admin area lists without changing the core code. For example, to add lookup by Invoice #, Phone Number, and Postal Code to the orders list in the PresaShop Admin area, I only had to create the following file: /override/controllers/admin/AdminOrdersController.php

NOTE: Be sure to delete /cache/class_index.php after adding your new class!

<?php
class AdminOrdersController extends AdminOrdersControllerCore
{
    public function __construct()
    {
        parent::__construct();

        $this->fields_list['invoice_number'] = array(
            'title' => $this->l('Invoice #'),
            'align' => 'text-center',
            'class' => 'fixed-width-xs'
        );
        $this->fields_list['phone_mobile'] = array(
            'title' => $this->l('Phone Number')
        );
        $this->fields_list['postcode'] = array(
            'title' => $this->l('Zip/Postal code')
        );
    }
}

Wednesday, July 27, 2016

CentOS7 + PHP 5.6 + APCu

No comments:
To install APCu on Linux (fully updated CentOS7 box), I read on various places on the web that I needed:

yum install php-pecl-apcu

Which gave me the error

Error: php56u-common conflicts with php-common-5.4.16-36.1.el7_2.1.x86_64

So I searched yum

sudo yum list \*apcu\*

...and came up with a command that worked....

sudo yum install php56u-pecl-apcu

Thursday, May 26, 2016

PrestaShop 1.6.x Front Module for non-CMS Page

No comments:
Ever want to add a totally new front page to PrestaShop, but found that a CMS page was not enough? I needed to create a totally new page, with a form that could submit to itself, and I did not find info about how to do this in PrestaShop 1.6.

Based on the idea of a module for doing this which I found in a PrestaShop 1.5 article, I did the following...

  • Use the PrestaShop module generator to create a new module
  • Inside the module folder, create folders /controllers/front/
  • Inside /controllers/front/, create a php file that describes the action for the controller
  • Name the controller class {modulename}{action}ModuleFrontController (extends ModuleFrontController). E.g. module changepassword, controller file changepassword.php would be
    class changepasswordchangepasswordModuleFrontController extends ModuleFrontController 
  • I BELIEVE case is unimportant, but make it case sensitive just in case.
  • If the customer needs to be logged in to use the action, then set the following at the beginning of the class before adding functions to your ModuleFrontController
    public $auth = true;
  • Put your template in /modules/{your_module}/views/templates/front/{your_template_name}.tpl
  • In your ModuleFrontController::initContent() function, do
    parent::initContent(); $this->setTemplate('{your_template_name}.tpl');
  • If you are submitting to self, you form action (in the tpl file) should be
    action="{$link->getModuleLink('{modulename}', '{action}')|escape:'html':'UTF-8'}"  
  • If you need to define smarty values based on the submitted form, use $this->context->smarty->assign in the init function of your ModuleFrontController.
  • Define a URL for the form in admin area -> preferences -> SEO & URLs.

Sunday, March 27, 2016

Full List of AdWords URL Parameters for Tracking Templates

No comments:
AdWords has added the ability to add parameters to all your URLs via Shared Library -> URL
options -> Tracking Template, which was a very welcome upgrade to those of us who tag all our URLs. However, I struggled to find a complete list of parameters available to me for use in the Tracking Template, and decided to make my own list and share it.

However, when investigating the creation of the table, I found a Google page "Set up tracking with ValueTrack parameters", which has a complete list of all the values and give good explanations. To find the list, you will need to expand the sections in "Available ValueTrack parameters" to see the values, but the list seems complete.

Thursday, March 24, 2016

In Search of the Lost MailChimp API v3 PHP Wrapper

No comments:
After spending some time deciding "MailChimp or some other service", for various reasons I decided to stay with MailChimp, especially since it's free for me at the current time. I dug into the docs, and immediately detect that MailChimp has moved from v2 of their API to the new v3, as of the spring of 2015. Since v2 will be turned off at the end of 2016, v3 was the logical choice.

Is there a wrapper? Let's see https://apidocs.mailchimp.com/api/downloads/ lists wrappers for a bunch of languages... but no mention of wrappers for v3.

When I reached out to MailChimp, they said:
"Because API v3.0 recently reached feature parity [emphasis mine] with previous versions, we haven't been able to set up any resources to promoting wrappers API 3.0. With said, our developers are working on improving our API 3.0 experience for our users, and if you'd like to check in on any feature updates or news relating to 3.0, please be sure to head to our Road map page below and sign up to receive our API announcements.
Going forward, while we don't have any documentations of various 3.0 wrappers, github would be a good resource to find any v3.0 wrappers that can be used."

Since Drew McLellan has updated his PHP API wrapper to v3, and his component is mentioned on the MailChimp site (listed as a v2 component), and since his component has more stars and downloads on packaist.org, I will go with that wrapper to start.

Wednesday, March 16, 2016

MySQL Split / Explode

No comments:
Note to self: Although MySQL does not have a split / explode type function, it DOES have a built SUBSTRING_INDEX function that can be used in some circumstances. E.g. if you have a field with value '12345-right', you can get the left part with SUBSTRING_INDEX(value, '-', 1), and the right part with SUBSTRING_INDEX(value, '-', -1).

In general, I agree with Melchior Blausand's rant on StackOverflow: that I shouldn't be looking for explode, I should be looking at a better way to store my data. If you are reading this, think about storing differently rather than using a hack like this.

Tuesday, March 15, 2016

TPV Virtual, BBVA, y PrestaShop

No comments:
En diciembre, escribí sobre mi uso del TPV de ING en mi tienda online. Funcionaba bien, pero faltaba la posibilidad de quitar 3D Secure (Verified by Visa, SecureCode, etc.) en pedidos seguros, y la opción de "Pago en 1 clic" (clicktopay).

Desde entonces, he cambiado a un TPV de BBVA. Sale ligeramente mas barato que el TPV de ING (creo que la commission es 0,48%, y recibo el dinero dentro de 72 horas), per mas importante, ahora tengo control de 3D Secure, y la opción de "Pago en 1 clic". Mi agente de BBVA entendía exactamente lo que estaba buscando, y necesitaba relativamente poco tiempo en tener todo en marcha.

También he cambiado al modulo RedSys de idnovate. El modulo tiene muchas opciones, y David siempre responde rápido a mis preguntas.

Da igual que banco estas utilizando, si esta a través de RedSys no olvides a utilizar la opción de "AutoReturn".

Sunday, February 14, 2016

Missing sqlite.dll when launching Navicat

No comments:
Note to self: "Missing required library sqlite.dll, 998" when starting Navicat: I have no idea what caused it, and reinstalling did not fix it, but this article let me practice my (pathetic) Germany, and gave me the solution to the problem - restarting the computer fixed it.
Posting since the majority of sites that talked about the problems did not include a solution.

Wednesday, February 10, 2016

PrestaShop Gamification / Merchant Expertise SQL Errors

No comments:
Quick Note: I added an override to the DbCore class yesterday after discovering that malformed queries fail silently. For example:

<?php
$resource = Db::getInstance()->query(
      "select * frommmmmmmmmmm ps_orders");
while ($data_row = 
      Db::getInstance()->nextRow($resource)) {
   //Do Important Stuff
}

Would simply fail to work, without logging anything.

[Yes, I hear you, I should have checked the value of $resource before starting the while loop, and I agree. However, note that the official PrestaShop docs say that query "Will not return a boolean; instead returns a database resource that you can use with other DB class methods, such as nextRow()". [Ed: Not true! query returns false on SQL syntax errors]]

[I have _PS_MODE_DEV_ on while developing, which catches the error in the example, but my problem was with code that I accidentally typed two letters when my focus was on the wrong window before committing. And yes, I hear you, I should have noticed that when doing my git commit.]

Once I am happy with my override, and the associated iterator I added to make code like the above cleaner and safer, I will blog about the classes. However, in the meantime, I can tell you that my override sends DB errors to the PHP error log, and that the log this morning was filled with stack crawls of SQL errors from the gamification module. I've verified that these errors exist in a virgin install of PrestaShop, and I will use these instructions (thanks, Oskar!) to disable the module.

I also reported the errors.

Tuesday, February 02, 2016

My 5 Most Read Tech Articles

No comments:
January was a "bad" month... my tech blog, which I use mostly to talk to myself, got more non-paid traffic than our e-commerce site. Trends say this is a very temporary situation (and let's hope that's true!), but it was a bit depressing anyway.

To celebrate, I've included the top 5 read articles from this blog for the month of January, 2016.

  1. PrestaShop 1.5/1.6 and the Google Tag Manager (May, 2015)
    Makes sense, I was surprised a module like this isn't included in PrestaShop by default. A surprising number of site are now using it.
  2. PHPStorm + xdebug + ScotchBox 2.0 (Jul, 2015)
    This came out of my summer love affair with Vagrant / ScotchBox, which I moved away from due to Windows 10 problems.
  3. PayPal Auto Return with PrestaShop (Nov, 2015)
    This goes hand in hand with the PrestaShop GTM module. It's needed to insure transactions get tracked.
  4. Enable the PrestaShop 1.6 Smarty Debug Console (Jul, 2015)
    Again, I was surprised this even needed to be researched... it should be easily enabled.
  5. Programmatically Importing Product with Images in Magento (Jun, 2009)
    The article that would not die. I don't know if it's still applicable, but for sure it's still read. I think I will add a warning to it to make sure people realize it was written centuries ago.
My favorite blog article in January, excluding my blog of course :->, came from L3's Peter O'Neil. Understanding your Website Visitors: Prospects vs Customers is a must have for your Google Analytics setup. I have to work though all the technical articles on his blog, there are others that look juicy, too.

Wednesday, January 13, 2016

PHPMailer SMTP in Prestashop

No comments:
I was using the Mail::Send static function in PrestaShop to send some messages with attachments, but PrestaShop was "decorating" the emails with an attached shop logo image. It also did not allow multiple BCCs.

Rather than override the Mail::Send function, I decided to use Composer to install an updated library to provide flexibility both now and in the future.

As many people have commented, PrestaShop uses an outdated version of SwiftMailer. My initial idea was to simply install a current version in my composer directory (leaving PrestaShop alone), but first I took a look at what libraries people recommended. PHPMailer and SwiftMailer are both very popular (and both apparently work just fine), but PHPMailer seems to be more popular. A comment that I read indicating that debugging PHPMailer was MUCH easier than debugging SwiftMailer, which lead me to decided on PHPMailer.

I used my old article to guide my PHPMailer installation, and then used my configured SMTP params to send email. Worked like a charm... multiple BCCs and attachments included. Below is the SMTP setup using the PrestaShop config. Note that this ONLY works if you set "Set my own SMTP parameters (for advanced users ONLY)" with valid SMTP values in the "Advanced Parameter" / "E-Mails" section of your PrestaShop admin area.

<?php
require(_PS_ROOT_DIR_ . '{location of your autoload file}/autoload.php');
use PHPMailer\PHPMailer\PHPMailer;

function getConfiguredPHPMailer()
{
    $configuration = Configuration::getMultiple(array (
        'PS_MAIL_METHOD',
        'PS_MAIL_SERVER',
        'PS_MAIL_USER',
        'PS_MAIL_PASSWD',
        'PS_MAIL_SMTP_ENCRYPTION',
        'PS_MAIL_SMTP_PORT'
    ), null, null, Context::getContext()->shop->id);

    // Returns immediatly if emails are deactivated
    if ($configuration['PS_MAIL_METHOD'] == 3) {
        return null;
    } else {
        if ($configuration['PS_MAIL_METHOD'] != 2) {
            @mail('you@yoursite.com', 'ERROR: Code only configured for SMTP',
                'Code only works with PrestaShop configured for SMTP (with PS_MAIL_METHOD == 2)');
            return null;
        }
    }

    $mail = new PHPMailer;
    $mail->isSMTP();                                 // Set mailer to use SMTP
    $mail->Host = $configuration['PS_MAIL_SERVER'];  // Specify SMTP server
    $mail->SMTPAuth = true;                          // Enable SMTP authentication
    $mail->Username = $configuration['PS_MAIL_USER'];// SMTP username
    $mail->Password = $configuration['PS_MAIL_PASSWD'];// SMTP password
    $mail->SMTPSecure = $configuration['PS_MAIL_SMTP_ENCRYPTION'];// Enable encryption
    $mail->Port = $configuration['PS_MAIL_SMTP_PORT'];// TCP port to connect to

    return $mail;
}

Friday, January 08, 2016

Buttons in Emails

No comments:
I was just checking my inbox to see how people do buttons in emails, and I found a lot of broken buttons - HTML emails which use links to images that GMail did not load by default. Reading this long post lead me to Button.cm, which gave me a nice, image-free button.

Thursday, January 07, 2016

Comprar Online

No comments:
Curioso... "comprar online" esta MUCHO mas utilizado en busquedas Google que "comprar por internet".

Monday, January 04, 2016

No comments:
Another "note to self": In PrestaShop, "partial refunds" are stored in the ps_order_slip table. You need to sum the shipping and products totals to get the full amount of the refund.