$quoteItem = Mage::getModel('sales/quote_item')->setProduct($product)
->setQuote(Mage::getModel('sales/quote')->load($order->getQuoteId()));
$orderItem = Mage::getModel('sales/convert_quote')->itemToOrderItem($quoteItem)->setProduct($product);
this is the code i use to add a simple product to existing order , but i am having issues adding custom option product to the order.
$quoteItem->addOption(new Varien_Object(
array(
'product' => $quoteItem->getProduct(),
'code' => 'option_ids',
'value' => 1 // 45,46,55
)
));
$quoteItem->addOption(new Varien_Object(
array(
'product' => $quoteItem->getProduct(),
'code' => 'option_1', //45
'value' => 2 // ‘White’
)
));
after the first line , but no success.
Any help please.
Thanks
There is one method to change exitsting order:
http://prattski.com/2013/04/22/magento-adding-items-to-existing-orders/
Related
I am dynamically adding products to the cart in Magento2 with some custom options. Every product has the same base product id with different options. Represent Product has been properly overridden so that all products added to the cart are separate. However with this code, the second product added will lose it's custom options:
$magento_product = $this->productRepository->get('simple-product-1');
$params = array(
'product' => $magento_product->getId(),
'qty' => intval(5),
'options' => array(
'cr_price' => 12.0,
'Product' => "Test P",
'cr_XML' => '<root></root>'
),
);
$this->cart->addProduct($magento_product, $params);
$params = array(
'product' => $magento_product->getId(),
'qty' => intval(10),
'options' => array(
'cr_price' => 14.0,
'Product' => "Test P2",
'cr_XML' => '<root></root>'
),
);
$this->cart->addProduct($magento_product, $params);
$this->cart->save();
Only the first product has an entry in the quote_item_option table.
Any thoughts on why or how to fix would be appreciated.
Force reloading the product between each add fixes this issue.
$this->productRepository->get('simple-product-1', false, null, true);
The last true parameter is forceReload.
I have tried to get total cost in sales order report but without success. I can see the related data in the "sales_order_aggregated_created" and "sales_order_aggregated_updated" tables in database but unable to see total cost of orders. The data is being managed through app/code/core/Mage/Sales/Model/Resource/Order/collection.php
Please help if any one have idea to get the same value.
Finally I have done with the same. I have made corrections in three files to get the total cost field in sales order report. First of all copy this three core files to local folder.
1.Add total cost app/code/local/Mage/Sales/Model/Resource/Report/Order/Createdat.php in columns array around line number 95
'total_base_cost' => new Zend_Db_Expr('SUM(oi.total_base_cost)')
Dont forget to add same column (total_base_cost) in sales_order_aggregated_created table in databse. Now the $columns would be as below:
$columns = array(
// convert dates from UTC to current admin timezone
'period' => $periodExpr,
'store_id' => 'o.store_id',
'order_status' => 'o.status',
'orders_count' => new Zend_Db_Expr('COUNT(o.entity_id)'),
'total_qty_ordered' => new Zend_Db_Expr('SUM(oi.total_qty_ordered)'),
'total_base_cost' => new Zend_Db_Expr('SUM(oi.total_base_cost)'),
'total_qty_invoiced' => new Zend_Db_Expr('SUM(oi.total_qty_invoiced)'),
'total_income_amount' => new Zend_Db_Expr(
sprintf('SUM((%s - %s) * %s)',
$adapter->getIfNullSql('o.base_grand_total', 0),
$adapter->getIfNullSql('o.base_total_canceled',0),
$adapter->getIfNullSql('o.base_to_global_rate',0)
)
),
and add same column in $cols array to get the value from sales/order_item table around line number 204
'total_base_cost' => new Zend_Db_Expr('SUM(base_cost)')
now $cols array is:
$cols = array(
'order_id' => 'order_id',
'total_qty_ordered' => new Zend_Db_Expr("SUM(qty_ordered - {$qtyCanceledExpr})"),
'total_base_cost' => new Zend_Db_Expr('SUM(base_cost)'),
'total_qty_invoiced' => new Zend_Db_Expr('SUM(qty_invoiced)'),
);
2. Add same column in app/code/local/Mage/Sales/Model/Resource/Report/Order/Collection.php arround line 87
'total_base_cost' => 'SUM(total_base_cost)',
now $this->_selected array will be as below:
$this->_selectedColumns = array(
'period' => $this->_periodFormat,
'orders_count' => 'SUM(orders_count)',
'total_qty_ordered' => 'SUM(total_qty_ordered)',
'total_base_cost' => 'SUM(total_base_cost)',
'total_qty_invoiced' => 'SUM(total_qty_invoiced)',
'total_income_amount' => 'SUM(total_income_amount)',
'total_revenue_amount' => 'SUM(total_revenue_amount)',
'total_profit_amount' => 'SUM(total_profit_amount)',
'total_invoiced_amount' => 'SUM(total_invoiced_amount)',
'total_canceled_amount' => 'SUM(total_canceled_amount)',
'total_paid_amount' => 'SUM(total_paid_amount)',
'total_refunded_amount' => 'SUM(total_refunded_amount)',
'total_tax_amount' => 'SUM(total_tax_amount)',
'total_tax_amount_actual' => 'SUM(total_tax_amount_actual)',
'total_shipping_amount' => 'SUM(total_shipping_amount)',
'total_shipping_amount_actual' => 'SUM(total_shipping_amount_actual)',
'total_discount_amount' => 'SUM(total_discount_amount)',
'total_discount_amount_actual' => 'SUM(total_discount_amount_actual)',
);
3. Final display the column in sales order report grid by adding the same column in the file app/code/local/Mage/Adminhtml/Block/Report/Sales/Sales/Grid.php
$this->addColumn('total_base_cost', array(
'header' => Mage::helper('sales')->__('Cost'),
'type' => 'currency',
'currency_code' => $currencyCode,
'index' => 'total_base_cost',
'total' => 'sum',
'sortable' => false,
'rate' => $rate,
));
It may help someone else who wants to add the same column.
if($this->input->post('tambah')){
$kode = $this->input->post('kode');
$jumlah = $this->input->post('jumlah');
$hjual = $this->input->post('hjual');
$nama = $this->input->post('nama');
$exp = $this->input->post('tglexp');
$hpp = $this->input->post('hpp');
$temp_stok = $this->input->post('temp_stok');
$diskon = $this->input->post('diskon');
$cart = array(
'id' => $kode,
'qty' => $jumlah,
'price' => $hjual,
'name' => $nama,
'options' => array('exp' => $exp, 'hpp' => $hpp,
'temp_stok' => $temp_stok , 'diskon'=>$diskon ));
$this->cart->insert($cart);
header('location:'.base_url().'penjualan/load_input_barang_eceran');
}
I cant seem to add any more items and the latest one I add replaces the existing one.
I had like this in another controller but strangely can insert and not overwriting
I've had this.
It was non alphanumerics in the product code which caused the whole cart to behave strangely.
Try just having aaa123 etc as codes to test this
In CakePHP, I would like to sort my index list (created by the paginator component) on sequence ASC, but it won't work. If I see the query setup in the CakePHP docs (http://book.cakephp.org/2.0/en/core-libraries/components/pagination.html#query-setup), my paginator settings should look like this:
public function index()
{
$this->Paginator->settings = array(
'Attraction' => array(
'conditions' => array(
'Attraction.deleted' => null
),
'order' => array(
'Attraction.sequence ASC',
'Attraction.id ASC'
),
'limit' => 15
)
);
$attractions = $this->Paginator->paginate('Attraction');
$this->set('attractions', $attractions);
}
But every time I load my index file, the list is sorted on ID and ignores the "order" setting. Can anybody tell me if there's anything wrong with my "order" item in my paginator settings? ;)
Thx!
try
'order' => array(
'Attraction.sequence' => 'asc',
'Attraction.id' => 'asc'
),
edit:
The sorting direction must be in the array value, while the field name should be the index. The examles I found in the documentations are always showing that
I don't think you should have that Attraction index in your options array - in other words, I think your options array should look like this:
$this->Paginator->settings = array(
'conditions' => array(
'Attraction.deleted' => null
),
'order' => array(
'Attraction.sequence ASC',
'Attraction.id ASC'
),
'limit' => 15
);
I'm using magento 1.7.0.2. I have add the custom value in database. But how to retrive the custom value and image in Topmanu. I have tried in below mentioned code in the palce of 'my_attribute' to replace my attribute, but i din't get the result.
Model: Mage_Catalog_Model_Observer
Method: _addCategoriesToMenu()
$categoryData = array(
'name' => $category->getName(),
'id' => $nodeId,
//'url' => Mage::helper('catalog/category')->getCategoryUrl($category),
'is_active' => $this->_isActiveMenuCategory($category),
'my_attribute' => $category->getData('my_attribute') // Add our data in...
);
When i print the array i'll get this,
Array ( [name] => Matelas [id] => category-node-31 [is_active] => 1 [my_attribute] => )
Can any one guide me, Thanks in advance...
I am guessing you mean you have added a new custom attribute to the Category entity?
Becuase you are dealing with a Node_collection the full category object won't be loaded, try loading the full object to get what you're after:
$cat = Mage::getModel('catalog/category')->load($category->getId());
$categoryData = array(
name' => $category->getName(),
'id' => $nodeId,
//'url' => Mage::helper('catalog/category')->getCategoryUrl($category),
'is_active' => $this->_isActiveMenuCategory($category),
'my_attribute' => $cat->getData('my_attribute') // Add our data in...
);