Opencart change languge with currency change options - php

I am just a newbie to opencart . I have made an ecommerce wesite with it. In that website there is the feature for multilingual with multi currency converter option. Now I want that when a user clicks on his language it should also convert the currency to his language as well. So is it possible to do this with Opencart. Can someone share any codes or any reference link so that I can do that. Any help and suggestions will be highly appreciable. Thanks.

There is a currency option in the opencart admin panel , the path is something like this :
system > localisation > currencies
there you can change and add currency options related to a particular language.

if ($currency && $this->has($currency)) {
$symbol_left = $this->currencies[$currency]['symbol_left'];
$symbol_right = $this->currencies[$currency]['symbol_right'];
$decimal_place = $this->currencies[$currency]['decimal_place'];
} else {
if($_SESSION['language']=="es"):
$symbol_right = $this->currencies[$this->code]['symbol_right'];
else:
$from="USD";
$to="MXN";
$path = "http://www.google.com/ig/calculator?hl=en&q=1".$from."=?".$to;
$rawdata = file_get_contents($path);
$data = explode('"', $rawdata);
$data = explode(' ', $data['3']);
$var = $data['0'];
$e=round($var,3);
if ($e):
$number=$number / $e;
else:
$default_dollar=12.863;
$number=$number / $default_dollar;
endif;
$symbol_right=" USD";
endif;
$symbol_left = $this->currencies[$this->code]['symbol_left'];
$decimal_place = $this->currencies[$this->code]['decimal_place'];
$currency = $this->code;
}

There is a function at :\system\library\currency.php
public function format($number, $currency = '', $value = '', $format = true) {
if ($currency && $this->has($currency)) {
$symbol_left = $this->currencies[$currency]['symbol_left'];
$symbol_right = $this->currencies[$currency]['symbol_right'];
$decimal_place = $this->currencies[$currency]['decimal_place'];
} else {
$symbol_left = $this->currencies[$this->code]['symbol_left'];
$symbol_right = $this->currencies[$this->code]['symbol_right'];
$decimal_place = $this->currencies[$this->code]['decimal_place'];
$currency = $this->code;
}
if you look carefully you can change the currency here as per the language or you can use jquery to send an ajax request for the currency change.

Related

How to get variable from functions.php to page

I'm trying to get $cert_url and use it in my custom page to create a sharable link to Facebook. However, I have no idea to get the variable functions.php and pass it to custom page.
Functions.php
add_action( 'woocommerce_thankyou', 'get_cert_url' );
function get_cert_url( $order_id ) {
global $wpdb;
$msf_campaign_status = array('wc-completed');
$msf_campaign_detail = get_post_meta($order_id);
$msf_campaign_fund = $msf_campaign_detail['msf_charity_fund'][0];
$order = wc_get_order( $order_id );
if( $order->has_status('processing') ){
$name_on_e_cert = str_replace(" ", "+", $msf_campaign_detail['name_on_e_cert'][0]);
$msf_charity_name = get_option('wc_fields_billing');
if($msf_campaign_detail['charity_organizations'][0] == 'msf_charity_1'){
$charity_name = $msf_charity_name['charity_organizations']['options']['msf_charity_1'];
}
elseif ($msf_campaign_detail['charity_organizations'][0] == 'msf_charity_2') {
$charity_name = $msf_charity_name['charity_organizations']['options']['msf_charity_2'];
}
elseif ($msf_campaign_detail['charity_organizations'][0] == 'msf_charity_3') {
$charity_name = $msf_charity_name['charity_organizations']['options']['msf_charity_3'];
}
elseif ($msf_campaign_detail['charity_organizations'][0] == 'msf_charity_4') {
$charity_name = $msf_charity_name['charity_organizations']['options']['msf_charity_4'];
}
$donateto = str_replace(" ", "+", $charity_name);
$subtotal = $order->get_subtotal();
$amount = (($subtotal*25)/100);
$request = wp_remote_retrieve_body(wp_remote_get('https://www.api_website.com.my/api/c/product.ashx?key=api_key&orderid='.$order_id.'&name='.$name_on_e_cert.'&donateto='.$donateto.'&amount='.$amount.''));
$data = json_decode($request);
$result[]= $data;
foreach($result[0] as $line) {
$cert_url = $line;
}
return $cert_url;
}
}
The code below is to create a share button to share the link to Facebook.
Custom page
Share this on Facebook
May I know how can I get the $cert_url and use it on custom page? Thanks in advance !
Thank you for your answer. I solved the problem by using add_query_arg().

Trying to translate text, not working

$server_loc = $_SERVER['REQUEST_URI'];
$locations = array( '/aiesec/ar/',
'/aiesec/ar/volunteer-abroad/',
'/aiesec/ar/about/',
'/aiesec/ar/working-abroad/',
'/aiesec/ar/stories/'
);
foreach ($locations as $loc) {
if($server_loc == $loc) {
$translate['apply'] = "قدم الآن";
$translate['recent_stories'] = "قصص الأخيرة";
$translate['instagram_feed'] = "إينستاجرام تغذية";
} else {
$translate['apply'] = "APPLY NOW";
$translate['recent_stories'] = "RECENT STORIES";
$translate['instagram_feed'] = "INSTAGRAM FEED";
}
}
Hey all,
Trying to get this simple code to work.
It's a very simple translation for a small website but for some reason, it refuses to work.
$server_loc works, as it'll echo '/aiesec/ar/' when I'm on the homepage.
Why don't you use in_array
if(in_array($server_loc,$locations)){
$translate['apply'] = "قدم الآن";
$translate['recent_stories'] = "قصص الأخيرة";
$translate['instagram_feed'] = "إينستاجرام تغذية";
}

PHP Suggest Jobs within Location set by user field

Got a strange problem here on my little project, I have an account area that people can set a location so we can suggest job openings within the area they live in.
EDIT: Code indented - Sorry
The locations that do not work are "Maidstone" & "Medway". These locations are all stored in the database, When another user adds a job they can set the location the job is in and that will then add that job to the database under "State" String.
Other Locations such as Canterbury do work and the jobs that are listed under the Canterbury location show up on the users account as they should.
This php works for every location other then 2 of them which is really strange.
<?php
class SJB_Classifieds_SuggestedJobs extends SJB_Function
{
public function execute()
{
$tp = SJB_System::getTemplateProcessor();
$count_listing = SJB_Request::getVar('count_listing', 10, null, 'int');
$current_user = SJB_UserManager::getCurrentUser();
$properties = $current_user->getProperties();
foreach ($properties as $property) {
if ($property->getType() == 'location') {
$fields = $property->type->child;
$childProperties = $fields->getProperties();
foreach ($childProperties as $childProperty) {
if (in_array($childProperty->getID(), array('State'))) {
$value = $childProperty->getValue();
switch ($childProperty->getType()) {
case 'list':
if ($childProperty->getID() == 'State') {
$displayAS = $childProperty->display_as;
$displayAS = $displayAS?$displayAS:'State';
$listValues = SJB_StatesManager::getStatesNamesByCountry(false, true, $displayAS);
}
else
$listValues = $childProperty->type->list_values;
foreach ($listValues as $values) {
if ($value == $values['id'])
$phrase[strtolower($childProperty->getID())] = $values['caption'];
}
break;
default:
$phrase[strtolower($childProperty->getID())] = $value;
break;
}
}
}
}
}
$phrase = array_diff($phrase, array(''));
$phrase = implode(" ", $phrase);
$listing_type_id = "Job";
$request['action'] = 'search';
$request['listing_type']['equal'] = $listing_type_id;
$request['default_listings_per_page'] = $count_listing;
$request['default_sorting_field'] = "activation_date";
$request['default_sorting_order'] = "DESC";
$request['keywords']['relevance'] = $phrase;
$searchResultsTP = new SJB_SearchResultsTP($request, $listing_type_id, array('field'=>'keywords', 'value'=>$phrase));
$tp = $searchResultsTP->getChargedTemplateProcessor();
$tp->display('suggested_jobs.tpl');
}
}
Not sure if my problem is due to the PHP that tells which jobs to display.
Could someone just skip though the PHP and let me know if anythings wrong? I really want to work this out on my own however I'm alittle lost and if i can find out that the PHP is fine then I can figure it out some where else :)
Thanks!

Exporting Invoices from Magento

I have been trying to export all of our invoices in a specific format for importing into Sage accounting. I have been unable to export via Dataflow as I need to export the customer ID (which strangely is unavailable) and also a couple of static fields to denote tax codes etc…
This has left me with the option of using the API to export the data and write it to a CSV. I have taken an example script I found (sorry can’t remember where in order to credit it...) and made some amendments and have come up with the following:
<?php
$website = 'www.example.com';
$api_login = 'user';
$api_key ='password';
function magento_soap_array($website,$api_login,$api_key,$list_type,$extra_info){
$proxy = new SoapClient('http://'.$website.'/api/soap/?wsdl');
$sessionId = $proxy->login($api_login, $api_key);
$results = $proxy->call($sessionId,$list_type,1);
if($list_type == 'order_invoice.list'){
/*** INVOICES CSV EXPORT START ***/
$filename = "invoices.csv";
$data = "Type,Account Reference,Nominal A/C Ref,Date,Invoice No,Net Amount,Tax Code,Tax Amount\n";
foreach($results as $invoice){
foreach($invoice as $entry => $value){
if ($entry == "order_id"){
$orders = $proxy->call($sessionId,'sales_order.list',$value);
}
}
$type = "SI";
$nominal = "4600";
$format = 'Y-m-d H:i:s';
$date = DateTime::createFromFormat($format, $invoice['created_at']);
$invoicedOn = $date->format('d/m/Y');
$invoiceNo = $invoice['increment_id'];
$subtotal = $invoice['base_subtotal'];
$shipping = $invoice['base_shipping_amount'];
$net = $subtotal+$shipping;
$taxCode = "T1";
$taxAmount = $invoice['tax_amount'];
$orderNumber = $invoice['order_id'];
foreach($orders as $order){
if ($order['order_id'] == $orderNumber){
$accRef = $order['customer_id'];
}
}
$data .= "$type,$accRef,$nominal,$invoicedOn,$invoiceNo,$net,$taxCode,$taxAmount\n";
}
file_put_contents($_SERVER['DOCUMENT_ROOT']."/var/export/" . $filename, "$header\n$data");
/*** INVOICES CSV EXPORT END ***/
}else{
echo "nothing to see here";
}/*** GENERIC PAGES END ***/
}/*** END function magento_soap_array ***/
if($_GET['p']=="1")
{
magento_soap_array($website,$api_login,$api_key,'customer.list','Customer List');
}
else if($_GET['p']=="2")
{
magento_soap_array($website,$api_login,$api_key,'order_creditmemo.list','Credit Note List');
}
else if($_GET['p']=="3")
{
magento_soap_array($website,$api_login,$api_key,'sales_order.list','Orders List');
}
else if($_GET['p']=="4")
{
magento_soap_array($website,$api_login,$api_key,'order_invoice.list','Invoice List');
}
?>
This seems to be working fine, however it is VERY slow and I can’t help but think there must be a better, more efficient way of doing it…
Has anybody got any ideas?
Thanks
Marc
i think on put break; would be okey. because only one key with order_id, no need to looping after found order_id key.
if ($entry == "order_id"){
$orders = $proxy->call($sessionId,'sales_order.list',$value);
break;
}
and you can gather all call(s) and call it with multicall as example:
$client = new SoapClient('http://magentohost/soap/api/?wsdl');
// If somestuff requires api authentification,
// then get a session token
$session = $client->login('apiUser', 'apiKey');
$result = $client->call($session, 'somestuff.method');
$result = $client->call($session, 'somestuff.method', 'arg1');
$result = $client->call($session, 'somestuff.method', array('arg1', 'arg2', 'arg3'));
$result = $client->multiCall($session, array(
array('somestuff.method'),
array('somestuff.method', 'arg1'),
array('somestuff.method', array('arg1', 'arg2'))
));
// If you don't need the session anymore
$client->endSession($session);
source

How to use alphauserpoints credits towards adsmanager payment in joomla?

Are there any plugins or hacks that let me use alphauserpoints credits towards payments for adsmanager adverts in joomla?
Here is my solution for Alphauserpoints 1.7.4, Adsmanager 2.7 RC3 and PaidSystem.
Edit components\com_paidsystem\api.paidsystem.php
After defined('_JEXEC') or die( 'Restricted access' ); add the below code
//AlphaUserPoints start
$api_AUP = JPATH_SITE.DS.'components'.DS.'com_alphauserpoints'.DS.'helper.php';
if ( file_exists($api_AUP))
{
require_once ($api_AUP);
}
//AlphaUserPoints end
Next you need to edit function getBalance($userid). This is in api.paidsystem.php
function getBalance($userid)
{
//Alphauserpoints substitute for value
//Get the RefferreID of a user
$referreid = AlphaUserPointsHelper::getAnyUserReferreID((int)$userid);
$profil=AlphaUserPointsHelper:: getUserInfo ($referreid);
$value=$profil->points;
//Alphauserpoints substitute for value end
//ORIGINAL CODE BELOW
/*$db =JFactory::getDbo();
//$db->setQuery( "SELECT credit FROM #__paidsystem_credits WHERE userid=".(int)$userid );
//To explicitly convert a value to integer, use either the (int) or (integer) casts.
$value = $db->loadResult();*/
if ($value == "")
$value = 0;
return $value;
}
Then edit the next function
//EDIT this to debit credits from alphauserpoints
//Use alphauserpoints rule to debit from alphauserpoints.
function removeCredits($userid,$num,$description)
{
$db =JFactory::getDbo();
//$db->setQuery( "SELECT credit FROM #__paidsystem_credits WHERE userid=".(int)$userid );
//$balance = (float) $db->loadResult();
$referreid = AlphaUserPointsHelper::getAnyUserReferreID((int)$userid);
$profil=AlphaUserPointsHelper:: getUserInfo ($referreid);
$balance=$profil->points;
//$db->setQuery( "UPDATE #__paidsystem_credits SET credit=credit-".(float)$num." WHERE userid=".(int)$userid );
//$db->query();
echo "removeCredits=$userid,$num";
$obj = new stdClass();
$obj->userid = $userid;
$obj->balance = $balance;
$obj->change = $num * -1;
$obj->description = $description;
$obj->date = date("Y-m-d H:i:s");
AlphaUserPointsHelper::newpoints( 'plgaup_purchaseadvertising', '','', 'purchase advertising', $num*-1);
$db->insertObject("#__paidsystem_history",$obj);
}
REMEMBER: You will need to create a new rule in the administrator section of the alphauserpoints component in Joomla for this to work. In my code the new rule name was called plgaup_purchaseadvertising.

Categories