Magento: Get product price from another store? - magento

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.

Related

How to programmatically get option id's and values from configurable product in phtml?

I am modifying phtml code were I have access to
$this which happens to be Mage_Checkout_Block_Cart_Item_Renderer_Configurable class
and
$_item = $this->getItem();
$_product = $_item->getProduct();
where product is a configurable product in a cart.
Based on this I need to get a list of option id (swatches) and their values.
For example, to get specific size option id :
$product = $_item->getProduct();
$idStore = $_item->getOrder()->getStoreId();
$sizeSpecificAttributeCode = 'specific_size';
$sizeAttributeOptionId = $product->getResource()
->getAttributeRawValue($product->getId(), $sizeSpecificAttributeCode,$idStore);
from the same logic you can get the swatches or other options

How to assign categories to a new product automatically?

I am new to Magento and not familiar with it. My requirement is to assign a category to new products automatically. How could I do that?
If you have fixed category to assign when new product is saved then it can be done by observer event (like catalog_product_save_after).
When product is saved, in observer you can write code to assign that newly saved product to particular category.
Following is snippet to assign product to category.
$categories = $product->getCategoryIds();
$categories[] = $categoryId;
$product->setCategoryIds($categories);
$product->save();

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/>';
}
}
}

Upsell : get parent product from child product id

i am looking for code which can help me get parent product id from child product Id and this both products are related using upsell feature
so far i was able to retrieve child products id from parent id by using below code
//Get product detail using product id (Suppose you have product id is : $product_id)
$_product = Mage::getModel('catalog/product')->load($product_id);
// Fetch list of upsell product using query.
$upsell_product = $_product->getUpSellProductCollection();
but i want result in reverse manner
$childProductId = 17;//edit this value, or get it by $product->getId()
$productsLinkedAsUpsell = Mage::getModel('catalog/product_link')->getCollection()
->addFieldToFilter('linked_product_id', $childProductId)
->addFieldToFilter('link_type_id', Mage_Catalog_Model_Product_Link::LINK_TYPE_UPSELL);
foreach ($productsLinkedAsUpsell as $upsell) {
$parentId = $upsell->getProductId();
}

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

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);

Resources