How can I show invoice id in \app\code\local\Mage\Sales\Model\Order\Pdf\Abstract.php
I don't need to show getRealOrderId() into pdf invoice, but I need invoice id.
How can I do that?
First be sure, that your order is loaded ... take a look at:
protected function insertOrder(&$page, $obj, $putOrderId = true)
{
if ($obj instanceof Mage_Sales_Model_Order) {
$shipment = null;
$order = $obj;
} elseif ($obj instanceof Mage_Sales_Model_Order_Shipment) {
$shipment = $obj;
$order = $shipment->getOrder();
}
.....
}
So later you can use this snippet:
$invoiceIncrementId = '';
if ($order->hasInvoices()) {
// "$_eachInvoice" is each of the Invoice object of the order "$order"
foreach ($order->getInvoiceCollection() as $_eachInvoice) {
$invoiceIncrementId = $_eachInvoice->getIncrementId();
}
}
I referred, that forum reply: http://www.magentocommerce.com/boards/viewthread/198222/#t393368
Good luck.
Related
//Observer function
$order = $observer->getEvent()->getOrder();
foreach($order->getAllItems() as $item){
if($item->getProductType() == 'bundle')
{
//Loading bundle product object
$bundle_product = Mage::getModel('catalog/product')->load($item->getProductId());
//Getting bundle items collection
$selectionCollection = $bundle_product->getTypeInstance(true)->getSelectionsCollection($bundle_product->getTypeInstance(true)->getOptionsIds($bundle_product), $bundle_product);
foreach($selectionCollection as $option)
{
//Loading each bundle item
$bundle_item = Mage::getModel('catalog/product')->load($option->getId());
//How to get the quantity that was ordered? example:
$bundle_item->getQtyOrdered(); //Note: I know this is wrong, this is not the correct object.
}
}
}
Please use below code:
//Observer function $order = $observer->getEvent()->getOrder();
foreach($order->getAllItems() as $item){
if($item->getProductType() == 'bundle')
{
$options = $item->getProduct()->getTypeInstance(true)->getOrderOptions($item->getProduct());
$bundleOption=$options['info_buyRequest']['bundle_option_qty'];
foreach($bundleOption as $bundleItemQty){
echo 'Bundle Item Qty='.$bundleItemQty;
}
}
}
Given this function in Magento:
public function capture(Varien_Object $payment, $amount)
{
$order = $payment->getOrder();
$order_id = $order->getId();
$invoice = ????
$invoice_id = $invoice->getId();
}
How can I get the invoice or invoice ID?
The Mage_Sales_Model_Order has methods like hasInvoices() and getInvoiceCollection():
public function capture(Varien_Object $payment, $amount)
{
$order = $payment->getOrder();
$order_id = $order->getId();
if ($order->hasInvoices()) {
$oInvoiceCollection = $order->getInvoiceCollection();
foreach ($oInvoiceCollection as $oInvoice) {
$invoice_id = $oInvoice->getId();
// ...
}
}
}
My Cart is looking like this with popup window:
I am updating multiple configurable items in cart with custom options at a time by AJAX Call.
But I am not able to get all items data back to AJAX response.
I am getting just 1st itemPrice and rowTotal. For remaining items itemPrice and rowTotal are set to 0.
Code:
public function updateItemOptionsAction()
{
$cartData = $this->getRequest()->getParam('cart');
Mage::log($cartData);
if (is_array($cartData)) {
$result = array();
$result['data'] = array();
foreach ($cartData as $index => $data) {
$cart = $this->_getCart();
$params = $data;
$id = (int)$data['id'];
if (!isset($params['options'])) {
$params['options'] = array();
}
$result['data'][$index] = array();
$oldQty = null;
$kitType = $params['efk_kType'];
$params['super_attribute'] = array($data['sAttr']=>$kitType);
unset($params['sAttr']);
$stock = null;
try {
if (isset($params['qty'])) {
$product = Mage::getModel("catalog/product")->load($params['product']);
$childProducts = Mage::getModel('catalog/product_type_configurable')->getUsedProducts(null, $product);
foreach($childProducts as $cProd){
if($cProd->getKitType() == $kitType){
$stock = intval(Mage::getModel('cataloginventory/stock_item')->loadByProduct($cProd)->getQty());
}
}
if(intval($params['qty']) > $stock){
$oldQty = intval($params['qty']);
$params['qty'] = $stock;
$result['data'][$index]['revised'] = true;
}
$filter = new Zend_Filter_LocalizedToNormalized(
array('locale' => Mage::app()->getLocale()->getLocaleCode())
);
$params['qty'] = $filter->filter($params['qty']);
}
$quoteItem = Mage::getSingleton('checkout/cart')->getQuote()->getItemById($id);
if (!$quoteItem) {
Mage::throwException($this->__('Quote item is not found.'));
}
//Its going to infinity loop duwe to Varien Object need to check later
//$item = $cart->updateItem($id, new Varien_Object($params));
$item = Mage::getSingleton('checkout/cart')->updateItem($id, $params);
if (is_string($item)) {
Mage::throwException($item);
}
if ($item->getHasError()) {
Mage::throwException($item->getMessage());
}
Mage::log('hi2');
$related = $params['related_product'];
if (!empty($related)) {
Mage::getSingleton('checkout/cart')->addProductsByIds(explode(',', $related));
}
Mage::getSingleton('checkout/cart')->save();
Mage::getSingleton('checkout/session')->setCartWasUpdated(true);
Mage::dispatchEvent('checkout_cart_update_item_complete',
array('item' => $item, 'request' => $this->getRequest(), 'response' => $this->getResponse())
);
$cart->getQuote()->setTotalsCollectedFlag(false);
Mage::getSingleton('checkout/cart')->init();
if (!Mage::getSingleton('checkout/session')->getNoCartRedirect(true)) {
if (!Mage::getSingleton('checkout/cart')->getQuote()->getHasError()) {
Mage::log('hi4');
$result['success'] = true;
if($oldQty > $item->getQty()){
$message = $this->__('%s has been revised due to stock limitations. You may proceed with the order for the revised quantity.', Mage::helper('core')->escapeHtml($item->getProduct()->getName()));
}else{
$message = $this->__('%s was updated in your shopping cart.', Mage::helper('core')->escapeHtml($item->getProduct()->getName()));
}
$result['data'][$index]['message'] = $message;
$result['data'][$index]['itemId'] = $item->getId();
$result['data'][$index]['itemPrice'] = Mage::helper('checkout')->formatPrice($item->getCalculationPrice());
$result['data'][$index]['qty'] = $item->getQty();
$result['data'][$index]['rowTotal'] = Mage::helper('checkout')->formatPrice($item->getRowTotal());
}
}
} catch (Mage_Core_Exception $e) {
$result['success'] = false;
$result['data'][$index]['success'] = 'qty';
$result['data'][$index]['message'] = $e->getMessage();
} catch (Exception $e) {
$result['success'] = false;
$result['data'][$index]['message'] = $e->getMessage();
$result['data'][$index]['secondMessage'] = $this->__('Cannot update the item.');
}
}
$result['data']['grandTotal'] = Mage::helper('checkout')->formatPrice(Mage::getSingleton('checkout/cart')->getQuote()->getGrandTotal());
$result['data']['totalItems'] = Mage::getSingleton('checkout/cart')->getSummaryQty();
$totals = Mage::getSingleton('checkout/cart')->getQuote()->getTotals();
$result['data']['subTotal'] = Mage::helper('checkout')->formatPrice($totals['subtotal']->getValue());
if(isset($totals['discount']) && $totals['discount']->getValue()){
$result['data']['discount'] = Mage::helper('checkout')->formatPrice($totals['discount']->getValue());
}else{
$result['data']['discount'] = Mage::helper('checkout')->formatPrice(0);
}
}
$this->getResponse()->setBody(Mage::helper('core')->jsonEncode($result));
}
AJAX Response I'm getting
{
"data": {
"1187": {
"success": true,
"message": "THREE PHASE SOLID STATE RELAY WITH ZVS was updated in your shopping cart.",
"itemId": "1191",
"itemPrice": "<span class=\"price\">20b9 3,799</span>",
"qty": 1,
"rowTotal": "<span class=\"price\">20b9 3,799</span>",
"forLoop": "yes"
},
"1189": {
"success": true,
"message": "AUTO INTENSITY CONTROL OF STREET LIGHTS was updated in your shopping cart.",
"itemId": "1193",
"itemPrice": "<span class=\"price\">20b9 0</span>",
"qty": 1,
"rowTotal": "<span class=\"price\">20b9 0</span>",
"forLoop": "yes"
},
"grandTotal": "<span class=\"price\">20b9 8,798</span>",
"totalItems": 2,
"subTotal": "<span class=\"price\">20b9 8,798</span>",
"discount": "<span class=\"price\">20b9 0</span>"
}
}
I am getting itemPrice and rowTotal for 2nd item as 0. Every time I am getting correct values for 1st item only. If i am update 5 items at a time (say for example) then i am getting correct values for 1st item and for remianing items i am getting 0's.
If i refresh cart once i get AJAX response, then it is showing itemPrice and rowTotal updated values correctly for all items.
Note: 20b9 is HEX Code for Indian Rupee symbol
Please point out where i am wrong.
Thanks in advance.
You're working tooooo hard... try updating the items in the controller server side as you sort of are, saving the current quote... and then just have a controller method that loads the current .phtml and returns the html as json for the cart block, and replace the whole cart html block (div) with the new one.
At the end of your controller method
$this->getResponse()->setBody( json_encode(
array("html" =>
Mage::app()->getLayout()->createBlock('checkout/[[whatevertag_is_to_cart_div phtml block]]')->toHtml()
)
);
I need to join a table and subtract from that table the position and pricebycat1 but i cannot figure out the function on codeigniter.
This is my function to retrieve the products.
function get_product($id, $related=true)
{
$result = $this->db->get_where('products',array('id'=>$id))->row();
// get position, pricebycat1, join category_products 'category_products.product_id=products.id'
if(!$result) {
return false;
}
$related = json_decode($result->related_products);
if(!empty($related)) {
//build the where
$where = false;
foreach($related as $r) {
if(!$where) {
$this->db->where('id', $r);
} else {
$this->db->or_where('id', $r);
}
$where = true;
}
$result->related_products = $this->db->get('products')->result();
} else {
$result->related_products = array();
}
$result->categories = $this->get_product_categories($result->id);
// group discount?
if($this->group_discount_formula) {
eval('$result->price=$result->price'.$this->group_discount_formula.';');
}
return $result;
}
Any help is appreciated.
You can't join another table using only get_where() .
Try to use this approach for extraction data
$this->db->select('*.products, category_products.position, category_products.price');
$this->db->from('products');
//join LEFT by default
$this->db->join('category_products', 'category_products.product_id=products.id');
$this->db->where('products.id = '.$id);
$this->db->row();
I want to create partial invoice for downloadable product of an order based on release date of that product, I have got so many solutions to create partial invoice but it's create the invoice for all product, not for selected one.
Here is the solution but don't forget to change condition according your requirement.
<?php
require_once '../app/Mage.php';
Mage::app('admin');
CapturePayment::createInvoice();
class CapturePayment {
public static function createInvoice() {
$orders = Mage::getModel('sales/order')->getCollection()
->addFieldToFilter('status', array('processing'));
foreach ($orders as $order) {
$orderId = $order->getIncrementId();
try {
if (!$order->getId() || !$order->canInvoice()) {
echo 'Invoice is not allowed for order=>.' . $orderId . "\n";
continue;
}
$items = $order->getAllItems();
$partial = false;
$qtys = array();
foreach ($items as $item) {
/* Check wheter we can create invoice for this item or not */
if (!CapturePayment::canInvoiceItem($item, array())) {
continue;
}
/* Get product id on the basis of order item id */
$productId = $item->getProductId();
/* If product is tablet then don't create invoice for the same */
/* Put your condition here for items you want to create the invoice e.g.*/
/* Load the product to get the release date */
$productDetails = Mage::getModel('catalog/product')->load($productId);
/* create your $qtys array here like */
$qtys['orderItemId'] = 'quantityOrdered';
/* NOTE: But if you don't want to craete invoice for any particular item then pass the '0' quantity for that item and set the value for $partial = true if some product remain in any order*/
}
/* Prepare the invoice to capture/create the invoice */
$invoice = Mage::getModel('sales/service_order', $order)->prepareInvoice($qtys);
if (!$invoice->getTotalQty()) {
continue;
}
$amount = $invoice->getGrandTotal();
if ($partial) {
$amount = $invoice->getGrandTotal();
$invoice->register()->pay();
$invoice->getOrder()->setIsInProcess(true);
$history = $invoice->getOrder()->addStatusHistoryComment('Partial amount of $' . $amount . ' captured automatically.', false);
$history->setIsCustomerNotified(true);
$invoice->sendEmail(true, '');
$order->save();
Mage::getModel('core/resource_transaction')
->addObject($invoice)
->addObject($invoice->getOrder())
->save();
$invoice->save();
} else {
$invoice->setRequestedCaptureCase(Mage_Sales_Model_Order_Invoice::CAPTURE_ONLINE);
$invoice->register();
$invoice->getOrder()->setCustomerNoteNotify(true);
$invoice->getOrder()->setIsInProcess(false);
$invoice->getOrder()->setData('state', "complete");
$invoice->getOrder()->setStatus("complete");
$invoice->sendEmail(true, '');
$order->save();
Mage::getModel('core/resource_transaction')
->addObject($invoice)
->addObject($invoice->getOrder())
->save();
$invoice->save();
}
} catch (Exception $e) {
echo 'Exception in Order => ' . $orderId . '=>' . $e . "\n";
}
}
}
/* Check the invoice status for an item of an order */
public static function canInvoiceItem($item, $qtys=array()) {
if ($item->getLockedDoInvoice()) {
return false;
}
if ($item->isDummy()) {
if ($item->getHasChildren()) {
foreach ($item->getChildrenItems() as $child) {
if (empty($qtys)) {
if ($child->getQtyToInvoice() > 0) {
return true;
}
} else {
if (isset($qtys[$child->getId()]) && $qtys[$child->getId()] > 0) {
return true;
}
}
}
return false;
} else if ($item->getParentItem()) {
$parent = $item->getParentItem();
if (empty($qtys)) {
return $parent->getQtyToInvoice() > 0;
} else {
return isset($qtys[$parent->getId()]) && $qtys[$parent->getId()] > 0;
}
}
} else {
return $item->getQtyToInvoice() > 0;
}
}
}