Skip to content

Instantly share code, notes, and snippets.

View neilbradley's full-sized avatar

Neil Bradley neilbradley

View GitHub Profile
@neilbradley
neilbradley / magento-orders-export-xml.php
Last active July 28, 2017 10:12
export Magento Orders as XMLs
<?php
require_once('app/Mage.php'); //Path to Magento
umask(0);
Mage::app();
// Run you code here
$orderCollection = Mage::getModel('sales/order')->getCollection();
$fromDateStart = '2017-01-01';
$toDateEnd = '2017-07-24';
@neilbradley
neilbradley / magento-set-default-addresses.php
Created July 26, 2017 13:42
Programmatically set default billing/shipping address of customers if they are not set in magento
<?php
require_once ("app/Mage.php");
umask(0);
Mage::app("default");
$collection = Mage::getModel('customer/customer')->getCollection()->addAttributeToSelect('*');
foreach ($collection as $customer) {
@neilbradley
neilbradley / export.php
Created July 26, 2017 13:19
Set a Custom Config date in Magento
Set a Last Run date
Mage::getConfig()->saveConfig('custom_module/order_export/last_run', date('Y-m-d H:i:s'), 'default', 0);
Get this date back
Mage::getStoreConfig('custom_module/order_export/last_run');
@neilbradley
neilbradley / cron-check.php
Created July 26, 2017 13:17
Get last finished_at time from Magento cron
$tasks = Mage::getModel('cron/schedule')->getCollection()
->addFieldToSelect('finished_at')
->addFieldToFilter('job_code', 'orders_exportsales')
->addFieldToFilter('status', 'success');
$tasks->getSelect()
->limit(1)
->order('finished_at DESC');
$lastRun = $tasks->getFirstItem()->getFinishedAt();
@neilbradley
neilbradley / amazon-ses-smtp-sample.php
Created July 20, 2017 11:56
Amazon SES SMTP Sample
<?php
// Modify the path in the require statement below to refer to the
// location of your Composer autoload.php file.
require './vendor/autoload.php';
// Instantiate a new PHPMailer
$mail = new PHPMailer;
// Tell PHPMailer to use SMTP
@neilbradley
neilbradley / ProductExport.php
Created July 18, 2017 13:07
Product Feed / Export for Magento
<?php
/**
* Source: https://www.demacmedia.com/magento-commerce/magento-tutorials/magento-data-feed/
*/
/* To start we need to include abscract.php, which is located
* in /shell/abstract.php which contains Magento's Mage_Shell_Abstract
* class.
*
* Since this ProductExport.php is in /shell/Namespace/ we
@neilbradley
neilbradley / dotmailerpurchasetest.php
Last active May 25, 2017 14:22
Dotmailer Add Transactional Data
<?php
//https://developer.dotmailer.com/docs/add-transactional-data-to-contact
//PHP Version 7 Example
$apiUsername = "API_USER"; //Your API username
$apiPassword = "API_PASSWORD"; //your API password
$baseUrl = 'https://r1-api.dotmailer.com';
$url = $baseUrl . '/v2/contacts/transactional-data/Orders';
@neilbradley
neilbradley / getcustomer.php
Created May 24, 2017 10:12
Get Magento Customer by Entity ID
<?php
require_once('app/Mage.php');
umask(0);
Mage::app();
$customers = Mage::getResourceModel('customer/customer_collection')
->addAttributeToSelect('*') // <- careful with this
->addAttributeToFilter('entity_id', 15701);
@neilbradley
neilbradley / duplicate-sku.sql
Created April 7, 2017 09:07
Find Duplicate SKUs in Magento
SELECT
DISTINCT(`sku`) as `sku`,
COUNT(`sku`) as `skuCount`,
entity_id
FROM
catalog_product_entity
GROUP BY
`sku`
HAVING
`skuCount` > 1;
@neilbradley
neilbradley / .htaccess
Created March 23, 2017 12:53
Password Protect Website
# Password protection
AuthType Basic
AuthName "Site Name Stage"
AuthUserFile /.htpasswd
Require valid-user