Just another WordPress.com weblog

Archive for July, 2010

Magento Basics

Advertisements

Delete orders of particular customer in magento

Hello Everyone,

You can delete order of particular customer using below code .. You need to run below code in adminpanel.

<?php $order = Mage::getModel(‘sales/order’)->getCollection()
->addAttributeToFilter(‘customer_id’,’14’);//”14″ is a id of customer
print_r($order->count()); // It display no. of order place by customer whose id is ’14’
foreach ($order as $ord) {
echo $ord->getIncrementId() . ‘<br>’; //It display increment id of order
$ord->delete(); //This statement delete order
} ?>

I hope the above code is help you to delete sales order in magento

Thanks,
Bijal Bhavsar 🙂

Adding Free bundle product to cart when subtotal is equal or greater than N amount

Hello Guys & Gals,

I like to share some code for adding free product to cart when subtotal is greater or equal to N amount (Amount is define in Backend)

You have to add two fields in system->configuration->sales section, Check the code below to add fields:

Copy file from core :: YourProject/app/code/core/Mage/sales/etc/system.xml
Paste to Local:: YourProject/app/code/Local/Mage/sales/etc/system.xml
Open file:: Search for “</groups> </sales>” Add below code snippents before the search terms.


<offers translate="label">
<label>Offer Bundle Product Id</label>
<frontend_type>text</frontend_type>
<sort_order>20</sort_order>
<show_in_default>1</show_in_default>
<show_in_website>1</show_in_website>
<show_in_store>1</show_in_store>
<fields>
<bundle_product_id translate="label comment">
<label>Product Id Used in Offer</label>
<frontend_type>text</frontend_type>
<sort_order>1</sort_order>
<show_in_default>1</show_in_default>
<show_in_website>1</show_in_website>
<show_in_store>1</show_in_store>
</bundle_product_id>
<cart_subtotal translate="label comment">
<label>Cart Subtotal Used in bundle product Offer </label>
<frontend_type>text</frontend_type>
<sort_order>1</sort_order>
<show_in_default>1</show_in_default>
<show_in_website>1</show_in_website>
<show_in_store>1</show_in_store>
</cart_subtotal>
</fields>
</offers>

Clear cache from backend. And open System->configuration->sales:

There you can find 2 fields under “Offer Bundle Product Id” Add product id to “Bundle Product Id Used in Offer” field and subtotal amount to “Cart Subtotal Used in bundle product Offer “

After adding the above lines in system.xml open admin panel
Add below function in CartController.php

In function indexAction::search term ” foreach ($cart->getQuote()->getMessages() as $message) ” add below lines before search term

$this->addFreeProductToCart(); // This function is define below indexAction function to add free product to cart

Function defination of addFreeProductToCart

public function addFreeProductToCart()
{
$freeGiftProductId = Mage::getStoreConfig('sales/offers/bundle_product_id');
$freeGiftSubtotal = Mage::getStoreConfig('sales/offers/cart_subtotal'); //not including tax
static $lowStockWarningAmount = 5;
$freeGiftCartItemId = null;
$subtotal = 0;
if(($freeGiftProductId > 0) && ($freeGiftSubtotal >0)) {

foreach ($cart->getQuote()->getAllItems() as $item) {
if ($item->getProduct()->getId() == $freeGiftProductId) {
if ($item->getQty() > 1) {
$item->setQty(1);
$cart->save();
}
$freeGiftCartItemId = $item->getItemId();
$cart->getQuote()->setGiftCartItemId($freeGiftCartItemId);
}
}
$subtotal = $cart->getQuote()->getSubtotal();

if ($subtotal >= $freeGiftSubtotal) {
if(!$cart->getQuote()->getGiftCartItemId()){
$bundled_product = Mage::getModel('catalog/product')
->setStoreId(Mage::app()->getStore()->getId())
->load($freeGiftProductId);
if($bundled_product->isSaleable()) {

$bundled_items = array();
$bundled_options = array();
if($bundled_product->getTypeId() == 'bundle'){

$selectionCollection = $bundled_product->getTypeInstance(true)->getSelectionsCollection(
$bundled_product->getTypeInstance(true)->getOptionsIds($bundled_product), $bundled_product
);

$bundled_options['bundle_option']=array();

$i=1;

foreach($selectionCollection as $option)
{
if(sizeof($selectionCollection)>1){
$bundled_options['bundle_option'][1][$option->option_id] = $option->selection_id;
$i++;

$bundled_items[] = $option->product_id;
} else {
$bundled_options['bundle_option'][$option->option_id] = $option->selection_id;
}
}

$bundled_options['qty'] = 1;
}
$cart->addProduct($bundled_product,$bundled_options)->save();
$cart->getCheckoutSession()->addSuccess('Your free gift has been added to your cart .');
} else {
$cart->getCheckoutSession()->addError('The requested quantity for "'.$bundled_product->getName().'" is not available.');
}
}
} else {
//remove product if it is already there because the subtotal is less than the threshold
if ($freeGiftCartItemId != null) {
$cart->removeItem($freeGiftCartItemId)->save();
$cart->getQuote()->setGiftCartItemId(null);
$cart->getCheckoutSession()->addSuccess('Your free gift has been removed from your cart due to insufficient subtotal.');
}
}

}

I am very glad to share my knowledge. If you have any question you can add comment to this post.

Thanks,
Bijal Bhavsar 🙂

Magento :: Advanced search Not Working – Solved

Hi ,,

Magento Advanced Search is Not Working in magento 1.3.*..

Just Refresh .. Layered Navigation Indices from Cache Management..

Then also if its not working . try this..

in CatalogSearch/model/Advanced.php
in addFilters() ..
Comment these lines …

/*$indexFilters = Mage::getModel(‘catalogindex/indexer’)->buildEntityFilter(
$attributes,
$values,
$filteredAttributes,
$this->getProductCollection()
);
foreach ($indexFilters as $filter) {
$this->getProductCollection()->addFieldToFilter(‘entity_id’, array(‘in’=>new Zend_Db_Expr($filter)));
}*/

This is working fine for me … Hope this will helpful …

Thanks ..
Vishal Surani

Product wise Free Shipping Without Using Coupon

Product wise Free Shipping Without Using Coupon

1. Log into the backend of your site.
2. Go to Systems -> Configuration
3. On the tabs on the left, click "Shipping Methods"
4. Under "Free Shipping", set minimum shipping price to 9999999999.99. This way, its enabled but wont ever show up (unless someone buys 9999999999.99 worth of products from your store. In which case, set it so its not possible to reach the amount where free shipping would be allowed.
5. Save Config.

Now, onto setting up attributes and rules!

Steps:

1. Log into the backend of your site.
2. Go to Catalog -> Manage Products.
3. Select a product you want to edit. It doesn’t matter at this point.
4. On the top right, there will be a “Create New Attribute” button, click it. Hard.
5. Once you’re on the “Create Attribute” screen, you’ll want to fill it out. Here is what I have for reference
a. Attribute Code: free_shipping
b. Scope: Global
c. Catalog Input Type for Store Owner: Dropdown
d. Unique Value: No
e. Values Required: Yes
f. Input Validation for Store Onwner: None
g. Apply To: All Product Types
h. Use To Create Configurable Product: No
i. Use in Quick Search: No
j. Use in Advance Search: No
k. Comparable on Front End: No
l. Use in Layered Navigation: No
m. Visible on Catalog Pages on Front End: No
6. Once you’re done filling that information out, go to the Manage Label/Options side tab:
a. Now I don’t know what the fields under “Manage Titles” say, because they are just scrambled letters (thanks v1.1.1) but the first field is what is show next to the drop down box and shown when creating a coupon and stuff. So I went with “Free Shipping”.
b. Under the “Manage Options”, create two options. Again, I don’t know what the fields say (thanks v1.1.1). One should say “Yes” and the other should say “No”. Set the default to “No”
7. Save Attribute (button in upper right.)
8. Once that saves, go to Promotions -> Shopping Cart Price Rules.
9. Click the “Add New Rule” button on the upper right. Softly this time.
10. Here is the information I used as a reference
a. Rule Name: Free Shipping
b. Description: Free shipping on selected products.
c. Status: Active
d. Customer Groups: NOT LOGGED IN, GENERAL, WHOLESALE, RETAILER
e. Everything else I left blank/default.
11. The “Conditions” tab on the left should be left how it is. Skip over it and select the “Actions” tab
a. Apply: Percent of product price discount
b. Discount Amount: 0
c. Maximum Qty Discount is Applied to: 0
d. Discount Qty Step (Buy X): 0
e. Free Shipping: For Matching items only (IMPORTANT! If a user has multiple items in shopping cart, only the product with free shipping is free, and not everything in the cart.)
f. Stop Further Rules Processing: No
12. Here is the important part… the rules. Set this up like mine and you’ll be good:
a. If ANY of these conditions are TRUE:
b. Click the + and select the “Free Shipping” attribute you created earlier. Then click the “…” and select it as “Yes”
13. Save attribute!
14. Edit any product you like. ** IT MUST BE A SIMPLE PRODUCT **. At the very bottom of product information when youre under the "General" tab, there will be a Free Shipping* with a drop down box. Set the “Free Shipping” to “Yes”. Save it. Now act like you are buying the product you just updated and calculate shipping cost. If ground shipping says: $0.00, it work!

This also works with version 1.4

Thanks,
Bijal Bhavsar 🙂

Get Store Email address

Gerneral contact
Mage::getStoreConfig(‘trans_email/ident_gerneral/name’);
Mage::getStoreConfig(‘trans_email/ident_gerneral/email’);

Sales Representative
Mage::getStoreConfig(‘trans_email/ident_sales/name’);
Mage::getStoreConfig(‘trans_email/ident_sales/email’);

Customer Support
Mage::getStoreConfig(‘trans_email/ident_support/name’);
Mage::getStoreConfig(‘trans_email/ident_support/email’);

Custom email1
Mage::getStoreConfig(‘trans_email/ident_custom1/name’);
Mage::getStoreConfig(‘trans_email/ident_custom1/email’);

Custom email2
Mage::getStoreConfig(‘trans_email/ident_custom2/name’);
Mage::getStoreConfig(‘trans_email/ident_custom2/email’);

— Meghna Vora

Custom wysiwyg text blocks aren’t parsed for variables like {{media }} in magento 1.4

So far one big cause of the problem is that the configuration for the Wysiwyg on custom fields is different than that on CMS/Product Description fields. In particular the Varien Widget menu options are not included.

If these are missing then the bug is exposed, in js/mage/adminhtml/wysiwyg/tiny_mce/setup.js the beforeSetContent and saveContent methods incorrectly assume that widgets have to be configured before it will process directives.

beforeSetContent: function(o) {
o.content = this.encodeDirectives(o.content); //add
if(this.config.add_widgets) {
o.content = this.encodeWidgets(o.content);
//o.content = this.encodeDirectives(o.content); // removed
}
},

saveContent: function(o) {
o.content = this.decodeDirectives(o.content);//add
if(this.config.add_widgets) {
o.content = this.decodeWidgets(o.content);
//o.content = this.decodeDirectives(o.content); // removed
}
},

Still to do
1) you can still stuff things up if you show the editor, then press submit when its still showing – even though the saveContent method gets called it no longer functions correctly, so I suspect the wrong object is being passed to it in this sequence…this is where I’m currently stuck, any suggestions most welcome!
2) custom wysiwyg text blocks currently aren’t parsed for variables like {{media }} or {{skin }} so it needs to be generically extended to cope with that, or filtered in the .phtml file that renders it.
The filter for a custom attribute is of the form:


$_cmsHelper = Mage::helper('cms');
$_process = $_cmsHelper->getBlockTemplateProcessor();
echo $_process->filter($_product->getMyCustomAttribute()); //pass the variable which is use to display content of wysiwyg editor

Thanks,
Bijal Bhavsar 🙂