remove particular order status from list in magento - magento

I am using extension
http://www.magentocommerce.com/magento-connect/eitai2001/extension/1468/order-status/reviews#reviews
of magento which provide a lot of order status..but my need is limited ..so i want to remove some status from my order-status list... how can i do this..please help
Thanks!
Edited
I made change in config.xml
If I comment any order-status ... like this
<!--<processing_cc_settled translate="label"><label>Processing - Credit Card has been Settled</label></processing_cc_settled>-->
but in combobox(where status shows in admin site )still processing_cc_settled appears at the same place where Processing - Credit Card has been Settled showing up before commenting

If this is the same extension that I have seen installed one client's site then it should have a config.xml file included in its /etc subdirectory (NOTE: not the global /app/etc but somwhere in the /app/code/community/ folder). In this file you will find definitions for all the additional statuses. Just comment out the ones you don't want. You can also change the ones that you leave so that they are better suited to your needs.
CLARIFICATION:
Here's a piece of my config.xml:
<config>
<modules>
<Mage_Sales_Community>
<version>0.1.2</version>
</Mage_Sales_Community>
</modules>
<global>
<sales>
<order>
<statuses>
<!--Complete Status Descriptions-->
<complete translate="label"><label>Dispatched</label></complete>
<!--Cancelled Status Descriptions-->
<canceled translate="label"><label>Suspended</label></canceled>
<!--<canceled_discontinued translate="label"><label>Suspended - No stock</label></canceled_discontinued> -->
<!-- /* Additional custom statuses will go here */ -->
<!-- Format of a status description is <name_of_status translate="label"><label>Name of Status</label?</name_of_status> -->
</statuses>
</order>
</sales>
</global>
</config>
Note that complete and canceled have a different label defined. There is also a canceled_discontinued status, but it is not used as the whole entry is commented out. If the entry stays on the order comments dropdown after you have commented it make sure that you have refreshed the cache...

I add/remove magento statuses in install scripts, using something like below:
<?php
$installer = $this;
/*
Possible states:
Mage_Sales_Model_Order::STATE_CANCELED
Mage_Sales_Model_Order::STATE_CLOSED
Mage_Sales_Model_Order::STATE_COMPLETE
Mage_Sales_Model_Order::STATE_HOLDED
Mage_Sales_Model_Order::STATE_NEW
Mage_Sales_Model_Order::STATE_PAYMENT_REVIEW
Mage_Sales_Model_Order::STATE_PENDING_PAYMENT
Mage_Sales_Model_Order::STATE_PROCESSING
*/
$installer->startSetup();
// Get status model
$status = Mage::getModel('sales/order_status');
// Delete some statuses
$status->setStatus('processing_cc_settled')->delete();
$status->setStatus('another_status_code_to_delete')->delete();
//Add a new status
$status->setStatus('holded_cc_error')
->setLabel('On Hold: CC Error')
->assignState(Mage_Sales_Model_Order::STATE_HOLDED)
//for example, use any available existing state from above
->save();
//To set an order to this status:
//$order->setData('state', "holded");
//$order->setStatus("holded_cc_error");
//$order->save();
$installer->endSetup();

Related

Magmi url_key slug - how to include sku?

I'm trying to figure out the best course of action to change URL keys in the store to be name-sku.html
Currently MAGMI seems to be dictating the url key, which is fine. Some of our products are not imported through MAGMI, so I think I'd probably have to also use the updateurl event to change the url on save -- I found this here for that -- https://magento.stackexchange.com/questions/24869/manufacturer-in-product-url-key
The question is, how is it best to do this within MAGMI? I'm importing about 300,000 products currently. The URL also needs to change, as it currently just uses the default settings.
I've looked into the wiki here -- http://wiki.magmi.org/index.php?title=Value_Replacer -- I guess the following code could work for the way it is currently working -- but what do I actually type into the value replacer box?
{{ Slugger::slug({item.name}) }}
Does anyone know how to add the sku to this as well? Would I just do something like....
{{ Slugger::slug({item.name} ."-". {item.sku}) }}
Also, does anyone know if this automatically adds the dashes and the .html?
Any guidance would be extremely appreciated.
EDIT:
I have successfully tested this as working in my test environment, but it is not working as expected in my production environment. I'll go over what happens, and what I did.
1) I purged the core_url_rewrite table
2) I deleted all cache
3) I set up MAGMI (updated it to the most current version as well, and triple checked all my settings)
4) MAGMI went through fine, and the url key on about 5 products that I checked for were how I would expect
5) During the catalog url rewrites reindex, all url keys disappeared.
6) After the reindex was done, they were now in the default magento format (using just the name, and not the sku)
Any ideas?
The only difference between production and development that I can think of at the moment that may have anything to do with this is the fact that I did create a module based on the linked manufacturer-in-product-url-key question on production. Now that I think of it, maybe that's the main difference that I need to address..... I didn't think reindexing would have anything to do with that, but maybe I'm wrong.
Anyway, if anyone has any insight, I would still appreciate it. I have a feeling maybe MAGMI should also be rewriting the url_path?? I think I read something about that somewhere.
Ok, I figured this out. I think this is the best approach.
I was mistaken in my question. I'm actually looking to add the mpn, not the sku. Either way, that doesn't change the process.
So, the best thing to do is to use the Value Replacer in MAGMI, and to create a custom module that updates the url on the Magento catalog_product_save_before event.
Here's exactly what I did.....
MAGMI settings (Value Replacer)
Replaced attributes: url_key
New value for url_key: {{ Slugger::slug({item.name}.' '.{item.mpn}) }}
URLKeyChange (Magento Module)
app/code/local/My/URLKeyChange/etc/config.xml
<config>
<global>
<models>
<LeathornURLRewrite>
<class>Leathorn_URLKeyChange_Model</class>
</LeathornURLRewrite>
</models>
<events>
<catalog_product_save_before>
<observers>
<LeathornURLRewrite>
<type>singleton</type>
<class>LeathornURLRewrite/observer</class>
<method>updateurl</method>
</LeathornURLRewrite>
</observers>
</catalog_product_save_before>
</events>
</global>
</config>
app/code/local/My/URLKeyChange/Model/Observer.php
class My_URLKeyChange_Model_Observer {
public function updateurl($observer){
Mage::log('My log entry', null, 'mylogfile.log');
if($observer->getEvent()->getProduct()){
$Product=$observer->getEvent()->getProduct();
$Url='';
if(!is_null($Product->getData('name'))):
$Url=$Url.$Product->getData('name');
endif;
if(!is_null($Product->getData('mpn'))):
$Url=$Url.$Product->getData('mpn').'-';
endif;
//Mage::log('My log entry'.$Url, null, 'mylogfile.log');
$Product->setData('url_key',$Url);
}
}
}
app/etc/modules/My_URLKeyChange.xml
<config>
<modules>
<My_URLKeyChange>
<!-- Whether our module is active: true or false -->
<active>true</active>
<!-- Which code pool to use: core, community or local -->
<codePool>local</codePool>
</My_URLKeyChange>
</modules>
</config>
URL key will always be just dash separated strings. Don't worry, magento will add .html in it dynamically. You can see in magnento backend in any product configuration page, url key is without html.
Also magento will add dash in url key, Replace your "-" by space " ". Otherwise it will take last word of name and SKU as one word. :)

How to sell coupoun code in magento?

How to sell a coupon code in magento.
The coupon code that can be gift to a friend, so that he can buy products with that code?
Log in to Magento Admin.
Click on Promotions –> Shopping Cart Price Rule.
On Right side click on Add new rule.
Fill in the fields be sure to give the rule a Name and Description and decide whether or not you are choosing ALL Customer groups or not.
In the General Information page in the coupon menu, select the Specific Coupon option.
Enter a code in the coupon code field (can be letters or numbers).
In the Uses Per Coupon field, specify the number of times a customer can use this coupon code if you would like to provide a limit. If not, leave blank.
In the Uses Per Customer field, specify the number of times a customer can use this promotion if you would like to provide a limit. If not, leave blank.
In the From/To Date menu, select a time frame for your coupon if you would like to provide one. If not, leave blank.
IDEA:
create coupon rule with auto generated coupons
create specific controller which will generate coupon and display it to customer
create downloadable product with link to our controller
NOTE
THIS IS MY FIRST INITIAL IDEA AND I'M NOT SURE IF IT IS PROPER SOLUTION.
I've never dealt with downloadable products before.
FIRST STEP CREATE COUPONS
When adding new rule to Shopping Cart Price Rules fill all required fields, remember to select appropriate customer groups (include NOT LOGGED IN if coupon should be available for guest customers).
Then, in Coupon select Specific Coupon, and select Use Auto Generation in checkbox below. Uses per Coupon set to 1. You can also set time limit if you want to.
Then save.
After saving new tab will appear on the left: Manage Coupon Codes.
There you can generate many coupon codes by setting qty (amount of coupons to generate), code length, code format (letters and digits, letters, only digits), code prefix and/or suffix, and if to include dash every x characters.
Remember code length applies only to generated part without dashes, prefix or suffix.
You don't need to generate anything yet, I'm just explaining some properties which I will refer to later on.
SECOND STEP PREPARE MODULE
Create path app/code/local/Example/Coupon, and two directories there etc and controllers.
In etc create config.xml
<?xml version="1.0"?>
<config>
<modules>
<Example_Coupon>
<version>0.1</version>
</Example_Coupon>
</modules>
<global>
</global>
<frontend>
<routers>
<example_coupon>
<use>standard</use>
<args>
<module>Example_Coupon</module>
<frontName>mycoupon</frontName>
</args>
</example_coupon>
</routers>
</frontend>
</config>
Then IndexController.php in controllers:
<?php
class Example_Coupon_IndexController extends Mage_Core_Controller_Front_Action {
const RULE_ID = 4;
public function indexAction() {
$rule = Mage::getModel('salesrule/rule')->load(self::RULE_ID);
$generator = Mage::getModel('salesrule/coupon_massgenerator');
$generator->setFormat(Mage_SalesRule_Helper_Coupon::COUPON_FORMAT_ALPHANUMERIC);
$generator->setDash(false);
$generator->setLength(6);
$generator->setPrefix('EX');
$rule->setCouponCodeGenerator($generator);
$rule->setCouponType(Mage_SalesRule_Model_Rule::COUPON_TYPE_AUTO);
$coupon = $rule->acquireCoupon();
$code = $coupon->getCode();
$coupon->setType(Mage_SalesRule_Helper_Coupon::COUPON_TYPE_SPECIFIC_AUTOGENERATED)->save();
die($code);
}
}
Here actual coupon is being generated and saved (upon requesting our custom url). Note that here all properties of code are defined (described above). You should edit this to suit your needs.
You can access this by visiting http://www.yourstore.com/mycoupon/index
Finally you need to enable module in etc/app/modules
create Example_Coupon.xml
<?xml version="1.0"?>
<config>
<modules>
<Example_Coupon>
<active>true</active>
<codePool>local</codePool>
</Example_Coupon>
</modules>
</config>
THIRD STEP ADD DOWNLOADABLE PRODUCT
I'm not going to cover all the details here, there is a good tutorial: https://www.hostknox.com/tutorials/magento/downloadable-products
What you finally need to do is to provide previously generated url as an downloadable link: http://www.yourstore.com/mycoupon/index
ISSUES
It works, but:
There is no validation whatsoever if customer have all rights to download this coupon or not. I'm not sure, maybe magento covers this or maybe not. There is an option to disable sharing in magento, so I would expect magento to hide this final url from customer.
You would probably need to expand my example module, because there should be downloadable file at the end - most likely some kind of PDF. Not simply echoing new generated coupon.
This file should be stored somewhere on disk, and served again upon request from same customer and same order.

Magento observer throwing error

I'm attempting to subscribe to the sales_order_place_after observer in Magento so that I can output order data. Unfortunately, anytime I try to log output to Mage::log, print_r, or even var_dump, I receive a User Error: Some transactions have not been committed or rolled back error.
It's probably also important to note that I'm using one step checkout and the checkout usually hangs (confirmation email still comes through). Shortly after the hang, I receive a PHP Fatal error: Allowed memory size of 268435456 bytes exhausted (tried to allocate 234881024 bytes) error. Can't seem to track down where or what is causing the memory leak... but it this error is only spit out if I am trying to output data.
config.xml
<?xml version="1.0" encoding="UTF-8"?>
<config>
<modules>
<InfinitelyWhite_OrderEvent>
<version>0.0.1</version>
</InfinitelyWhite_OrderEvent>
</modules>
<!-- Configure our module's behavior in the global scope -->
<global>
<!-- Defining models -->
<models>
<!--
Unique identifier in the model's node.
By convention, we put the module's name in lowercase.
-->
<infinitelywhite_orderevent>
<!--
The path to our models directory, with directory
separators replaced by underscores
-->
<class>InfinitelyWhite_OrderEvent_Model</class>
</infinitelywhite_orderevent>
</models>
<events>
<sales_order_place_after>
<observers>
<infinitelywhite_orderevent>
<class>infinitelywhite_orderevent/observer</class>
<method>exportNewOrder</method>
<type>singleton</type>
</infinitelywhite_orderevent >
</observers>
</sales_order_place_after>
</events>
</global>
Observer.php
class InfinitelyWhite_OrderEvent_Model_Observer
{
/**
* Magento passes a Varien_Event_Observer object as
* the first parameter of dispatched events.
*/
public function exportNewOrder(Varien_Event_Observer $observer)
{
Mage::log('reached export_new_order');
$order = $observer->getOrder();
Mage::log($order->getData());
return $this;
}
}
Any help would be greatly appreciated.
Nick Parson .....please removed singleton
<type>singleton</type>
Turns out the error was coming up because I was attempting to pull order information with $observer->getOrder(), when the correct approach is to use $observer->getEvent()->getOrder(). I was simply missing the getEvent().
I'm now able to extract data like so:
$order = $observer->getEvent()->getOrder();
$billing = $order->getBillingAddress();
$shipping = $order->getShippingAddress();
$customer = $order->getCustomer();
And then I can do something like:
$order->getData() or $customer->getData()
It's also important to note that because I switched up my observer event and I'm not using sales_model_service_quote_submit_success which stopped the nasty User Error: Some transactions have not been committed or rolled back error.
Can't comment yet, but what happens if you disable your observer? (Just to make sure it is the observer causing this issue).
If it is the observer, you could try replacing $order->getData() with $order->debug() and see if that helps

Magento Observer Destination

I have wrote 2 Magento observers and they both do exactly what I want with the exception that they end on the wrong page. In other words, they write the log files, modify the databases, and talk with other servers, but they modify the page to page routing. For example, I have an observer that I used at login that modifies a database, writes a cookie, and writes to a log, but it changes the post log-in page to
http://www.my-web-site.com/index.php/customer/login/post/
and then gives me a 404 error. If I hit "Ctrl" + 'r' then I am logged in at
http://www.my-web-site.com/index.php/customer/account/index/
which is correct. If I change, app/code/local/my_module/my_model/etc/config.xml to
app/code/local/my_module/my_model/etc/config.xml.1 (in other words take out the observer), then Magento routes to the correct page,
I'm thinking that I need router information in config.xml. My current config.xml is:
<?xml version="1.0" encoding="UTF-8"?>
<!-- The root node for Magento module configuration -->
<config>
<!-- The module's node contains basic information about each Magento module -->
<modules>
<!-- This must exactly match the namespace and module's folder
names, with directory separators replaced by underscores -->
<MyCompany_LogIn>
<!-- The version of our module, starting at 0.0.0 -->
<version>0.0.0</version>
</MyCompany_LogIn>
</modules>
<!-- Configure our module's behavior in the global scope -->
<global>
<!-- Defining models -->
<models>
<!-- Unique identifier in the model's node.
By convention, we put the module's name in lowercase. -->
<mycompany_login>
<!-- The path to our models directory,
with directory separators replaced by underscores -->
<class>MyCompany_LogIn_Model</class>
</mycompany_login>
</models>
</global>
<frontend>
<!-- Defining an event observer -->
<events>
<!-- The code of the event we want to observe -->
<customer_login>
<!-- Defining an observer for this event -->
<observers>
<!-- Unique identifier within the catalog_product_save_after node.
By convention, we write the module's name in lowercase. -->
<mycompany_login>
<!-- The model to be instantiated -->
<class>mycompany_login/observer</class>
<!-- The method of the class to be called -->
<method>wrtLogInCookie</method>
<!-- The type of class to instantiate -->
<type>singleton</type>
</mycompany_login>
</observers>
</customer_login>
</events>
</frontend>
</config>
I'm guessing that the login inside Magento uses an observer, and I'm interfering with it.
Besides the , I'm guessing that I could also accomplish a similar thing in the PHP Observer code. My observer is:
<?php
/**
* Our class name should follow the directory structure of
* our Observer.php model, starting from the namespace,
* replacing directory separators with underscores.
* i.e. /www/app/code/local/MyCompany/LogIn/Model/Observer.php
*/
class MyCompany_LogIn_Model_Observer extends Varien_Event_Observer
{
/**
* Magento passes a Varien_Event_Observer object as
* the first parameter of dispatched events.
*/
public function wrtLogInCookie(Varien_Event_Observer $observer)
{
// Retrieve the product being updated from the event observer
$customer = $observer->getEvent()->getCustomer();
$email = $customer->getEmail();
Mage::log('The E-mail is: ' . $email);
$ran_nmbr = rand();
Mage::log('The random number is: ' . $ran_nmbr);
$crnt_dat = date("m-d-Y::H:i:s");
Mage::log('The date is: ' . $crnt_dat);
return $this;
}
}
?>
I have read about routers, but the articles discussed it in terms of landing on some page before the extension is executed. As you can see, I need to land on the right page after the extension is executed.
Inside the PHP observer, I also tried redirects. For example,
Mage::app()->getResponse()->setRedirect(Mage::getUrl('customer/account/login'));
Maybe I need a full URL address or something. I'm sure this is easy to fix, but my ignorance seems to be following me around. Please help if you know something about this.
Unfortunately, it's not quite as simple as an easy fix. You see, if we look at app/code/core/Mage/Customer/controllers/AccountController.php, in the loginPostAction(), we see that the customer/session singleton triggers the customer_login call. However, what is causing the trip-up here is that after that is called, back in the controller, the controller calls $this->_loginPostRedirect(), so all of your rerouting work that you did is overwritten.
How to fix:
After saying it isn't all that simple, I did happen to see a cheat that we can take advantage of:
$session = Mage::getSingleton('customer/session');
$session->setBeforeAuthUrl($forwardToUrl);
You're partially right. The problem you're running into is Magento's redirect mechanism works with a "last one to say something" wins philosophy. If you look at the standard login code in
app/code/core/Mage/Customer/controllers/AccountController.php
You'll see the loginPostAction method ends with a call to
$this->_loginPostRedirect();
which (ultimately) ends up calling some code that looks like this
$this->getResponse()->setRedirect($url);
This may be the code that's causing you a problem, or it may be something else. The general problem is the final call to the response object's setRedirect method will win.
My usual solution to this is setting some sort of global flag (static variable on a class, a flag set with Mage::register) when I want to perform a redirect, and then creating an additional observer for controller_action_postdispatch. In this observer I look for the global flag I set, and if I find it, set the redirect there.
This handled 99% of redirect situations, and should handle yours. The times this won't work are with some admin login cases, as well as URL rewrites.
The admin login contains some redirect code that doesn't use Magento response object
#File: app/code/core/Mage/Admin/Model/Session.php
...
header('Location: ' . $requestUri);
exit;
...
If this redirect is causing you a problem, create a listener for admin_session_user_login_success that uses PHP header redirects before Magento's does.
Similarly, if Magento's using a rewrite object, the following code might run
#File: app/code/core/Mage/Core/Model/Url/Rewrite.php
if ($isPermanent) {
header('HTTP/1.1 301 Moved Permanently');
}
header('Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0');
header('Pragma: no-cache');
header('Location: ' . $url);
exit;
(that said, the rewrite code will rarely be your problem, as in standard Magento operation is runs before controller dispatch)

How can I change the order life cycle in Magento?

I’m new to magento and as far as I can see, the order states are labeled as "pending", "processing" and "completed". When customer checks out, then the state becomes "pending", and either invoicing or shipping makes the state "processing", and when both are done, state becomes "completed". Please correct me if I am wrong.
So, I’d like to introduce new states but not statuses, I did manage to introduce new statuses when it is in one of the states above, or I could change the labels of the existing states but I want to learn how magento manages the states and how to modify it/add new states. I can modify the core code if required.
So, my question is how do I introduce new states (not statuses) or how do I change/modify the order life-cycle?
I can investigate the source if you tell me which parts of the code is managing the order life-cycle. Any help or clue is appreciated.
PS: I'm using v1.5.1.0 right now.
So in your config.xml you would have something like ...
<config>
<global>
<sales>
<order>
<states>
<my_state translate="label">
<label>My State</label>
<statuses>
<pending default="1"/>
</statuses>
<visible_on_front/>
</my_state>
</states>
</order>
</sales>
</global>
</config>
Then whenever you want the state to change you could override the core or add an observer to change the state (please don't edit the core directly!) with something like (assuming $order is a valid order already loaded and ready to go) ....
$order->setState("my_state");
$order->save();
which will do the default status for the state. if you want to set a status put that in the second parameter so ..
$order->setState("my_state","complete");
$order->save();
HTH

Resources