2

I try to change the currency from "RON" to "USD" in a programmatically order but i don't know how. I also want to add the Store in the order (Purchased from (store)) like in the attached picture

enter image description here but again, i can't find anything about this. My code looks like this:

//take all product sku
            foreach($product as $key => $value){
                $sku_qty = implode(" ",$value);
                $sqk_qty_array = explode(";",$sku_qty);
                $sku = ($sqk_qty_array[1]);
                $sku_array = explode(".", $sku);
                $products[] = $sku_array[0]."-".$sku_array[0].".".$sku_array[1]."-".$sku_array[2]." ".$sqk_qty_array[2];    
            }
            //take products id by sku
            $products_id = array();
            foreach($products as $key=> $value){
                 //take the sku from array without qty
                $sku_no_qty = explode(" ",$value);
                $sku = $sku_no_qty[0];
                $item = Mage::getModel('catalog/product');
                $id = Mage::getModel('catalog/product')->getResource()->getIdBySku($sku);
                $product_id_qty[] = $id."-".$sku_no_qty[1];
                $products_id []=$id;
            }

            //add order by script
            $email = "[email protected]";
            $productids = $products_id;
            $websiteId = Mage::app()->getWebsite()->getId();
            $store = Mage::app()->getStore();
            // Start New Sales Order Quote
            $quote = Mage::getModel('sales/quote')->setStoreId($store->getId());
            //products count
            $prod_num = count($products_id);
            // Set Sales Order Quote Currency
            $quote->setCurrency($order->AdjustmentAmount->currencyID);
            $customer = Mage::getModel('customer/customer')
                    ->setWebsiteId($websiteId)
                    ->loadByEmail($email);
            if ($customer->getId() == "") {
                $customer = Mage::getModel('customer/customer');
                $customer->setWebsiteId($websiteId)
                        ->setStore($store)
                        ->setFirstname('Client')
                        ->setLastname('Jolidon')
                        ->setEmail($email)
                        ->setPassword("password");
                $customer->save();
            }

            // Assign Customer To Sales Order Quote
            $quote->assignCustomer($customer);
            // Configure Notification
            $quote->setSendCconfirmation(1);
            foreach ($product_id_qty as  $id)
            {   $split = explode("-", $id);
                $id=$split[0]; 
                $qty =$split[1];
                $product = Mage::getModel('catalog/product')->load($id);
                $quote->addProduct($product, new Varien_Object(array('qty' => $qty)));
            }

            // Set Sales Order Billing Address
            $billingAddress = $quote->getBillingAddress()->addData(array(
                'customer_address_id' => '',
                'prefix' => '',
                'firstname' => 'Client',
                'middlename' => 'Client',
                'lastname' => 'Client',
                'suffix' => '',
                'company' => '',
                'street' => array(
                    '0' => '',
                    '1' => 'Client64'
                ),
                'city' => 'Client',
                'country_id' => 'Client',
                'region' => 'Client',
                'postcode' => 'Client',
                'telephone' => 'Client',
                'fax' => 'Client',
                'vat_id' => '',
                'save_in_address_book' => 1
                    ));

            // Set Sales Order Shipping Address
            $shippingAddress = $quote->getShippingAddress()->addData(array(
                'customer_address_id' => '',
                'prefix' => '',
                'firstname' => 'Client',
                'middlename' => 'Unic',
                'lastname' => 'Client',
                'suffix' => '',
                'company' => '',
                'street' => array(
                    '0' => 'Client',
                    '1' => '45'
                ),
                'city' => 'Client',
                'country_id' => 'Client',
                'region' => 'Client',
                'postcode' => 'Client',
                'telephone' => 'Client',
                'fax' => 'Client',
                'vat_id' => '',
                'save_in_address_book' => 1
                    ));
            if ($shipprice == 0) {
                $shipmethod = 'freeshipping_freeshipping';
            }

            // Collect Rates and Set Shipping & Payment Method
            $shippingAddress->setCollectShippingRates(true)
                    ->collectShippingRates()
                    ->setShippingMethod('flatrate_flatrate')
                    ->setPaymentMethod('checkmo');

            // Set Sales Order Payment
            $quote->getPayment()->importData(array('method' => 'checkmo'));

            // Collect Totals & Save Quote
            $quote->collectTotals()->save();

            try {
                // Create Order From Quote
                $service = Mage::getModel('sales/service_quote', $quote);
                $service->submitAll();
                $increment_id = $service->getOrder()->getRealOrderId();
            }
            catch (Exception $ex) {
                echo $ex->getMessage();
            }
            catch (Mage_Core_Exception $e) {
                echo $e->getMessage();
            }

            // Resource Clean-Up
            $quote = $customer = $service = null;

            // Finished
            return  $this->_redirectUrl

Does anyone have any idea how to do this?

1
  • for change the currency in order i found this answer: Mage::app()->getStore($storeId)->setCurrentCurrency(Mage::getModel('directory/currency')->load('EUR')); but this code should be put before $quote->collectTotals()->save(); Commented Apr 20, 2017 at 11:25

1 Answer 1

1

Solution:

 Mage::app()->getStore($storeId)->setCurrentCurrency(Mage::ge‌​tModel('directory/cu‌​rrency')->load('EUR'‌​)); 

but this code should be put before $quote->collectTotals()->save();

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.