i am using Magento 1.9.0.1 and i am developing a custom extension.
Right now i am stuck at the following thing.
Like this i use to get the customers name from an order:
$CustomerName = $observer->getOrder()->getBillingAddress()->getName();
I have custom customer attribute called sms_on_order_change and i am trying to get the value of it like that:
$SMSOnStatusChange = $observer->getResource()->getAttribute('sms_on_order_change')->getFrontend()->getValue();
But it is not working.
Here is the extension that i am using for the creation of custom customer attributes: http://www.magentocommerce.com/magento-connect/manage-customer-attributes.html
So guys, can you help me out so i can get the value of this custom attribute ?
Thanks in advance!
This should help you out:
//get order from observer
$order = $observer->getOrder();
// get customer id from order
$customer_id = $order->getCustomerId();
// condition only necessary if guest orders are allowed
if ($customer_id)
{
$_customer = Mage::getModel('customer/customer')->load($customer_id);
$sms_on_order_change = $_customer->getData('sms_on_order_change');
}
Related
How to add Custom option value on coupon rules Magneto 2. I have a product which have some custom option like size, color etc. with different value, I want give discount on basic of size = 7'. I don't want use sku custom option.. Let me know how I fix it.
https://github.com/Turiknox/magento2-custom-total
Moulde I use for Discount but i have face a problem.
one Data I can't get cart information
$obj = $bootstrap->getObjectManager();
// Set the state (not sure if this is neccessary)
$state = $obj->get('Magento\Framework\App\State');
$state->setAreaCode('frontend');
// Getting the object managers dependencies
$quote = $obj->get('Magento\Checkout\Model\Session')->getQuote();
$helper = $obj->get('\Magento\Checkout\Helper\Cart');
// Get quote and cart items collection
$quote = $helper->getQuote();
$quoteitems = $quote->getAllItems();
$coupon_code = 'Test23';
// Get cart contents
$cart= $helper->getCart();
foreach ($quoteitems as $item)
{
}
It goes to the infinity loop.
This one Run fast that's why here we can't load quote total, For Discount given you must set session core cookies which allow giving discount...
I'm building out custom landing pages for products in WooCommerce and I'd like to get the product price amongst other things in order to display them on the landing page.
Each landing page has some custom fields which allow the WP Admin to add in content, for the landing page as well as the product ID, which will then be used to generate the product price, checkout URL etc..
I can't get the wc_get_product(); to work with my custom field or a variable built off that. It only works when I use a straight ID. I think there's something I'm not understanding about how variables work within PHP. Here's my code.
<?php
//Gets the course ID from the custom field entered by user
$courseID = the_field('course_id');
// This line is where the problem is...
$_product = wc_get_product('$courseID');
// If I replace the line above with this line
// $_product = wc_get_product('7217');
// everything works great, but that does not let
// each landing page function based on the custom fields where the user determines
// the product ID they are selling on that landing page.
// Get's the price of the product
$course_price = $_product->get_regular_price();
// Output the Course price
?> <span class="coursePrice">$<?php echo $course_price;?></span>
Update
I get the following error using wc_get_product( $courseID ); or get_product( $courseID );:
Fatal error: Call to a member function get_regular_price() on a non-object in ...
Update related to your recent comment. The 2 ways to explore:
1) Instead of you should try to use to get the product object (avoiding the error):
$courseID = the_field('course_id');
// Optionally try this (uncommenting)
// $courseID = (int)$courseID;
// Get an instance of the product object
$_product = new WC_Product($courseID);
2) Alternatively if this doesn't work, you should try to use get_post_meta() function to get the product price (or any product meta data) this way:
<?php
//Gets the course ID from the custom field entered by user
$courseID = the_field('course_id');
// Get the product price (from this course ID):
$course_price = get_post_meta($courseID, '_regular_price', true);
// Output the Course price
?> <span class="coursePrice">$<?php echo $course_price;?></span>
This time you should get displayed the price with one or the other solutions.
Update: May be Also you need to convert $courseID to an integer variable.
Because you need to use your variable $courseID inside wc_get_product() (without the 2 ') function this way:
<?php
//Gets the course ID from the custom field entered by user
$courseID = the_field('course_id');
// Optionally try this (uncommenting)
// $courseID = (int)$courseID;
// Here
$_product = wc_get_product( $courseID );
$course_price = $_product->get_regular_price();
// Output the Course price
?> <span class="coursePrice">$<?php echo $course_price;?></span>
This should work now.
You can try this out :
$courseID = the_field('course_id');
$product = get_product( $courseID );
I figured out the answer after running through the possible solution routes that #LoicTheAztec supplied in his response. None of these worked and so I assumed something else was up.
I use Advanced Custom Fields to add custom fields in the back end and I was using ACF's the_field() in order to create my variable. That is incorrect usage of that function as it's designed to display the field, (it's basically using php's echo). To work with these custom field's you need to use ACf's get_field() which is to use it to store a value, echo a value and interact with a value.
Once I switched to setting my $courseID to this..
$courseID = get_field('course_id');
Everything worked. My code worked, and all #LoicTheAztec's code approaches also worked.
Need to update custom field value in magento order where order_date is my custom field.
$order2 = Mage::getModel('sales/order')->load(100000013);
It returns following exception Call to a member function getMethodInstance() on a non-object.
Any solution for fix this issue ?
Your order not able to load by magento that's why magento giving you error.
you are passing order increment id in the load function
Load By Increment Id
$id = 100000013;
$order = Mage::getModel('sales/order')->loadByIncrementId($id);
$order->setData('order_date', "2014-12-12");
$order->save();
Load By Order Id(Entity Id)
$id = 13;
$order = Mage::getModel('sales/order')->load($id);
$order->setData('order_date', "2014-12-12");
$order->save();
Please check.
I'm new to Magento and have some difficulties with writing mdoule that will allow me to export (send to remote API) data from my magento store.
Currently what I have is created observer for "sales_order_save_after" event and what I want do in my observer is to get Order data, make them xml and send to some remote url.
Can anyone help with that? I'm using magento 1.8
you can get data in observer like below function
public function orderExportTxt(Varien_Event_Observer $observer)
{
$order = $observer->getEvent()->getOrder();
print_r($order->getData()); // your user detail.
}
EDIT
To get Product detail from order
<?php $order_id = 2314; //use your own order id
$order = Mage::getModel("sales/order")->load($order_id);
//load order by order id
$ordered_items = $order->getAllItems();
foreach($ordered_items as $item){
//item detail
echo $item->getItemId(); //product id
echo $item->getSku();
echo $item->getQtyOrdered(); //ordered qty of item
echo $item->getName(); // etc.
} ?>
its depends on your xml format for your third party service in which format it accept your order to be in saved.
below is just example to create xml file.
http://www.php.net//manual/en/domdocument.savexml.php
hope this will sure help you.
Let me know if i could help further.
I have a custom address attribute. In the backend, order page i need to get that attribute value.
Try this one
$orderId = '100000001';
$order = Mage::getModel('sales/order')->loadByIncrementId($orderId);
$customAttributeValue = $order->getShippingAddress()->getAttributeText('your_custom_attribute');