linking to magento website based on currency - php

Basically i need to link to my website, but i need the currency to change based on what link is used.
i need this for google adwords, if i am targeting ireland in adwords, i need my website to display euros. if i am targeting the U.K. i need it to display in Pounds and so on.
the website is developed in magento, and i have a select box at the top of my page that changes the currency throughout the website.
Any ideas how i can do this, the website is www.funkychristmasjumpers.com

Credit per this link on the Magento forums
You could always add the following bit of code to the top of your /template/directory/currency.phtml file in your theme. I've tested this in a 1.7.0.2 instance and it works nicely.
You just add cy=code to the end of the URL, so for www.funkychristmasjumpers.com it would be http://www.funkychristmasjumpers.com?cy=USD to default to USD. The code applies the currency and then redirects back to the target page
$currentCurrency = $this->getCurrentCurrencyCode();
if(!isset($currentCurrency)) $currentCurrency = 'NA';
$currencies = array("GBP","USD","EUR");
if(isset($_GET['cy']))
{
if (in_array(strtoupper($_GET['cy']),$currencies)) {
if(strtoupper($_GET['cy']) != $currentCurrency)
{
header("Location: ".$this->helper('directory/url')->getSwitchCurrencyUrl()."currency/".$_GET['cy']);
exit;
}
}
}

Related

Paypal Express Checkout demo files NVP/SOAP Demo Samples

Wonder if anyone have tried successfully the Paypal demo code`s ?
My self is trying to get the Express Checkout Flow into my custom php, and downloaded the NVP / SOAP Code Samples from https://demo.paypal.com/us/demo/download?capability=checkOutWithPaypal&lang=PHP
After input of my sandbox account details, it works very well, in-fact just as hoped. But (always a but), it seems that this setting from paypal_config.php do not work as it should be:
//Set this constant USERACTION_FLAG = true to skip review page
define("USERACTION_FLAG", false);
//Based on the USERACTION_FLAG assign the page
if(USERACTION_FLAG){
$page = 'return.php';
} else {
$page = 'review.php';
}
If you try to set that to true, when directing from Paypal, you just comes to an white page.
Anyone got this to work as it should do?
Since its an express checkout, there shouldt be needed for another "review" page, just hit Pay, and done!
Tried to locate all functions in the files, but the $page string is not anywhere to be found else than config file.
Thanks for all answers :)

Magento - Store Views and multiple currencies - Checkout using base currency always

I have a magento website
We have a store
In a store we have multiple store views (US, EU and UK)
Each store view has it's own currency, etc.
The base currency is GBP at the default config (main)
My problem is that the display currencies work well. Each store view has it's own individual price (no automatic conversion). Everything seems to be working and in order. However, on the final payment emails and actual connection with payment providers (PayPal/Sage). The base currency is always used. Although the display appears in the currency for each store view.
My question is why are the store view currencies not used with PayPal, emails, etc. Although the amounts, display currency, etc work fine?
It turns out that Base Currency can be set on each Store View. However, this option was not presented on the admin side. I had to change the system.xml
app/code/core/Mage/Directory/etc/system.xml
<label>Base Currency</label>
I have to set the appropriate to change from 0 to 1
<show_in_store>1</show_in_store>
Once this was done, I could see Base Currency under "Currency Options" even within a store view. This now works well and everything seems to be working fine.
No PHP code changes or any additional plugins required.
When I had run into this issue with a rather large Magento store, this quick fix worked pretty well for me: Magento knowledge-base paypal base currency tweak
Just note that, that fix probably won't work out of the box but it'll take some tweaking
Here it is some solutions.
You might custom some codes
If you are using Paypal Express,
\app\code\core\Mage\Paypal\Model\Express.php
protected function _placeOrder(Mage_Sales_Model_Order_Payment $payment, $amount)
{
$order = $payment->getOrder();
// prepare api call
$token = $payment->getAdditionalInformation(Mage_Paypal_Model_Express_Checkout::PAYMENT_INFO_TRANSPORT_TOKEN);
$api = $this->_pro->getApi()
->setToken($token)
->setPayerId($payment->
getAdditionalInformation(Mage_Paypal_Model_Express_Checkout::PAYMENT_INFO_TRANSPORT_PAYER_ID))
->setAmount($amount)
->setPaymentAction($this->_pro->getConfig()->paymentAction)
->setNotifyUrl(Mage::getUrl('paypal/ipn/'))
->setInvNum($order->getIncrementId())
**->setCurrencyCode($order->getOrderCurrencyCode())** // should be used getOrderCurrencyCode();
->setPaypalCart(Mage::getModel('paypal/cart', array($order)))
->setIsLineItemsEnabled($this->_pro->getConfig()->lineItemsEnabled)
;
if ($order->getIsVirtual()) {
$api->setAddress($order->getBillingAddress())->setSuppressShipping(true);
} else {
$api->setAddress($order->getShippingAddress());
$api->setBillingAddress($order->getBillingAddress());
}
// call api and get details from it
$api->callDoExpressCheckoutPayment();
$this->_importToPayment($api, $payment);
return $this;
}
\app\code\core\Mage\Paypal\Model\Standard.php
public function getStandardCheckoutFormFields()
{
$orderIncrementId = $this->getCheckout()->getLastRealOrderId();
$order = Mage::getModel('sales/order')->loadByIncrementId($orderIncrementId);
/* #var $api Mage_Paypal_Model_Api_Standard */
$api = Mage::getModel('paypal/api_standard')->setConfigObject($this->getConfig());
$api->setOrderId($orderIncrementId)
**->setCurrencyCode($order->getOrderCurrencyCode())** // should be used getOrderCurrencyCode();
//->setPaymentAction()
->setOrder($order)
->setNotifyUrl(Mage::getUrl('paypal/ipn/'))
->setReturnUrl(Mage::getUrl('paypal/standard/success'))
->setCancelUrl(Mage::getUrl('paypal/standard/cancel'));
// export address
$isOrderVirtual = $order->getIsVirtual();
$address = $isOrderVirtual ? $order->getBillingAddress() : $order->getShippingAddress();
if ($isOrderVirtual) {
$api->setNoShipping(true);
} elseif ($address->validate()) {
$api->setAddress($address);
}
// add cart totals and line items
$api->setPaypalCart(Mage::getModel('paypal/cart', array($order)))
->setIsLineItemsEnabled($this->_config->lineItemsEnabled)
;
$api->setCartSummary($this->_getAggregatedCartSummary());
$api->setLocale($api->getLocaleCode());
$result = $api->getStandardCheckoutRequest();
return $result;
}

Product URL in a shared shopping cart in Magento multi-store websites

I have Magento multi-store websites that I want that the user will be able to add products to his shopping cart from all the website and pay once.
I successfully done it using this article.
But when the user click on the product in the shopping cart, he is not redirected to the right website. It's a limitation the described in the article at the end.
The link for editing items in the cart will redirect customer to
original cart website. It is possible to change it, you can override
getUrl method for cart items block or override controller.
I couldn't find any explaination to how to do this override.
Someone can help me do this?
Thanks
In my case i seen file of cart's item.phtml, it was using getproducturl().
So, I modified that method in file /app/code/core/Mage/Checkout/Block/Cart/Item/Renderer.php line 152.
I made condition that if its main website don't change otherwise it adds stores code in url like www.example/store1/Producturl.
I hope This will Help You.
As You Require The File method. Check belowed code.
public function getProductUrl()
{
if (!is_null($this->_productUrl)) {
return $this->_productUrl;
}
if ($this->getItem()->getRedirectUrl()) {
return $this->getItem()->getRedirectUrl();
}
$product = $this->getProduct();
$option = $this->getItem()->getOptionByCode('product_type');
if ($option) {
$product = $option->getProduct();
}
$webids = $product->getWebsiteIds();
$wid = array();
foreach($webids as $webid){
$wid[] = $webid;
}
if(!in_array(1,$wid)){
$website = Mage::app()->getWebsite($wid[0])->getCode();
$org_url = $product->getUrlModel()->getUrl($product);
$mod_url = str_replace("www.example.com/index.php/","www.example.com/".$website."/index.php/",$org_url);
return $mod_url;
}
return $product->getUrlModel()->getUrl($product);
}
As my first website id was "1", that's why i used in_array(1.$wid). You Can use your main website id over there. and in str_replace u can use baseurl() method of main website instead of static value i used.

Magento multiple currencies on a single domain with no subdirectories

I am trying to set up a website that allows about 6 different currencies. I originally was able to achieve this quite well using the currency exchange rates built into Magento and the customer could select which currency they prefered and all prices were displayed in that currency. However I recently discovered that despite the prices being in that currency Magento will still process the transactions in the base currency, in this case GBP. In fact it doesn't tell the customer this is what will happen until right at the end of the order which in my opinion is a very bad thing, some customers might also be charged more by their banks for the currency conversion.
As PayPal has been configured to allow payments in the 6 currencies I would like the customers to be able to pay in those currencies.
I have since found out that due to the way Magento has been built that this is no easy task and instead you should set up a new 'website' for each of the currencies, then I can set a base currency for each website. This sounds easy enough, however the tutorials about this all seem to force each website to have its own unique url - such as either us.website.com or website.com/us - but in this case that will not do and we need everything to use only the one base url website.com.
Does anyone know if this is possible?
I have been able to change the store by manually adding the following to index.php and I was thinking one possible solution would be to remember the users selection in the session and then load the correct store here. Would this be efficient or is there a better way to do this that I have overlooked?
/* Override store code */
if (isset($_GET['code']))
{
$mageRunCode = $_GET['code'];
$mageRunType = 'website';
}
Mage::run($mageRunCode, $mageRunType);
The website is running Magento Community Edition v1.7.0.2.
I have been able to achieve this using something similar to the following in index.php
if (isset($_GET["currency"]) || !isset($_COOKIE["basewebsite"]))
{
// List of available stores
$stores = array('usd','aud','eur');
$website = 'base'; // Default store ID
if (isset($_GET['currency']) && in_array($_GET['currency'], $stores))
{
$website = $_GET['currency'];
}
// Set cookie to remember selection
setcookie("basewebsite", $website);
$_COOKIE['basewebsite'] = $website;
}
else
{
$website = $_COOKIE['basewebsite'];
}
/* Store or website code */
$mageRunCode = isset($_SERVER['MAGE_RUN_CODE']) ? $_SERVER['MAGE_RUN_CODE'] : $website;
/* Run store or run website */
$mageRunType = isset($_SERVER['MAGE_RUN_TYPE']) ? $_SERVER['MAGE_RUN_TYPE'] : 'website';
Mage::run($mageRunCode, $mageRunType);
With this I can then change the website by simply adding ?currency=usd to the end of any Magento url. The selection is then remembered by the cookie and the correct website is loaded with any further requests.
This question hasn't received many views but if anyone does spot a better solution then please do let me know!

WP Ecommerce: modifying the transaction report email sent to admin upon sale

I am looking to modify the transaction results email that is sent to the admin upon sale of an item (include and exclude certain information, etc), I've researched on google and looked on the wp-ecommerce support site and have been unable to locate where this is being done currently (a lot of references to older versions of the plugin that have since changed significantly). I will continue to look for where to do this but as I am not well versed in wp-ecommerce (or wordpress for that matter) I am not entirely sure where to look.
If anyone could shed light on this, it would be greatly appreciated.
Under wp-e-commerce/wpsc-updates/updating_tasks.php
Line 356-372 is where the email section is.
add_option('wpsc_email_receipt', '', __('Thank you for purchasing with %shop_name%, any items to be shipped will be processed as soon as possible, any items that can be downloaded can be downloaded using the links on this page.All prices include tax and postage and packaging where applicable.You ordered these items:%product_list%%total_shipping%%total_price%', 'wpsc'), 'yes');
add_option('wpsc_email_admin', '', __('%product_list%%total_shipping%%total_price%', 'wpsc'), 'yes');
if(get_option('wpsc_email_receipt') == '') {
if(get_option('email_receipt') != '') {
update_option('wpsc_email_receipt', get_option('email_receipt'));
} else {
update_option('wpsc_email_receipt', __('Thank you for purchasing with %shop_name%, any items to be shipped will be processed as soon as possible, any items that can be downloaded can be downloaded using the links on this page.All prices include tax and postage and packaging where applicable.You ordered these items:%product_list%%total_shipping%%total_price%', 'wpsc'));
}
}
if(get_option('wpsc_email_admin') == '') {
if(get_option('email_admin') != '') {
update_option('wpsc_email_admin', get_option('email_admin'));
} else {
update_option('wpsc_email_admin', __('%product_list%%total_shipping%%total_price%', 'wpsc'));
}
}
If you want to go even deeper into the whole email code, you can also go into this section
wp-e-commerce/wpsc-includes/purchase-log-notification.class.php
I created a plugin for this and many other wp e-commerce features.
With the shop styling plugin you can modify the transaction report with placeholders as well as any other mails from the wordpress backend without modifying any plugin files.

Categories