Magento 2 Creating a theme

Hopefully I’m going to cover the things I’ve been unable to find out so far.

To create your own theme you need the following structure app/design/frontend/Somename/Somename1/

From here you then need Magento_Theme/layout/ and Magento_Theme/templates/ for your layout.xml files and template.phtml files

Back in app/design/frontend/Somename/Somename1/ you need a web/ folder with the following structure

css/

js/

images/

fonts/

In app/design/frontend/Somename/Somename1/ you will also need registration.php and theme.xml.

 

Your registration file should contain the following where the somename and somename1 match your folder structure

<?php
/**
* Copyright © 2015 Magento. All rights reserved.
* See COPYING.txt for license details.
*/
\Magento\Framework\Component\ComponentRegistrar::register(
\Magento\Framework\Component\ComponentRegistrar::THEME,
‘frontend/somename/somename1’,
__DIR__
);

 

Your theme.xml file should contain the following where <parent> is if you are extending another theme

<theme xmlns:xsi=”http://www.w3.org/2001/XMLSchema-instance” xsi:noNamespaceSchemaLocation=”urn:magento:framework:Config/etc/theme.xsd”>
<title>A NAME</title> <!– your theme’s name –>
<parent>Magento/blank</parent> <!– the parent theme, in case your theme inherits from an existing theme –>
<media>
<preview_image>media/preview.jpg</preview_image> <!– the path to your theme’s preview image –>
</media>
</theme>

Magento display minimum order amout

I have used this slightly messy way of displaying the minimum order amount on any phtml file. I used it in the header but could easily go in any template file. Obviously you could also use the Magento subtotal for many other calculations too!

<div>
<? if(Mage::getSingleton(‘checkout/session’)->getQuote()->getSubtotal() > 50) { ?>

<? } else { ?>
<p>We have a minimum order of £50</p>
<p>Please continue shopping</p>
<? } ?>

</div>

Magento SQL Average Total Orders Per Customer

First we need to get the total number of orders:

$result = mysqli_query($con,”

SELECT count(mg_sales_flat_order.status) as grand_count
FROM mg_sales_flat_order
WHERE mg_sales_flat_order.status NOT LIKE ‘canceled’
AND mg_sales_flat_order.status NOT LIKE ‘closed’
AND mg_sales_flat_order.status NOT LIKE ‘fraud’
AND mg_sales_flat_order.status NOT LIKE ‘holded’
AND mg_sales_flat_order.status NOT LIKE ‘paypal_canceled_reversal’

$totalorders1 = $row[‘grand_count’];

“);

while($row = mysqli_fetch_array($result)) {

$totalorders = $row[‘grand_count’];

echo $totalorders;
}

Then we need to get the total number of customers:

$result = mysqli_query($con,”

SELECT COUNT(*) AS grand_count FROM(
SELECT customer_email FROM mg_sales_flat_order
WHERE mg_sales_flat_order.status NOT LIKE ‘canceled’
AND mg_sales_flat_order.status NOT LIKE ‘closed’
AND mg_sales_flat_order.status NOT LIKE ‘fraud’
AND mg_sales_flat_order.status NOT LIKE ‘holded’
AND mg_sales_flat_order.status NOT LIKE ‘paypal_canceled_reversal’
GROUP BY customer_email
) s”);

while($row = mysqli_fetch_array($result)) {

$totalcustomers = $row[‘grand_count’];

echo $totalcustomers1;

}

We then need to do total orders divided by total customers to give us the average number of orders per customer

$decimal_places = 2;

echo number_format($totalorders/$totalcustomers, $decimal_places);

Magento SQL Repeat Customers vs New Customers

First off get the total number of customers:

SELECT COUNT(*) AS grand_count FROM(
SELECT customer_email FROM mg_sales_flat_order
WHERE mg_sales_flat_order.status NOT LIKE ‘canceled’
AND mg_sales_flat_order.status NOT LIKE ‘closed’
AND mg_sales_flat_order.status NOT LIKE ‘fraud’
AND mg_sales_flat_order.status NOT LIKE ‘holded’
AND mg_sales_flat_order.status NOT LIKE ‘paypal_canceled_reversal’
GROUP BY customer_email

 

Then get the number of new customers:

SELECT COUNT(*) AS grand_count FROM(
SELECT customer_email FROM mg_sales_flat_order
WHERE mg_sales_flat_order.status NOT LIKE ‘canceled’
AND mg_sales_flat_order.status NOT LIKE ‘closed’
AND mg_sales_flat_order.status NOT LIKE ‘fraud’
AND mg_sales_flat_order.status NOT LIKE ‘holded’
AND mg_sales_flat_order.status NOT LIKE ‘paypal_canceled_reversal’
GROUP BY customer_email HAVING COUNT(*) = 1
) s

 

Then get the number of repeating customers:

SELECT COUNT(*) AS grand_count FROM(
SELECT customer_email FROM mg_sales_flat_order
WHERE mg_sales_flat_order.status NOT LIKE ‘canceled’
AND mg_sales_flat_order.status NOT LIKE ‘closed’
AND mg_sales_flat_order.status NOT LIKE ‘fraud’
AND mg_sales_flat_order.status NOT LIKE ‘holded’
AND mg_sales_flat_order.status NOT LIKE ‘paypal_canceled_reversal’
GROUP BY customer_email HAVING COUNT(*) > 1
) s

 

You can then get the outputs of the SQL to calculate your percentages with something like the below:

echo ($repeatcustomers/$totalcustomers)*100 . “%”;

echo ($newcustomers/$totalcustomers)*100 . “%”;

Magento SQL Average Order Value

I need to get the AOV from our store.

Simple SQL code is as follows:

SELECT SUM( grand_total ) / COUNT( * )
FROM `mg_sales_flat_order`
WHERE mg_sales_flat_order.status NOT LIKE ‘canceled’
AND mg_sales_flat_order.status NOT LIKE ‘closed’
AND mg_sales_flat_order.status NOT LIKE ‘fraud’
AND mg_sales_flat_order.status NOT LIKE ‘holded’
AND mg_sales_flat_order.status NOT LIKE ‘paypal_canceled_reversal’

Instead of using grand_total there are a couple of other things you can do which are as follows:

grand_total = product rev + ship – discount inc tax

base_subtotal & subtotal = product revenue exc tax

base_subtotal_incl_tax & subtotal_incl_tax  = product revenue inc tax

Woocommerce

I have recently started working with Woocommerce, after years of being developing on Magento.  The reason for me learning to develop on Woocommerce is simple, it’s very easy to develop on and the main reason I’ve been using it is due to it’s brilliant subscription engine extension. Woo’s subscription engine module is fair superior to the current Magento recurring profiles, for starters it has been developed to handle more payment gateways – Magento seems to like you to use Paypal which comes with masses of draw backs.

Over the next couple of posts I will share some of the work I have been doing including setting up and customising some of the code. So far I can’t rate Woo and the support enough!

Magento Optimisation – Part 1

Recently I have been exploring way in which to make Magento fly, and when I say fly I just mean not be as sluggish as it is out of the box. It’s well know that Magento is resource intensive meaning that a good powerful server is a must.

Server

As far as hosting goes my default option is and always has been Simple Servers. Not only have I found them to be the fastest Magento hosting but also their support and response time is very impressive.

.htaccess

Another must is a well configured .htaccess file, this is normally a very quick win if it has never been set up. You can find the version that I prefer to use here.

CSS, JS and HTML compression

 

Magento without any additional features or modules calls 25 JS files in the head of every page. The more requests the slower the site. Fortunately it is easy to merge all the CSS and Javascript files into 1 each each, drastically reducing the number of http requests made.

To merge CSS and JS files:

System -> configuration -> developer

Merge Javascript files -> yes

Merge CSS files -> yes

 

Magento Quick Personalisation

Magento doesn’t have any personalisation features out of the box and a lot of the companies that do personalisation for Magento charge a lot of money. I needed a quick free fix. I recently had to ensure that some content on a my account page within Magento was personalised to that customer. Pretty easy I though grab the customers email address that they used to login with, create a few arrays, and then output different information depending on which array they were in. The code is a little crude but provided me a quick fix, I’m probably now going to take this a little further and see if I can use a database table rather than sticking the email addresses in an array. This code can be used on any template page where the customer is logged in. I know someone would probably tell me this isn’t the safest way to do it so don’t include any sensitive information.

 

This is the code that I used:

<?php

if (Mage::getSingleton(‘customer/session’)->isLoggedIn()) {

//Check that the customer is login and return their credentials
$customer = Mage::getSingleton(‘customer/session’)->getCustomer();

//Get customers email address
$somevariable = $customer->getEmail();

//Email addresses
$array1 = array(
[email protected]”,
[email protected]”);

//Email addresses
$array2 = array(
[email protected]”,
[email protected]”);

//Email addresses
$array3 = array(
[email protected]”,
[email protected]”);

//Email addresses
$array4 = array(
[email protected]”,
[email protected]”);

//Email addresses
$array5 = array(
[email protected]”,
[email protected]”);

//Email addresses
$array6 = array(
[email protected]”,
[email protected]”);
if (in_array($variable123, $array1, TRUE)){
echo “Content Array 1”;
}

elseif(in_array($variable123, $array2, TRUE)){
echo “Content Array 2”;
}

elseif(in_array($variable123, $array3, TRUE)){
echo “Content Array 3”;
}

elseif(in_array($variable123, $array4, TRUE)){
echo “Content Array 4”;
}

elseif(in_array($variable123, $array5, TRUE)){
echo “Content Array 5”;
}

elseif(in_array($variable123, $array6, TRUE)){
echo “Content Array 6”;
}

else {
echo “Content not in array”;
}
}

?>