Archive for the ‘Net: Techy: PHP’ category

PHP: Magento: Extract orders based on tax status and payment type

February 2nd, 2013

When you are doing your quarterly VAT returns and inputting details of your Magento shopping cart ordersinto your accounting software (such as the brilliant Crunch system), wouldn’t it be handy to be able to get a simple list of all orders between two dates, whether tax was paid on the order or not (note: this query will NOT work if you have orders with taxable and non-taxable items) and the method of payment (if you are running the SagePaySuite, it’ll also list whether payment was made via Amex):

SELECT
COUNT(*) AS ordercount,SUM(nettotal) AS nettotal,SUM(taxamount) AS taxamount,taxstatus,paymenttype
FROM
(
SELECT
sales_flat_order.increment_id AS orderid,
sales_flat_order.entity_id AS internalid,
sales_flat_order.base_total_paid-sales_flat_order.base_tax_amount AS nettotal,
IF (sales_flat_order.base_tax_amount>0,'tax','untaxed') AS taxstatus,
sales_flat_order.base_tax_amount AS taxamount,
IF (sales_flat_order_payment.method='sagepayform',IF (sagepaysuite_transaction.card_type='AMEX','Amex','SagePay'),sales_flat_order_payment.method) AS paymenttype
FROM
sales_flat_order
JOIN sales_flat_order_payment ON sales_flat_order_payment.parent_id=sales_flat_order.entity_id
LEFT OUTER JOIN sagepaysuite_transaction ON sagepaysuite_transaction.order_id=sales_flat_order.entity_id
WHERE
sales_flat_order.state='complete'
AND sales_flat_order.created_at>='2012-11-01' AND sales_flat_order.created_at<='2013-01-31'
) AS subquery
GROUP BY subquery.taxstatus,subquery.paymenttype

Magento: Get customers ordered by order value

December 17th, 2012

Want to know which of your Magento e-commerce shopping cart customers have ordered the most this year? Well, I’ve written the following SQL query to help:

SELECT SUM(sales_flat_order.base_total_invoiced) AS totalvalue,sales_flat_order.customer_firstname,sales_flat_order.customer_lastname,sales_flat_order.customer_email,sales_flat_order_address.street,sales_flat_order_address.city,sales_flat_order_address.region,sales_flat_order_address.postcode FROM sales_flat_order,sales_flat_order_address WHERE sales_flat_order.state='complete' AND sales_flat_order.created_at>'2012-01-01' AND sales_flat_order_address.entity_id=sales_flat_order.billing_address_id GROUP BY sales_flat_order.customer_email ORDER BY totalvalue DESC

Marking old posts

July 25th, 2012

I’ve just added a piece of code from “Jem on WordPress” to flag that content older than 6 months on this blog may be inaccurate and not reflect “now” (this comes as I’ve just realised this would be my 996th [19 private, 6 drafts] post in a period of time spanning 15th of October 2001 to “today”: and that’s a long time in anybody’s book

Quicknotes: PHP Pear Modules

July 17th, 2012

Just really for my memory:

To install all of the above:

pear channel-discover pear.pearplex.net
pear install pearplex/PHPExcel
pear channel-discover pear.bairwell.com
pear install bairwell/Bairwell_Geocoder

If you want to make your own PEAR module, consider PHIX Project

WordPress PHPStorm coding standards

May 24th, 2012

I’m a regular user of JetBrains PhpStorm coding package and recently I’ve been doing a bit of WordPress orientated work – so how can I ensure my code matches the WordPress coding standards? Well, using Rarst’s WordPress coding standards helps.

  1. Just download the file and save it as “WordPress.xml” into your Php Storm folder such as .WebIde40/config/codestyles (on Linux, this was /home/[username]/.WebIde40/config/codestyles : I did have to show hidden files in Nautilus: on Windows it’ll be something like C:\Users\[username]\.WebIde40\config\codestyles\ ). To find your configuration file easily, run the following commands:
    • Linux: cd ~/.WebIde40/config/codestyles
    • Mac OS X: cd ~/Library/Preferences/WebIde40/codestyles
    • Windows: cd c:/Users/USERNAME/.WebIde40/config/codestyles
  2. Restart PhpStorm
  3. Load your project and go to “File -> Settings”
  4. Select “Project Settings -> Code Style”
  5. Select “Scheme: WordPress” and OK
  6. Select “Code -> Reformat code…” and wait for your code to be reformatted

This won’t catch every item (such as the Yoda conditions), but it’ll at least make it a bit closer.

gamy-dance