Welcome to Snippi.net

Welcome to Snippi.net. Place to share Magento code snippets.

Feel free to register and submit your own code snippets. Making so will hopefully help speed up collective community learning process with Magento eCommerce platform.

Duplicate a Product codewise

Public snippet   |  Code orientation PHP  |   Tested for Magento version 1.3.2.4 some times ints importent to dupe a product for some reasion here is the code for it cheers Pierre
<?php
	require_once 'app/Mage.php';
	umask(0);
	/* not Mage::run(); */
	Mage::app('admin');


	$product = Mage::getModel('catalog/product');
	$productId = $product->getIdBySku("testproduct");
	$product->load($productId);
	            
	$copy = $product->duplicate(); 
	$id_copy = $copy->getId();

	
	echo $id_copy;
	
	$copy = Mage::getModel('catalog/product')->load($id_copy); 
	$co

Dump a array as PHP code

Public snippet   |  Code orientation PHP  |   Tested for Magento version 1.3.2.4 No description given for this code snippet.
/**
 * Indents a string to given deep
 *
 * @param string $string string to indent
 * @param int    $level  depp of the indent
 *
 * @return string
 */
function indentString($string, $level)
{
    while($level) {
        $level--;
        echo "    ";
    }
    echo $string;
}

/**
 * dumps an Array as PHP code
 *
 * @param array $array array to dump
 * @param int   $level ind

Retrieve Order Information and Create XML

Public snippet   |  Code orientation PHP  |   Tested for Magento version 1.3.2.4 This is a method that we developed to handle custom integration with an inventory management system. This pulls all orders and processes them into an xml feed for processing by the inventory management system. Once it has passed the information it can optionally set each order to closed. Hopefully this helps you. If you want to submit me a note. please use the contact form at www.flintcreative.net
//External script - Load magento framework
       require_once("../app/Mage.php");
       Mage::app();

       /* function for adding new node to xml file  */

       function Add_NewDocElement($root, $parent, $name, $value){
       $parent->appendChild($root->createElement($name))->appendChild($root->createTextNode($value));
       }

#creating new xml-document
       $dom = new DomDoc

Manually create localized invoice and shipment of given order

Public snippet   |  Code orientation PHP  |   Tested for Magento version 1.3.2.4 if you want to load an order with status 'pending' or 'processing' and manually create an invoice and/or shipment, you first have to populate the store and locale information of the order store
// load order
$order = Mage::getModel('sales/order')->load($orderId);

// set store and locale according to order store
Mage::app()->setCurrentStore($order->getStoreId());
Mage::app()->getLocale()->emulate($order->getStoreId());

// create invoice and send email
if ($order->canInvoice()) {
    $invoice = $order->prepareInvoice();
    $invoice->register();
    $invoice->setEmailSent(true

Total snippets

135

Related stuff

Who's new

  • partychat
  • pkircher
  • kasn
  • madcad
  • Nate Flint
 
Magento Code Snippets by the developers for developers :)