Manual magento order creation - item price original and converted to store currency - magento

I'm using code below to create order in magento:
$quote = Mage::getModel('sales/quote');
$quote->setCheckoutMethod('guest')->save();
$quote->setStore($store);
$quote->setForcedCurrency(Mage::getModel('directory/currency')->load($storeCurrency));
foreach ($productInCardList as $productItem) {
$product = Mage::getModel('catalog/product')->load($productItem['id']);
$product->setPrice($productItem['price']);
$request = new Varien_Object();
$request->setQty($productItem['qty']);
$quote->addProduct($product, $request);
}
$quote->collectTotals();
$quote->reserveOrderId();
$quote->save();
$service = Mage::getModel('sales/service_quote', $quote);
$service->submitAll();
$orderObj = $service->getOrder();
// ... code setting billing, shipping address, payment and shipping method.
The order is created, but it shown in sales->orders grid with incorrect G.T. Purchased Price (the amount for USD and EUR are the same)
The orders placed thorugh magento front end have correct G.T. Purchased price the initial price in USD (92 USD) and converted price for store in EUR(66 EUR). But orders which is created using code shows the same amount converted in EUR(66 EUR) and USD (66 USD). I would very appreciate if you help me to make the price shown correctly in the order.
Thank you for your help

To convert a price from currency of store view in which the order is placed to the base currency (which Magento is setup with and is shown in the admin), use the following code:
$basePrice = Mage::app()->getStore()->convertPrice($price, false, false);

Related

magento adding custom parameter and updating price

i want to add custom donate(like tip) module in addition to product price
suppose Product A (price 100) have text box field
1:donate with blank value which user have to enter user can insert any value and product price will be donated value + product price
how can i implement this via observer
i tried using "checkout_cart_product_add_after" observer
code of observer.php
class Mour_Customgroup_Model_Observer
{
public function modifyPrice(Varien_Event_Observer $obs ){
// Get the quote item
$quote = $obs->getEvent()->getQuote();
$item = $obs->getQuoteItem();
$product_id=$item->getProductId();
$_product=Mage::getModel('catalog/product')->load($product_id);
$newprice=$_product->getPrice()+10;
Mage::log('My log entry', null, 'mylogfile.log');
// Set the custom price
$item->setCustomPrice($newprice);
$item->setOriginalCustomPrice($newprice);
// Enable super mode on the product.
$item->getProduct()->setIsSuperMode(true);
}
}
but this code adds same amount to add items in cart
my issue are
how to pass value of donate text box to observer
add donated value to product price

Get the tier prices of associated product in Magento 1.8.0

I'm using Magento 1.8.0
How can I get the tier prices of the associated product?
I'm only getting the price of the configurable product. Below is my site example:
Example: Product Apple is a configurable product thas has tier prices, $10,$20,$30. Product Apple has also an associated product like Green Apple, it has tier prices, $15,$20,$30.
My question here, is how can I get the value of my Associated products.
Thanks and Have a good Day!
You have to firstly get associated products
$product = Mage::getModel('catalog/product')->load(1); //your_product_id
$childProducts = Mage::getModel('catalog/product_type_configurable')
->getUsedProducts(null,$product);
foreach($childProducts as $child) {
$id = $child->getId();
$pro = Mage::getModel('catalog/product')->load($id); //load associated product id
if($pro['tier_price'] != NULL) {
foreach($pro['tier_price'] as $tier){
echo $tier['price'].'<br/>';
}
}
}

Magento - Promotions don't apply to downloadable files prices

Initial conditions:
Magento 1.7 installed (haven't tried with previous versions)
One (downloadable) product with multiple downloadable files, with prices added to the default product (let's say product that costs 50$ + 2 downloadable files, one free, the other an extra 50$ )
A new promotion (Catalog price rule) that applies to all products (let's say -20%)
More info about promotion:
Applies to all products, all groups, is active and applied, applies 'by percentage of original price', enable discount for subproducts -> Yes, stop further rule for processing -> No
Expected result:
Price for the product with the 50$ file: 80$ (80% from 100$)
Actual result:
Price for the product with the 50$ file: 90$ (80% from the initial 50$, and the full price for the downloadable file).
Conclusion:
The promotion doesn't apply to the extra prices that downloadable files have.
Question(s):
Is this the desired behavior for downloadable files? Or is this a bug ?
Any tips on how to modify the code (eventually create a module) to make it work as expected ? (Just tips, ie. what to extend)
Links / downloadable files its not products entities ( so it doesn't have price_index table and it doesn't treated as products )
There is 2 Ways to apply promotion in products
Catalog Price Rules
Shopping Cart Price Rules
As your question stated that you used Catalog Price Rules I have solved your question using Catalog Price Rules.
Create Module and rewrite the Model
Mage_Downloadable_Model_Product_Type
======
<global>
<models>
<downloadable>
<rewrite>
<product_type>Web_Eproduct_Model_Downloadable_Product_Type</product_type>
</rewrite>
</downloadable>
</models>
</global>
and the Code Below calculate the price of each Link on the fly ( even if you have more than one rule applied to the same product )
class Namespace_Modulename_Model_Downloadable_Product_Type extends Mage_Downloadable_Model_Product_Type {
public function getLinks($product = null)
{
$product = $this->getProduct($product);
$wId = Mage::app()->getWebsite()->getId();
$gId = Mage::getSingleton('customer/session')->getCustomerGroupId();
$catalogRules = Mage::getSingleton('catalogrule/resource_rule')->getRulesFromProduct('',$wId,$gId,$product->getId());
/* #var Mage_Catalog_Model_Product $product */
if (is_null($product->getDownloadableLinks())) {
$_linkCollection = Mage::getModel('downloadable/link')->getCollection()
->addProductToFilter($product->getId())
->addTitleToResult($product->getStoreId())
->addPriceToResult($product->getStore()->getWebsiteId());
$linksCollectionById = array();
foreach ($_linkCollection as $link) {
/* #var Mage_Downloadable_Model_Link $link */
$link->setProduct($product);
$link->setPrice($this->calcLinkPrice($catalogRules,$link->getPrice()));
$linksCollectionById[$link->getId()] = $link;
}
$product->setDownloadableLinks($linksCollectionById);
}
return $product->getDownloadableLinks();
}
public function calcLinkPrice(array $rules = array(),$productPrice = 0 )
{
foreach($rules as $ruleData)
{
$productPrice = Mage::helper('catalogrule')->calcPriceRule(
$ruleData['action_operator'],
$ruleData['action_amount'],
$productPrice);
}
return $productPrice;
}
}
I have tested it and confirmed its working as you expect :)
Try it and let me know your thoughts :)
There is another way to achieve this if you will use Shopping Cart Price Rules i will post it later.
There are 2 types of price rules in Magento, Catalog and Shopping Cart Price Rules. Catalog Rules are enacted on products before they are added to the cart, while Shopping Cart Price Rules are applied in the shopping cart.
You should set this promo as a Shopping Cart Price Rule.

Magento : Get all Shipping Rates

How can I get an array/object with the shipping rates in magento such as Flat Rate, Free Delivery etc ?
Irrelevant of the address or products selected.
Here's another way. You need to set a zip and country - even if that doesn't matter for your shipping methods.
// Change to your postcode / country.
$zipcode = '2000';
$country = 'AU';
// Update the cart's quote.
$cart = Mage::getSingleton('checkout/cart');
$address = $cart->getQuote()->getShippingAddress();
$address->setCountryId($country)
->setPostcode($zipcode)
->setCollectShippingrates(true);
$cart->save();
// Find if our shipping has been included.
$rates = $address->collectShippingRates()
->getGroupedAllShippingRates();
foreach ($rates as $carrier) {
foreach ($carrier as $rate) {
print_r($rate->getData());
}
}
you can't do it "irrelevant" as you need address data (billing or shipping if only billing then shipping set same as billing: country, zip, region dependant of your shipping methods) to be set and quote to have at least one simple item (quote existing, virtual and downloadable products don't need shipping). After that you can call on your quote object
$quote->getShippingAddress()->getGroupedAllShippingRates();
I figured it out...
$carriers = Mage::getStoreConfig('carriers', Mage::app()->getStore()->getId());
foreach ($carriers as $carrierCode => $carrierConfig) {
print_R($carrierConfig);
}
Thanks for the help

Magento: Get product price from another store?

I have multi-store Magento installation, and different product prices are set in different stores. I want to display on one page the actual product price from the current store, and the price from other store (I have its ID), but I'm not sure how to get that info?
The prices are set for each store view for each product, no tier-pricing or special-pricing was used.
If you know the storeId, set in setStoreId :
/**
* call the Magento catalog/product model
* set the current store ID
* load the product
*/
$product = Mage::getModel('catalog/product')
->setStoreId($storeId)
->load($key);
Display in a block :
echo $product->getName();
We can also use print_r to see the values :
print_r($product->getData());
The following code will show current store ID :
$storeId    = Mage::app()->getStore()->getId();
To get all product ID's with each store view :
$product    = Mage::getModel('catalog/product');
$products   = $product->getCollection()->addStoreFilter($storeId)->getData();
If you change the $storeId will show different product.

Resources