Magento - show a custom customer attribute in new oder validation E-mail - magento

How can I show the value of a custom customer attribute in new oder validation E-mail, using Magento ver. 1.4.1.1
I have added this code to /sales/model/order.php :
public function getCustomerNumber() {
if (!$this->getCustomerId()) return;
$customer = Mage::getModel('customer/customer')->load( $this->getCustomerId());
$customer = $customer->getData('customer_number');
return ($customer);
and {{var order.getCustomer()}} in order email template but it get the word 'Object' and not the right value.
Thanks for help.

Related

Send account confirmation email to specific customer group in magento

How to send account confirmation email to specific customer group in magento
I want to send confirmation email only a specific customer group. please any one can help in this issue....
I already save the customer group during registration or new account creation by using below link:-
http://phpmagento.blogspot.in/2012/01/how-to-show-customer-group-selecter-in.html
Go to the \app\code\core\Mage\Customer\Model\Customer.php
replace
<pre>
public function isConfirmationRequired()
{
if ($this->canSkipConfirmation()) {
return false;
}
if (self::$_isConfirmationRequired === null) {
$storeId = $this->getStoreId() ? $this->getStoreId() : null;
self::$_isConfirmationRequired = (bool)Mage::getStoreConfig(self::XML_PATH_IS_CONFIRM, $storeId);
}
return self::$_isConfirmationRequired;
}
</pre>
with:
public function isConfirmationRequired()
{
if ($this->canSkipConfirmation()) {
return false;
}
if (self::$_isConfirmationRequired === null) {
$storeId = $this->getStoreId() ? $this->getStoreId() : null;
if($this->getGroupId() == 2) {
self::$_isConfirmationRequired = (bool)Mage::getStoreConfig(self::XML_PATH_IS_CONFIRM, $storeId);
}
}
return self::$_isConfirmationRequired;
}
</pre>
Where 2 is the wholesale group Id.
Account confirmation email is sent when creating customer.
Customer group is added to customer after customer account is created.
So it's not possible to send confirmation email to only a specifik customer groep.
I Don't think you can without do some customization in magento.
Try
Disable All Email Confirmation. see How To Enable/Disable Email confirmation for New Account
Then create an observer for on customer save. see magento customer_save_after model / observer not called, catch customer -> edit -> save function
Check to see if the customer is a new customer and in the correct group (may need to check if the got confirmation email before)
Copy the logic that send Email confirmation from base magento into your observer

Magento get product collection via custom observer

I have a custom observer in Magento 1.8.1.0 that is called on Product view page when current product having any upsell products. I have verified (using Mage::log()) that the observer is working, however when I try the following:
public function updateUpsells(Varien_Event_Observer $oObserver)
{
$iCurrentCategory = Mage::registry('current_category')->getId();
$oUpsellCollection = $oObserver->getCollection();
foreach ($oUpsellCollection->getItems() as $key => $oUpsellProduct) {
$aCategoriesIds = $oUpsellProduct->getCategoryIds();
if (!in_array($iCurrentCategory, $aCategoriesIds)) {
$oUpsellCollection->removeItemByKey($key);
}
}
}
On echo $oUpsellCollection; i got nothing returned ?
Is anyone know how to get upsell products collection ? Is this a proper way to do it ?
$upsellCollection = $_product->getUpSellProductCollection();

Magento get coupon description

I am trying to retrive the text set in the Magento Coupon Description field to use as part of a validation rule. Does anyone know how to load a coupon price rule using the coupon code and retrieve the associated coupon description text?
Under Magento 1.3, you can use this code (not tested as I have no 1.3 within easy reach) :
$rule = Mage::getModel('salesrule/rule')->load($code, 'coupon_code');
if ($rule->getId()) {
$description = $rule->getDescription();
}
I have used in magento 1.9 and below code is working fine for me.
$oCoupon = Mage::getModel('salesrule/coupon')->load($couponCode, 'code');
$oRule = Mage::getModel('salesrule/rule')->load($oCoupon->getRuleId());
$message = $oRule->getData();
$description = $message['description'];
$this->_getSession()->addError(
$this->__($description, Mage::helper('core')->escapeHtml($couponCode))
);
$oCoupon = Mage::getModel('salesrule/coupon')->load($couponCode, 'code');
$oRule = Mage::getModel('salesrule/rule')->load($oCoupon->getRuleId());
var_dump($oRule->getData());
you can refer for same Magento - get rule from coupon code

How to create an invoice for magento downloadable product?

I have an problem with invoice generating for my downloadable product.
I tried to create an invoice. But it shows like this error message Cannot create an invoice without products.
Can any one help to solve this issue.
Thanks
meaning that you have not selected the products that you need to invoice if you look at the code that gives this error in following file
app/code/core/Mage/Adminhtml/controllers/Sales/Order/InvoiceController.php:88: Mage::throwException($this->__('Cannot create an invoice without products.'));
you see that this error is given when no items are found
$savedQtys = $this->_getItemQtys();
$invoice = Mage::getModel('sales/service_order', $order)->prepareInvoice($savedQtys);
if (!$invoice->getTotalQty()) {
Mage::throwException($this->__('Cannot create an invoice without products.'));
}
and you can also see that the items are looked from your post
/**
* Get requested items qty's from request
*/
protected function _getItemQtys()
{
$data = $this->getRequest()->getParam('invoice');
if (isset($data['items'])) {
$qtys = $data['items'];
} else {
$qtys = array();
}
return $qtys;
}
meaning that you have not selected or posted whatever needs to be posted to this method.

Magento: How to Print backend invoices like frontend as HTML?

I'm on Magento 1.7.0.2. How can I print invoices from backend with the same manner that frontend uses? I want it to be on HTML format not PDF.
Assuming that you want to print one invoice at a time from the admin order detail page
Create a custom admin module
Add a controller with the method below
public function printInvoiceAction()
{
$invoiceId = (int) $this->getRequest()->getParam('invoice_id');
if ($invoiceId) {
$invoice = Mage::getModel('sales/order_invoice')->load($invoiceId);
$order = $invoice->getOrder();
} else {
$order = Mage::registry('current_order');
}
if (isset($invoice)) {
Mage::register('current_invoice', $invoice);
}
$this->loadLayout('print');
$this->renderLayout();
}
Reference printInvoiceAction() in app/code/core/Mage/Sales/controllers/GuestController.php
Then in your custom layout.xml use <sales_guest_printinvoice> in /app/design/frontend/base/default/layout/sales.xml as your template
Then add a button with link to the following url (need to get invoice id from order) /customModule/controller/printInvoice/invoice_id/xxx
(Not tested, so let me know if you run into any issues)
You should create your custom css file for printing print.css. And you should add "Print Button", that will call window.print()

Resources