Jump to content
  • 0

Last Attempt, changing initial currency


Tiny

Question

Hi all,

for some legal reasons, I need default currency VND , ONLY for non-logged in users. My real default currency is USD, which must remain.

As failing with support and time running out, keeping all offline and playing with the code .................., This is a last week, I can burn into this matter .

There must be somewhere a point, in some file, possible similar  "$this-> currency ... set curency "VND" "

in fact, partially working, not all over, even some weblink redirection does work:      when adding:  '?currency=USD'

 $( document ).ready(function() {

          $('#change_currency').find('option[value=VND]').attr('selected','selected');
    });
--------html------------

<div class="row">
 <div class="col-md-5 col-sm-5 col-xs-5">
 <form method="GET" action="/order/summary/index/Hosting%20Packages">
<div class="form-group currency-selector">
  <select name="currency" class="form-control input-sm" id="change_currency">
<option value="USD" selected="selected">USD</option>
<option value="VND">VND</option>
</select>
</div>
  </form>
<div class="col-md-7">
</div>
</div>

-------------------------------------------------------------

The above works partially only, and only then, when at the packes, eg: 20Packages/?group_id=19 &currency=VND.

I assume strong, that is also via a php one-liner possible, something like  "$this-> currency ... set curency "VND" "

Anyone out there, who can push me in the right direction before I leave or pause the blesta world?

Again, the  DEFAULT USD MUST REMAIN intact, only the for non-logged in customers, the VND must show initial.

Tiny

 

 

 

 

 

right2.png

wrong2.png

right.png

wrong.png

Link to comment
Share on other sites

16 answers to this question

Recommended Posts

  • 0

this can be done by editing the order plugin .

how many order form you have, as blesta dind't have universal carts, so every order form has it own cart.

please look at order_form_controller.php , the fucntion   setCurrency(), i believe this is the function responsible for setting the currency for users in order form.

Link to comment
Share on other sites

  • 0

Hi,

 

yes, thank you. So far, I am already, but when looking in detail, it does ot happen....

my basic understanding of php, which I seriously hate, it would be something like

   code:             (isset($_POST["currency"])) ? $currency = $_POST["currency"] : $currency="USD";

to turn the 

<select name="currency" class="form-control input-sm" id="change_currency">
<option value="USD">USD</option>
<option value="VND" selected="selected">VND</option>
</select>

to the VND, trying about line 159. However, the fu...r doesn't.

On some places, it's also possible to set the query string ?currency=VND  for changing, however, I don't see a way, to apply that before, so that it is applied already for the domain

Tiny

 

Link to comment
Share on other sites

  • 0
3 minutes ago, Blesta Addons said:

a simple tip is to add the fallowing code in set setCurrency()


    protected function setCurrency()
    {			
		if (!$this->client) {
			$this->SessionCart->setData('currency', 'VND');			
		}
		
		....
		....

 

I have laced this in in line 159, however, now only a white screen :(

Any idea, where that should be placed, a line number?

Tiny

Link to comment
Share on other sites

  • 0
    /**
     * Sets the ISO 4217 currency code to use for the order form
     */
    protected function setCurrency()
    {
        // Set custom currency for no logged in users
        if (!$this->client) {
            $this->SessionCart->setData('currency', 'VND');			
        }	
        // If user attempts to change currency, verify it can be set
        // Currency can only be changed if cart is empty
        if (isset($this->get['currency']) && $this->SessionCart->isEmptyCart()) {
            foreach ($this->order_form->currencies as $currency) {
                if ($currency->currency == $this->get['currency']) {
                    $this->SessionCart->setData('currency', $currency->currency);
                    break;
                }
            }
        } elseif (!isset($this->get['currency']) && $this->SessionCart->isEmptyCart()) {
            // If a queued item for the cart exists, verify and set its pricing currency for the order form
            $cart = $this->SessionCart->get();
            if ($this->SessionCart->isEmptyCart() && !$this->SessionCart->isEmptyQueue()
                && !$this->SessionCart->getData('currency')
                && ($queue_item = $this->SessionCart->checkQueue()) && count($cart['queue']) == 1) {
                $pricing_id = $queue_item['pricing_id'];

                // Fetch the package info for the selected pricing ID
                if (($package = $this->Packages->getByPricingId($pricing_id))) {
                    // Find the matching pricing
                    foreach ($package->pricing as $pricing) {
                        // Set the queued pricing currency as the form currency
                        if ($pricing->id == $pricing_id) {
                            foreach ($this->order_form->currencies as $currency) {
                                if ($currency->currency == $pricing->currency) {
                                    $this->SessionCart->setData('currency', $currency->currency);
                                    break;
                                }
                            }
                            break;
                        }
                    }
                }
            }
        }

        // If no currency for this session, default to the company's default currency,
        // or the first available currency for the order form
        if ($this->SessionCart->getData('currency') == null) {
            $temp = $this->Companies->getSetting($this->company_id, 'default_currency');
            if ($temp) {
                $company_currency = $temp->value;
            }

            foreach ($this->order_form->currencies as $currency) {
                if ($currency->currency == $company_currency) {
                    $this->SessionCart->setData('currency', $currency->currency);
                    break;
                }
            }

            if ($this->SessionCart->getData('currency') == null && isset($this->order_form->currencies[0]->currency)) {
                $this->SessionCart->setData('currency', $this->order_form->currencies[0]->currency);
            }
        }
    }

 

Link to comment
Share on other sites

  • 0
3 minutes ago, Blesta Addons said:

if you don't want to change the blesta files you can remove usd currency from order form setting and set only vnd, then all users/client will be forced to use vnd .

Yes, but that works even worse, than using VND as main currency

I have no issue with editing some files, however, I need multi currency, because we are working in 6 currencies. Only reduced to get a start. Despite, your code loks decent, It's not working in my thing

Burned that much hours and not even can sell a single thing. I not have the currency issue solved by coming saturday, I need to switch back to whmcs

... and tons of further issues after that "default" selection remain

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...