Skip to main content

Coding guidelines

  • Don't use `INNER JOIN`
    Use `JOIN`. Keep it simple. `INNER JOIN` is the same as `JOIN`
    Don't use `LEFT OUTER JOIN`
    Just use `LEFT JOIN`. Keep it simple. `LEFT OUTER JOIN` is the same as `LEFT JOIN`
  • For SQL statement, when using GROUP_CONCAT it's highly recommended to use | as separator. Because by default, most database use comma as a separator. When raw data is used for csv output; column cannot contain comma. 
    For example, instead of 
    SELECT GROUP_CONCAT(order_id) -- which yield 3,5,7 -> breaks the CSV download
    we should do
    SLECT GROUP_CONCAT(order_id  SEPARATOR '|') -- which yields 3|5|7 -> does not break for the CSV download

  • To check if a value exists, use if ($value !== null)
    Do not use if ($value)
    because when $value is zero, if ($value) does not pass.
    Example code:

            if($quote->getIsMultiShipping() && $quoteItem->getCustomPrice()) {
                $item->setPrice($quoteItem->getCustomPrice())->setBaseOriginalPrice($quoteItem->getCustomPrice());

    This code is wrong. When customPrice is zero (no-charge), this if statement does not pass.

    Rewrite it to this:

             if($quote->getIsMultiShipping() && ($quoteItem->getCustomPrice() !== null)) {
                $item->setPrice($quoteItem->getCustomPrice())->setBaseOriginalPrice($quoteItem->getCustomPrice());

    now, if customPrice is zero, this if statement passes