/** * Save a preferred currency for a member. * @param EcommerceCurrency $currency - object for the currency */ public function SetPreferredCurrency($currency) { if ($this->owner->exists()) { if ($currency && $currency->exists()) { $this->owner->PreferredCurrencyID = $currency->ID; $this->owner->write(); } } }
function Currencies() { return EcommerceCurrency::ecommerce_currency_list(); }
/** * Standard SS Method * Adds the default currency */ function requireDefaultRecords() { parent::requireDefaultRecords(); $defaultCurrencyCode = Payment::site_currency(); if (!DataObject::get_one("EcommerceCurrency", "\"Code\" = '{$defaultCurrencyCode}'")) { $obj = new EcommerceCurrency(); $obj->Code = $defaultCurrencyCode; $obj->Name = $defaultCurrencyCode; $obj->InUse = 1; $obj->write(); } }
public function getTotalAsMoney($recalculate = false) { return EcommerceCurrency::get_money_object_from_order_currency($this->getTotal($recalculate), $this->Order()); }
function getTableValueAsMoney() { return EcommerceCurrency::get_money_object_from_order_currency($this->TableValue, $this->Order()); }
function __construct($optionalController = null, $name, FieldList $fields, FieldList $actions, $optionalValidator = null, $recommendedBuyables) { $fieldsArray = new FieldList(array(new HeaderField($this->config()->get("something_recommended_text")))); $productFieldList = new FieldList(); foreach ($recommendedBuyables as $buyable) { $template = Config::inst()->get("RecommendedProductsModifier_Form", "product_template"); if ($template) { $checkboxID = $buyable->ClassName . "|" . $buyable->ID; $arrayData = new ArrayData(array("Buyable" => $buyable, "CheckboxID" => $checkboxID, "Checkbox" => new CheckboxField($checkboxID, _t("RecommendedProductsModifier_Form.ADD", "add")))); $productFieldList->push(new LiteralField("Buyable_" . $buyable->ID, $arrayData->renderWith($template))); } else { //foreach product in cart get recommended products $imageID = $buyable->ImageID; $imagePart = ''; if ($buyable && $buyable->ImageID > 0) { $resizedImage = $buyable->Image()->SetWidth($this->Config()->get("image_width")); if (is_object($resizedImage) && $resizedImage) { $imageLink = $resizedImage->Filename; $imagePart = '<span class="secondPart"><img src="' . $imageLink . '" alt="' . Convert::raw2att($buyable->Title) . '" /></span>'; } } if (!$imagePart) { $imagePart = '<span class="secondPart noImage">[no image available for ' . $buyable->Title . ']</span>'; } $priceAsMoney = EcommerceCurrency::get_money_object_from_order_currency($buyable->calculatedPrice()); $pricePart = '<span class="firstPart">' . $priceAsMoney->NiceLongSymbol() . '</span>'; $title = '<a href="' . $buyable->Link() . '">' . $buyable->Title . '</a>' . $pricePart . $imagePart . ''; $newField = new CheckboxField($buyable->ClassName . "|" . $buyable->ID, $title); $fieldsArray->push($newField); } } $fieldsArray->push(new CompositeField($productFieldList)); $actions = new FieldList(new FormAction('processOrderModifier', $this->config()->get("add_button_text"))); // 6) Form construction parent::__construct($optionalController, $name, $fieldsArray, $actions, $optionalValidator); Requirements::javascript(THIRDPARTY_DIR . "/jquery/jquery.js"); //Requirements::block(THIRDPARTY_DIR."/jquery/jquery.js"); //Requirements::javascript(Director::protocol()."ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"); Requirements::javascript("ecommerce_alsorecommended/javascript/RecommendedProductsModifier.js"); Requirements::themedCSS("RecommendedProductsModifier", "ecommerce_alsrecommended"); }
/** * sets the display currency for the cart. * @param String $currencyCode * @return Boolean **/ public function setCurrency($currencyCode) { if ($currency = EcommerceCurrency::get_currency_from_code($currencyCode)) { if ($this->currentOrder()->MemberID) { $member = $this->currentOrder()->Member(); if ($member && $member->exists()) { $member->SetPreferredCurrency($currency); } } $this->currentOrder()->SetCurrency($currency); $msg = _t("ShoppingCart.CURRENCYUPDATED", "Currency updated."); $this->addMessage($msg, 'good'); return true; } else { $msg = _t("ShoppingCart.CURRENCYCOULDNOTBEUPDATED", "Currency could not be updated."); $this->addMessage($msg, 'bad'); return false; } }
function onBeforeWrite() { parent::onBeforeWrite(); if (!$this->CurrencyUsedID) { $this->CurrencyUsedID = EcommerceCurrency::default_currency_id(); } }
/** * * checks if a currency exists, creates it and returns it. * @param String $code * @param String $name OPTIONAL * * @return NULL | EcommerceCurrency */ public static function create_new($code, $name = "") { $code = trim(strtoupper($code)); if (!$name) { $currencies = Config::inst()->get("EcommerceCurrency", "currencies"); if (isset($currencies[$code])) { $name = $currencies[$code]; } else { $name = $code; } } $name = ucwords($name); if ($currency = EcommerceCurrency::get()->filter(array("Code" => $code))->first()) { $currency->Name = $name; $currency->InUse = true; } else { $currency = EcommerceCurrency::create(array('Code' => $code, 'Name' => $name, 'InUse' => true)); } $valid = $currency->write(); if ($valid) { return $currency; } }
/** * return null if there is less than two currencies in use * on the site. * @return DataList | Null */ function Currencies() { $list = EcommerceCurrency::get_list(); if ($list && $list->count() > 1) { return $list; } }
function getDisplayPrice() { return EcommerceCurrency::display_price($this->CalculatedTotal, $this->Order()); }
<?php /** * Reset to all default configuration settings. */ // * * * NON-ECOMMERCE SETTINGS Payment::set_site_currency('USD'); Geoip::$default_country_code = false; //i18n::set_locale(''); // * * * ECOMMERCE I18N SETTINGS EcommerceCurrency::setDecimalDelimiter('.'); EcommerceCurrency::setThousandDelimiter(''); Object::useCustomClass('SS_Datetime', 'I18nDatetime', true); // * * * SHOPPING CART, ORDER, MODIFIERS Order::set_email(null); Order::set_receipt_subject("Shop Sale Information #%d"); Order::set_modifiers(array(), true); Order::set_table_overview_fields(array('ID' => 'Order No', 'Created' => 'Created', 'FirstName' => 'First Name', 'Surname' => 'Surname', 'Total' => 'Total', 'Status' => 'Status')); Order::set_maximum_ignorable_sales_payments_difference(0.01); Order::set_order_id_start_number(0); Order::set_cancel_before_payment(true); Order::set_cancel_before_processing(false); Order::set_cancel_before_sending(false); Order::set_cancel_after_sending(false); OrderForm::set_user_membership_optional(false); OrderForm::set_force_membership(true); OrderManipulation::set_allow_cancelling(false); OrderManipulation::set_allow_paying(false); // * * * PRODUCTS ProductsAndGroupsModelAdmin::set_managed_models(array("Product", "ProductGroup", "ProductVariation", "ProductAttributeType")); Product_Image::set_thumbnail_size(140, 100);
/** * @see self::LowestVariationPrice * @return Money */ public function LowestVariationPriceAsMoney() { return EcommerceCurrency::get_money_object_from_order_currency($this->LowestVariationPrice()); }
static function setThousandDelimiter($value) { self::$thousandDelimiter = $value; }
function getDisplayPrice() { return EcommerceCurrency::display_price($this->CalculatedPrice(), null); }
function getCalculatedPriceAsMoney() { return EcommerceCurrency::get_money_object_from_order_currency($this->CalculatedPrice()); }
function addCurrencyCodeIDToOrders_290() { $explanation = "\r\n\t\t\t<h1>290. Add Curenccy to Orders</h1>\r\n\t\t\t<p>Sets all currencies to the default currency for all orders without a currency.</p>\r\n\t\t"; if ($this->retrieveInfoOnly) { return $explanation; } else { echo $explanation; } $ordersWithoutCurrencyCount = Order::get()->filter(array('CurrencyUsedID' => 0))->count(); if ($ordersWithoutCurrencyCount) { $currencyID = EcommerceCurrency::default_currency_id(); DB::query("UPDATE \"Order\" SET \"CurrencyUsedID\" = {$currencyID} WHERE \"CurrencyUsedID\" = 0"); $this->DBAlterationMessageNow("All orders ({$ordersWithoutCurrencyCount}) have been set a currency value.", 'changed'); } return 0; }
function getTotalOutstandingAsMoneyObject() { return EcommerceCurrency::display_price($this->TotalOutstanding(), $this, "", true); }
function Currencies() { return EcommerceCurrency::get_list(); }
function getCalculatedTotalAsMoney() { return EcommerceCurrency::get_money_object_from_order_currency($this->CalculatedTotal, $this->Order()); }
protected function includeGoogleAnalyticsCode() { if ($this->EnableGoogleAnalytics && $this->currentOrder && Director::isLive()) { $currencyUsedObject = $this->currentOrder->CurrencyUsed(); if ($currencyUsedObject) { $currencyUsedString = $currencyUsedObject->Code; } if (empty($currencyUsedString)) { $currencyUsedString = EcommerceCurrency::default_currency_code(); } $js = ' ga(\'require\', \'ecommerce\'); ga( \'ecommerce:addTransaction\', { \'id\': \'' . $this->currentOrder->ID . '\', \'revenue\': \'' . $this->currentOrder->getSubTotal() . '\', \'currency\': \'' . $currencyUsedString . '\' } ); ga(\'ecommerce:send\');'; Requirements::customScript($js, "GoogleAnalyticsEcommerce"); } }