How to access Magento order 'visible_on_front' property?
I've tried the following bits:
$order = $this->getOrder();
$order->setStatus('processing');
$order->setData('visible_on_front', 1);
or
$history = $this->getOrder()->addStatusHistoryComment('msg');
$history->setStatus('processing');
$history->setData('state', 'visible');
or
$history = $this->getOrder()->addStatusHistoryComment('msg');
$history->setStatus('processing');
$history->setData('visible_on_front', 1);
Thanks in advance.
try this and see if it has changed after you changed the data
$order = $this->getOrder();
$order->setStatus('processing');
$order->setVisibleOnFront(1);
print_r($order->getData());
I've just had this need, I solved it like this:
$order->addStatusHistoryComment(<your comment>,<your status>)
->setIsVisibleOnFront(1);
Of course you load into $order the order you want to use.
With these you will have the comment visible into the user account page under the order details.
Related
In Magento 1.9 I want to get the customerId of opened customer in Mage_Adminhtml_Block_Customer_Edit_Tab_View.
I tried like this:
$customer_session = Mage::getSingleton('customer/session'); //I saw here in Stackoverflow this
$customer = $customer_session->getCustomer();
$customerID = $customer->getId();
But I got a null.
I also tried with $this->getId() and Mage::helper('customer')->getId(), but neither worked.
How do achieve this?
For admin we should use 'admin/session' for 'customer/session'
$user = Mage::getSingleton('admin/session');
$userId = $user->getUser()->getUserId();
$userEmail = $user->getUser()->getEmail();
I figured out that the correct way is:
$customerID = $this->getCustomer()->getId();
I am using following code for saving data from form to database.
$data = $this->getRequest()->getPost();
$custom['name'] = $data['name'];
$model = Mage::getModel('my/custom_order');
$model->setOrderId($order_id);
$model->setKey('name');
$model->setValue(serialize($custom));
$model->save();
Data does not save in database.But When I pass static data like below, It is Working.
$custom['name'] = 'John';
When I use print_r($data),
Array(
[name] => xyz
[surname] =>
)
Maybe you need:
$data = $this->getRequest()->getPost()->getParams();
Please check this. Check data which sended to server in your browser Network tool.
You need
$params = json_decode(file_get_contents('php://input'));
What would be the code to display articles from category (specified by ID)?
In Wordpress this is fairly easy by doing:
<?php
query_posts('cat=1');
while (have_posts()) : the_post();
the_title();
endwhile;
?>
I'm looking for similar code for Joomla.
$db = JFactory::getDbo();
$id = 50;//example
$query = $db->getQuery(true);
$query->select('*');
$query->from('#__content');
$query->where('catid="'.$id.'"');
$db->setQuery((string)$query);
$res = $db->loadObjectList();
foreach($res as $r){
echo '<h3>'.$r->title.'</h3>';
echo $r->introtext;
}
You can use next code template:
$categoryId = $[category id];
require_once("components/com_content/models/category.php");
$category = new ContentModelCategory();
$category->hit($categoryId);
$articles = $category->getItems();
print_r($articles);
There is no direct code for getting this in joomla like word press.
If you want to check the code you can check the code for achieving this by following path.
components/com_content/view/category/view.html.php
and
components/com_content/view/category/tmpl/blog.php
According to my Guess your requirement is to display the articles from same category.
then in joomla you dont need to edit in any code.
for achieving this you can simply create a menu.
and menu layout type should be category blog and Choose your category from the right side category options.
This will get the complete article from that category.
If you want to manage it in your style you can add style based on blog.php file .
Hope this will help you..
Try this:
$articles = JFactory::getDBO()->setQuery("SELECT * FROM #__content WHERE catid = '21'")->loadObjectList();
Of course replace '21' with id of your category.
This is quite easy in Joomla. You can find the code in /components/com_content/models/category.php under getItems()
Below is an example
$model = JModelLegacy::getInstance('Articles', 'ContentModel', array('ignore_request' => true));
$model->setState('params', JFactory::getApplication()->getParams());
$model->setState('filter.category_id', $category_id);
$articles = $model->getItems();
I'm tasked to write a custom payment method for Magento CE, and tinkered with it for the last couple of weeks. Although I'm an experienced developer, this was my first serious brush with php and Magento itself.
Please note this a web payment gateway, so I'm using
public function getOrderPlaceRedirectUrl() { ... }
In my Payment Method Model to redirect the customer to the external url successfully.
The issue that kept me stuck for a full day is how to retrieve checkout shopping cart contents, shipping details and ancillary fees (tax, discounts, etc). This info needs to be sent to the payment method API.
The code I've been using in my Payment Method Model is something like this:
$order_id = Mage::getSingleton("checkout/session")->getLastRealOrderId();
$order = Mage::getModel('sales/order')->loadByIncrementId($order_id);
$oBillingAddress = $order->getBillingAddress(); //this works ok
$total = number_format($order->getBaseGrandTotal(), 2, '', ''); //this too
/* The following code won't work */
$oShippingAddress = $order->getShippingAddress(); // is unset!?
$oShippingAddress->getSameAsBilling(); //HOW can I check this?
$amount = array();
$quantity = array();
$sku = array();
$description = array();
$cart_items = $order()->getAllVisibleItems();
foreach ($cart_items as $item) {
$amount[] = number_format($item->getPrice(), 2, '', ''); //ok
$quantity[] = $item->getQtyToInvoice(); // is empty...
$sku[] = $item->getSku(); // nothing either??
$description[] = $item->getName(); //this is working
}
Please, wizards of Magento, tell what am I doing wrong here?
Magento dev has been very frustrating, mainly for its lack of straightforward documentation. I'm sure it's very customizable and what not, but the abuse of php's magic functions and it's cumbersome structure has been challenging - at the least.
I think you need to get the quote. Something like this should work:
$quote = Mage::getSingleton('checkout/session')->getQuote();
$items = $quote->getAllVisibleItems();
foreach ($items as $item) {
$amount[] = number_format($item->getPrice(), 2, '', ''); //ok
$quantity[] = $item->getQtyToInvoice(); // is empty...
$sku[] = $item->getSku(); // nothing either??
$description[] = $item->getName(); //this is working
}
If you still need the order, let me know..
how to get sku and product name on the head.php (\app\code\core\Mage\Page\Block\Html\head.php) page? thank you.
when i used $this->_data['sku']; or $this->getSku(); are all not work.
The previous answer is fine, except it doesn't check if product exists in registry. So you will get fatal error on non-product pages. Always make a check if variable exists.
$product = Mage::registry('current_product');
if ($product) //sometimes need check for instanse, use instanseof
{
$product->getSku();
}
You should be able to pull the current product back from the registry and access the values from that.
$product = Mage::registry('current_product');
$product->getSku();
Working Code:
if($_product = Mage::registry('current_product')){
$id = $_product->getId();
$sku = $_product->getSku();
}