Skip to content

Instantly share code, notes, and snippets.

@ryaan-anthony
ryaan-anthony / gist:9c3ffc3d75dc9c754f3d
Last active August 29, 2015 14:10
Magento - remove broken images
<?php
include_once("app/Mage.php");
umask(0);
Mage::app('admin');
$collection = Mage::getResourceModel('catalog/product_collection');
<?php
class Import_Csv
{
public function load($filepath)
{
if(!file_exists($filepath)){
throw new Exception("File \"{$filepath}\" not found.");
exit;
@ryaan-anthony
ryaan-anthony / createIfDoesntExist.php
Last active August 29, 2015 14:06
Magento - create entity if doesnt exist
/**
* Load object data and create if doesnt exist
*
* @param integer $id
* @return Mage_Core_Model_Abstract
*/
public function createIfDoesntExist($id, $field=null)
{
$this->load($id, $field);
@ryaan-anthony
ryaan-anthony / remove-images.php
Last active August 29, 2015 14:03
Magento - remove all images
<?php
include_once("app/Mage.php");
umask(0);
Mage::app('admin');
$collection = Mage::getModel('catalog/product')->getCollection();
foreach ($collection as $product){
<?php
include 'app/Mage.php';
Mage::app();
echo '<pre>';
print_r(Mage::getConfig()->getNode()->xpath('//global//rewrite'));
public function sendVendorNotification($po, $comment='')
{
$vendor = $po->getVendor();
$method = $vendor->getNewOrderNotifications();
if (!$method || $method=='0') {
return $this;
}
$collection = Mage::getModel('catalog/product')->getCollection();
$collection->joinField('category_id', 'catalog/category_product', 'category_id', 'product_id = entity_id', null, 'left');
$collection->addAttributeToFilter('category_id', array('null' => true));
$collection->addAttributeToFilter('status', 1);
$collection->addAttributeToSelect('*');
/**
* Get collection size
*
* @return int
*/
public function getSize()
{
if (is_null($this->_totalRecords)) {
$sql = $this->getSelectCountSql();
$this->_totalRecords = $this->getConnection()->fetchOne($sql, $this->_bindParams);
<?php
class Ip_Test_Model_Observer
{
public function implementOrderStatus(Varien_Event_Observer $observer)
{
$order = $observer->getEvent()->getOrder();
$orderItems = $order->getAllVisibleItems();
foreach ($orderItems as $item) {