Delete test orders in Magento 1.4.x

7 11 2010

hay Friends,

Many of you must have noticed that Magento has brought much changes in it’s EAV based database structure in version Magento 1.4.x. Like they did for changes in order data storage, perhaps this decision is to reduce the over complex structrue.

When we are developing some Magento based project, we oftenly try to add test data to check whether everything is fine or not. Though we can delete this test data using delte option but if you added some test order then you are stucked as Magento don’t give any option to delete a record from Magento prompt. So solution in such cases is to go at database prompt and run queries to reset Magento. Following are few queries for the same purpose:

– Reset Magento TEST Data
SET FOREIGN_KEY_CHECKS=0;

– Reset dashboard search queries
TRUNCATE `catalogsearch_query`;
ALTER TABLE `catalogsearch_query` AUTO_INCREMENT=1;

– Reset sales order info
TRUNCATE `sales_flat_creditmemo`;
TRUNCATE `sales_flat_creditmemo_comment`;
TRUNCATE `sales_flat_creditmemo_grid`;
TRUNCATE `sales_flat_creditmemo_item`;
TRUNCATE `sales_flat_invoice`;
TRUNCATE `sales_flat_invoice_comment`;
TRUNCATE `sales_flat_invoice_grid`;
TRUNCATE `sales_flat_invoice_item`;
TRUNCATE `sales_flat_order`;
TRUNCATE `sales_flat_order_address`;
TRUNCATE `sales_flat_order_grid`;
TRUNCATE `sales_flat_order_item`;
TRUNCATE `sales_flat_order_payment`;
TRUNCATE `sales_flat_order_status_history`;
TRUNCATE `sales_flat_quote`;
TRUNCATE `sales_flat_quote_address`;
TRUNCATE `sales_flat_quote_address_item`;
TRUNCATE `sales_flat_quote_item`;
TRUNCATE `sales_flat_quote_item_option`;
TRUNCATE `sales_flat_quote_payment`;
TRUNCATE `sales_flat_quote_shipping_rate`;
TRUNCATE `sales_flat_shipment`;
TRUNCATE `sales_flat_shipment_comment`;
TRUNCATE `sales_flat_shipment_grid`;
TRUNCATE `sales_flat_shipment_item`;
TRUNCATE `sales_flat_shipment_track`;
TRUNCATE `sales_invoiced_aggregated`;
TRUNCATE `sales_invoiced_aggregated_order`;
TRUNCATE `sales_order_aggregated_created`;
TRUNCATE `sendfriend_log`;
TRUNCATE `tag`;
TRUNCATE `tag_relation`;
TRUNCATE `tag_summary`;
TRUNCATE `wishlist`;
TRUNCATE `log_quote`;
TRUNCATE `report_event`;
ALTER TABLE `sales_flat_creditmemo` AUTO_INCREMENT=1;
ALTER TABLE `sales_flat_creditmemo_comment` AUTO_INCREMENT=1;
ALTER TABLE `sales_flat_creditmemo_grid` AUTO_INCREMENT=1;
ALTER TABLE `sales_flat_creditmemo_item` AUTO_INCREMENT=1;
ALTER TABLE `sales_flat_invoice` AUTO_INCREMENT=1;
ALTER TABLE `sales_flat_invoice_comment` AUTO_INCREMENT=1;
ALTER TABLE `sales_flat_invoice_grid` AUTO_INCREMENT=1;
ALTER TABLE `sales_flat_invoice_item` AUTO_INCREMENT=1;
ALTER TABLE `sales_flat_order` AUTO_INCREMENT=1;
ALTER TABLE `sales_flat_order_address` AUTO_INCREMENT=1;
ALTER TABLE `sales_flat_order_grid` AUTO_INCREMENT=1;
ALTER TABLE `sales_flat_order_item` AUTO_INCREMENT=1;
ALTER TABLE `sales_flat_order_payment` AUTO_INCREMENT=1;
ALTER TABLE `sales_flat_order_status_history` AUTO_INCREMENT=1;
ALTER TABLE `sales_flat_quote` AUTO_INCREMENT=1;
ALTER TABLE `sales_flat_quote_address` AUTO_INCREMENT=1;
ALTER TABLE `sales_flat_quote_address_item` AUTO_INCREMENT=1;
ALTER TABLE `sales_flat_quote_item` AUTO_INCREMENT=1;
ALTER TABLE `sales_flat_quote_item_option` AUTO_INCREMENT=1;
ALTER TABLE `sales_flat_quote_payment` AUTO_INCREMENT=1;
ALTER TABLE `sales_flat_quote_shipping_rate` AUTO_INCREMENT=1;
ALTER TABLE `sales_flat_shipment` AUTO_INCREMENT=1;
ALTER TABLE `sales_flat_shipment_comment` AUTO_INCREMENT=1;
ALTER TABLE `sales_flat_shipment_grid` AUTO_INCREMENT=1;
ALTER TABLE `sales_flat_shipment_item` AUTO_INCREMENT=1;
ALTER TABLE `sales_flat_shipment_track` AUTO_INCREMENT=1;
ALTER TABLE `sales_invoiced_aggregated` AUTO_INCREMENT=1;
ALTER TABLE `sales_invoiced_aggregated_order` AUTO_INCREMENT=1;
ALTER TABLE `sales_order_aggregated_created` AUTO_INCREMENT=1;
ALTER TABLE `sendfriend_log` AUTO_INCREMENT=1;
ALTER TABLE `tag` AUTO_INCREMENT=1;
ALTER TABLE `tag_relation` AUTO_INCREMENT=1;
ALTER TABLE `tag_summary` AUTO_INCREMENT=1;
ALTER TABLE `wishlist` AUTO_INCREMENT=1;
ALTER TABLE `log_quote` AUTO_INCREMENT=1;
ALTER TABLE `report_event` AUTO_INCREMENT=1;
SET FOREIGN_KEY_CHECKS=1;

Hope this information was helping!





Magento :: get URL paths for skin, media, Js OR base URL

12 05 2010

hello friends,

If anyone of you facing problems to fetch the Magento URL paths of  skin, media, Js or simple base URL of Magento while customization/programming, then following lines should be helpful for you:

Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_JS);
//http://magento.demo/js/

Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_LINK);
//http://magento.demo/index.php/

Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_MEDIA);
//http://magento.demo/media/

Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_SKIN);
//http://magento.demo/skin/

Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_WEB);
//http://magento.demo/

Enjoy!





Magento :: add or remove javascript files to your template

25 03 2010

Following  lines will be helping for you if you’r trying to add some javascript file to your custom theme. As per your requirements, you’ll need to see in which layout file you want to call your js file and simply put this line there:
<action method=”addItem”><type>skin_js</type><name>js/product.js</name></action>

Above line will try to find the product.js file under /skin/frontend/default/Your_Theme/js /product.js

Similarly you can remove a default javascript file by putting this line in your layout file:

<action method=”removeItem”>   <type>js</type>   <name>varien/product.js</name>   <params />   </action>

Hope this will be helping someone for fighting against Magento.





J2T Points & Rewards :: Step by step configurations

16 03 2010

hello,

“J2T Points & Rewards” is a big and FREe extension for Magento based e-commerce stores where Discounts are rewarded to customers on the basis of amount that they spent to buy from the store. In short, this is a Points and Reward system for a magento based store.

I really faced hard time to see some step by step manual to configure this extension but got no luck. Eventually i was able to configure it successfully with the help of some community mates (thanks to them) so thought to share. Here it is:

Step1: Disable your Cache.
Step2: Make sure you have copied the template and layout files of this extension under the active template of store.

Step3: Go in Reward points > Configurations and make following settings (you may set it according to your business logic too):
money to obtain: 1
points to obtain 1: 100
apply points by step: no
leave step value blank
use max points: no
round up points: no
coupon code restriction: yes
apply store scope: yes

Step4: Go Promotions –> Shopping cart price rules and add a shopping cart price rule with following settings:
rule name: points
customer group: general
coupon code: points
under action tab have the “fixed amount discount for entire cart”

Step4: Go catalog –> attributes –> manage attribute
create ‘reward_points’
scope: global
apply to: all product types
Use for Price Rule Conditions: yes
Allow HTML-tags on Front-end: yes

That’s it! After these settings are done, you’ll be able to see these effects:

– Reward points section is being shown in Customer Account area.
– Logged in User is given an option to redeem the points on shopping cart page.
– discount is applied on shopping cart

Hope it will be helping for someone.





Magento::calling a static block in your template file (.phtml)

17 02 2010

To call a static block in Magento, Following single line will solve your problem,

<?php getLayout()->createBlock('cms/block')->setBlockId('my_static_block_name')->toHtml() ?>

Definitely we’ll write this line in some .phtml file for which you want to call this block …

Hope this tip will be helping for someone ;)





Magento: retrieve base url path

20 05 2009

If you are working in Magento and trying to find the base URL path for your Magento installation then you must use try this line of code:
echo Mage::getBaseUrl();

It will fairly return you the base path Url. Hope this tip will help someone :) .





Magento::Change page Title of Magento Module

23 02 2009

hello friends,

While working on a Megento project, i got a scenario to set Title of my custom Module’s pages. I’ll try to provide the solution here. Note one thing, you may implement this solution to change the Title of any Core Module of Magento so I’ll refer to general file paths here.

Solution:
open this file in your Magenot installation:  “app/design/frontend/[your_name_space]/['your_theme']/layout/['your_module_name'].xml”
(If you haven’t created any name space then your path must be like: “app/design/frontend/Default/['your_theme']/layout/['your_module_name'].xml”)

Suppose, if  you want to change the title of ‘contacts’ module, you can find Xml file on this path : “app/design/frontend/default/default/layout/contact.xml”.

then modify your contact.xml file like this image. Notice the new code that is encircled in it.

helping image

helping image





Zend Framework: File upload using Zend_Form_Element_File

17 02 2009

hello All ,

This post will be helpful for all people who are wishing to get some practicle example for using ‘Zend_Form_Element_File’ of Zend framework’s ‘Zend_Form’.
There will 3 steps to implement it:

  1. Create form with ‘enctype’ set to ‘multipart/form-data’ using Zend_Form
  2. Create File upload box using Zend_Form_Element_File
  3. Upload the file on server and get uploaded file’s detail for saving in database

So Let’s explore these steps one by one:

Step 1: Create form with ‘enctype’ set to ‘multipart/form-data’ using Zend_Form

Setting Form ‘enctype’ to ‘mutipart/form-data’ in Zend framework appears difficult if you don’t know about it. In real it is very simple if you ever got a chance to observe setAttrib() function for setting attributes of any element. Lemme give you an example.

(For example, i am creating ‘DocumentForm’ Class that will handle Document uploading Form)

First thing that you’ll need is to set Zend_Form’s ecryption type to ‘multipart/form-data’. This is must for file uploading.
So here it goes ..

class DocumentForm extends Zend_Form
{
    public function __construct($options = null)
    {
	parent::__construct($options);
  	// setting Form name,Form action and Form Ecryption type
	$this->setName('document');
	$this->setAction("");
	$this->setAttrib('enctype', 'multipart/form-data');
    }
}

Above code will create a form named ‘document’ with encryption type ‘multipart/form-data’. Now lets move to next step.

Step2: Create File upload box using Zend_Form_Element_File

You may notice some new code in Bold here:

class DocumentForm extends Zend_Form
{
	 public function __construct($options = null)
	 {
		 parent::__construct($options);
		 // setting Form name, Form action and Form Ecryption type
		 $this->setName(’document’);
		 $this->setAction(”");
		 $this->setAttrib(’enctype’, ‘multipart/form-data’);
		 
		 // creating object for Zend_Form_Element_File
		 $doc_file = new Zend_Form_Element_File(’doc_path’);
		 $doc_file->setLabel(’Document File Path’)
				  ->setRequired(true);

		 // creating object for submit button
		 $submit = new Zend_Form_Element_Submit(’submit’);
		 $submit->setLabel(’Upload File’)
				 ->setAttrib(’id’, ’submitbutton’);

		// adding elements to form Object
		$this->addElements(array($doc_file, $submit));
	 }
}

Bold lines in above code will populate a File Element along with a Submit button on Form.

Now user will select the file for uploading and press the Submit button,so here comes our step 3.

Step 3: Upload the file on server and get uploaded file’s detail for saving in database

This is last but most important step of the process that saves the file on server and returns back file upload details. Above Form will be called by some Controller’s Action so here comes my Controller and Action that will show and handle this form.

class DocumentForm extends Zend_Form
{
 function addAction()
 {
 $form = new DocumentForm();
 $this->view->form = $form;

 if ($this->_request->isPost()) {

 $formData = $this->_request->getPost();
 if ($form->isValid($formData)) {

 /* Uploading Document File on Server */
 $upload = new Zend_File_Transfer_Adapter_Http();
 $upload->setDestination("/uploads/files/");
 try {
 // upload received file(s)
 $upload->receive();
 } catch (Zend_File_Transfer_Exception $e) {
 $e->getMessage();
 }

 // so, Finally lets See the Data that we received on Form Submit
 $uploadedData = $form->getValues();
 Zend_Debug::dump($uploadedData, 'Form Data:');

 // you MUST use following functions for knowing about uploaded file 
 # Returns the file name for 'doc_path' named file element
 $name = $upload->getFileName('doc_path');

 # Returns the size for 'doc_path' named file element 
 # Switches of the SI notation to return plain numbers
 $upload->setOption(array('useByteString' => false));
 $size = $upload->getFileSize('doc_path');

 # Returns the mimetype for the 'doc_path' form element
 $mimeType = $upload->getMimeType('doc_path');

 // following lines are just for being sure that we got data
 print "Name of uploaded file: $name 
";
 print "File Size: $size 
";
 print "File's Mime Type: $mimeType";

 // New Code For Zend Framework :: Rename Uploaded File
 $renameFile = 'newName.jpg';

 $fullFilePath = '/images/'.$renameFile;

 // Rename uploaded file using Zend Framework
 $filterFileRename = new Zend_Filter_File_Rename(array('target' => $fullFilePath, 'overwrite' => true));

 $filterFileRename -> filter($name);

 exit; 
 } 

 } else {

 // this line will be called if data was not submited
 $form->populate($formData);
 }
 }
}

and thats it!

please let me know if you guys feel anything more to add in it. :) For more advancements in above code, please see the File upload manual here: http://zendframework.com/manual/en/zend.file.html




Zend_Form_Element_Multiselect :: ’121′ was not found in haystack

19 01 2009

Hello Friends,

While working with Zend_Form, i came accross a problem that realy made me to pull up my hair.
I was simply using Zend_Form_Element_Select to show drop down menue in form. I got following message when i submited my form :

’121′ was not found in haystack

Apprently this message was because of some pre-set ‘validator’ as i enabled no validator for this select box. Following code i used to generate select box that generated above message:

$pCatg = array(121,123);
$arrList = array("name1"=>"name1", "name2"=>"name2", "name3"=>"name3");
$catg = new Zend_Form_Element_Multiselect('category_id');
$catg->setLabel('Category')
->setMultiOptions($arrList)
->setValue($pCatg)
->setDecorators($this->decorator);

Following Html code was generated by above code:

<select name=”test” id=”test”>
<option value=”121″ label=”name1″>name1</option>
<option value=”122″ label=”name2″>name2</option>
<option value=”123″ label=”name3″>name3</option>
</select>

Reason of Problem :

As you can see above that i haven’t used any Validator for this drop down menu, so that brought the problem. Actualy InArray validator is enabled automatically if validator was not present

Solution of Problem :

$pCatg = array(121,123);
$arrList = array(“name1″=>”name1″, “name2″=>”name2″, “name3″=>”name3″);
$catg = new Zend_Form_Element_Multiselect(‘category_id’);
$catg->setLabel(‘Category’)
->setMultiOptions($arrList)
->setValue($pCatg)
->setRegisterInArrayValidator(false)
->setDecorators($this->decorator);

So,
solution was just to set ‘setRegisterInArrayValidator(false)’,

Hope it may help someone,
Thanks





Zend Form :: ‘Multiple Select box’ and ‘Option Group’

15 01 2009

Hello Friends,

Multiple Select box in Zend Form using Zend Framework:
I got a scenario in which i was to put drop down with ‘multiple’ option enabled. I am using Zend_Form so  definatley i was in search of some Zend framework provided controll to create it,
i found following  way to create ‘Multiple Select box’ using Zend_Form in Zend framework:

$techDoc = new Zend_Form_Element_Multiselect(‘docs’);
$techDoc->setLabel(‘Technical Documents’)
->setMultiOptions(array(“1″=>”option1″ ,”2″=>”option2″));
$techDoc->size = 5;
I used  Zend_Form_Element_Multiselect to creat ’Multiple Select box’ so it is very simple ;) .

First parameter ( $techDoc->setLabel ) will set the Lable of this drop down and second parameter setMultiOptions expects [Associative] array of options that this drop down will have.

Last thing was $techDoc->size that helps to choose size of this Multiple select box.

In following  section, i’ll enhance this example and will try to explain how i achieved ‘Option Group’ in multiselect drop down. (you may also use the following scenario to create ‘Option Group’ in Zend_Form_Element_select that creates simple drop down)

Multiple Select box with ‘Option Group’:

$techDoc = new Zend_Form_Element_Multiselect(‘technical_doc’);
$techDoc->setLabel(‘Technical Documents’)
->setMultiOptions(array(“Option Group 1″ => array(“option1″,”option2″,”option3″),
“Option Group 2″=>array(“option1″,”option2″,”option3″)));
$techDoc->size = 5;

so Array of associative arrays generate ‘Option Group’ that was looking very hard to me :) ,

Hope you’ll find it inofrmative …








Follow

Get every new post delivered to your Inbox.