The followings are the available columns in table 'shop_currency':
Inheritance: extends ActiveRecord
 public function testField()
 {
     ShopCurrency::config()->currency_symbol = "X";
     ShopCurrency::config()->decimal_delimiter = "|";
     ShopCurrency::config()->thousand_delimiter = "-";
     ShopCurrency::config()->negative_value_format = "- %s";
     $field = new ShopCurrency("Price");
     $field->setValue(-12345.56);
     $this->assertEquals("- X12-345|56", $field->Nice());
 }
Exemple #2
0
 public function afterSave()
 {
     //Yii::app()->cache->delete(Yii::app()->currency->cacheKey);
     if ($this->default) {
         ShopCurrency::model()->updateAll(array('default' => 0), 'id != :id', array(':id' => $this->id));
     }
     if ($this->main) {
         ShopCurrency::model()->updateAll(array('main' => 0), 'id != :id', array(':id' => $this->id));
     }
     parent::afterSave();
 }
Exemple #3
0
 public function afterUninstall()
 {
     Yii::app()->settings->clear('shop');
     Yii::app()->unintallComponent('currency');
     $db = Yii::app()->db;
     $tablesArray = array(ShopTypeAttribute::model()->tableName(), ShopAttribute::model()->tableName(), ShopAttributeOption::model()->tableName(), ShopAttributeOptionTranslate::model()->tableName(), ShopAttributeTranslate::model()->tableName(), ShopCategory::model()->tableName(), ShopCategoryTranslate::model()->tableName(), ShopCurrency::model()->tableName(), ShopManufacturer::model()->tableName(), ShopManufacturerTranslate::model()->tableName(), ShopProduct::model()->tableName(), ShopProductCategoryRef::model()->tableName(), ShopProductImage::model()->tableName(), ShopProductTranslate::model()->tableName(), ShopProductType::model()->tableName(), ShopProductVariant::model()->tableName(), ShopRelatedProduct::model()->tableName(), ShopSuppliers::model()->tableName(), $db->tablePrefix . 'shop_product_attribute_eav', $db->tablePrefix . 'shop_product_configurable_attributes', $db->tablePrefix . 'shop_product_configurations');
     foreach ($tablesArray as $table) {
         $db->createCommand()->dropTable($table);
     }
     CFileHelper::removeDirectory(Yii::getPathOfAlias('webroot.uploads.product'), array('traverseSymlinks' => true));
     CFileHelper::removeDirectory(Yii::getPathOfAlias('webroot.uploads.categories'), array('traverseSymlinks' => true));
     CFileHelper::removeDirectory(Yii::getPathOfAlias('webroot.uploads.manufacturer'), array('traverseSymlinks' => true));
     return parent::afterUninstall();
 }
 public function PriceRange()
 {
     $variations = $this->owner->Variations();
     if (!$variations->exists() || !$variations->Count()) {
         return null;
     }
     $prices = $variations->map('ID', 'SellingPrice')->toArray();
     $pricedata = array('HasRange' => false, 'Max' => ShopCurrency::create(), 'Min' => ShopCurrency::create(), 'Average' => ShopCurrency::create());
     $count = count($prices);
     $sum = array_sum($prices);
     $maxprice = max($prices);
     $minprice = min($prices);
     $pricedata['HasRange'] = $minprice != $maxprice;
     $pricedata['Max']->setValue($maxprice);
     $pricedata['Min']->setValue($minprice);
     if ($count > 0) {
         $pricedata['Average']->setValue($sum / $count);
     }
     return ArrayData::create($pricedata);
 }
Exemple #5
0
 /**
  * Count total price
  */
 public function getTotalPriceAllCurrency()
 {
     $total = array();
     $data = $this->getDataWithModels();
     foreach ($data as $item) {
         $configurable = isset($item['configurable_model']) ? $item['configurable_model'] : 0;
         if ($item['currency_id']) {
             $currency = ShopCurrency::model()->cache(Yii::app()->controller->cacheTime)->findByPk($item['currency_id']);
             // print_r($currency);
             $total[$currency->iso] += ShopProduct::calculatePrices($item['model'], $item['variants'], $configurable) * $item['quantity'];
         } else {
             $total[Yii::app()->currency->main->iso] += ShopProduct::calculatePrices($item['model'], $item['variants'], $configurable) * $item['quantity'];
         }
     }
     return $total;
 }
Exemple #6
0
 public function getForm()
 {
     Yii::import('zii.widgets.jui.CJuiDatePicker');
     Yii::app()->controller->widget('ext.tinymce.TinymceWidget');
     return array('showErrorSummary' => true, 'attributes' => array('enctype' => 'multipart/form-data', 'class' => 'form-horizontal', 'id' => __CLASS__), 'elements' => array('content' => array('type' => 'form', 'title' => $this->t('TAB_GENERAL'), 'elements' => array('name' => array('type' => 'text', 'id' => 'title', 'visible' => Yii::app()->settings->get('shop', 'auto_gen_url') ? false : true), 'seo_alias' => array('type' => 'text', 'id' => 'alias', 'visible' => Yii::app()->settings->get('shop', 'auto_gen_url') || Yii::app()->settings->get('core', 'translate_object_url') ? false : true), 'sku' => array('type' => 'text', 'afterField' => '<span class="fieldIcon icon-barcode "></span>'), 'price' => array('type' => $this->use_configurations ? 'hidden' : 'text', 'afterField' => '<span class="fieldIcon icon-coin"></span>'), 'price_purchase' => array('type' => 'text', 'afterField' => '<span class="fieldIcon icon-coin"></span>'), 'pcs' => array('type' => 'text', 'visible' => Yii::app()->settings->get('shop', 'wholesale') ? true : false), 'label' => array('type' => 'dropdownlist', 'items' => self::getProductLabels(), 'empty' => Yii::t('core', 'EMPTY_DROPDOWNLIST', 1)), 'currency_id' => array('type' => 'dropdownlist', 'items' => Html::listData(ShopCurrency::model()->findAll(array('condition' => '`t`.`default`=:int', 'params' => array(':int' => 0))), 'id', 'name'), 'empty' => '&mdash; Не привязывать &mdash;', 'visible' => Yii::app()->controller->module->accept_currency), 'main_category_id' => array('type' => 'dropdownlist', 'items' => ShopCategory::flatTree(), 'empty' => '---'), 'switch' => array('type' => 'dropdownlist', 'items' => array(1 => Yii::t('app', 'YES'), 0 => Yii::t('app', 'NO')), 'hint' => $this->t('HINT_SWITCH')), 'date_create' => array('type' => 'CJuiDatePicker', 'options' => array('dateFormat' => 'yy-mm-dd ' . date('H:i:s')), 'afterField' => '<span class="fieldIcon icon-calendar-2"></span>'), 'manufacturer_id' => array('type' => 'dropdownlist', 'items' => Html::listData(ShopManufacturer::model()->findAll(), 'id', 'name'), 'empty' => $this->t('EMPTY_MANUFACTURER')), 'supplier_id' => array('type' => 'dropdownlist', 'items' => Html::listData(ShopSuppliers::model()->findAll(), 'id', 'name'), 'empty' => $this->t('EMPTY_SUPPLIERS'), 'visible' => Yii::app()->controller->module->supplier), 'short_description' => array('type' => 'textarea', 'class' => 'editor', 'hint' => Yii::app()->settings->get('shop', 'auto_fill_short_desc') ? Yii::t('ShopModule.admin', 'MODE_ENABLE', array('{mode}' => Yii::t('ShopModule.SettingsShopForm', 'AUTO_FILL_SHORT_DESC'))) : null), 'full_description' => array('type' => 'textarea', 'class' => 'editor'))), 'warehouse' => array('type' => 'form', 'title' => $this->t('TAB_WAREHOUSE'), 'elements' => array('quantity' => array('type' => 'text'), 'discount' => array('type' => 'text', 'hint' => $this->t('HINT_DISCOUNT')), 'auto_decrease_quantity' => array('type' => 'dropdownlist', 'items' => array(0 => Yii::t('app', 'NO'), 1 => Yii::t('app', 'YES')), 'hint' => $this->t('HINT_AUTO_DECREASE_QUANTITY')), 'availability' => array('type' => 'dropdownlist', 'items' => $this->getAvailabilityList()))), 'seo' => array('type' => 'form', 'title' => $this->t('TAB_SEO'), 'elements' => array('seo_title' => array('type' => 'text'), 'seo_keywords' => array('type' => 'textarea'), 'seo_description' => array('type' => 'textarea')))), 'buttons' => array('submit' => array('type' => 'submit', 'class' => 'btn btn-success', 'label' => $this->isNewRecord ? Yii::t('app', 'CREATE', 0) : Yii::t('app', 'SAVE'))));
 }
 /**
  * Select data from DB
  * @return boolean
  */
 private function updateCurrency()
 {
     Yii::import('application.modules.shop.models.*');
     Yii::log('updateCurrency()', 'info', 'cron');
     $result = true;
     $currencyArray = ShopCurrency::model()->findAll();
     Yii::log('ShopCurrency', 'info', 'cron');
     foreach ($currencyArray as $currency) {
         if ($currency->id != 1) {
             // skip UAH
             echo "processing " . $currency->iso . ": ";
             Yii::log('processing ' . $currency->iso, 'info', 'cron');
             $key = array_search($currency->iso, $this->_matches[2]);
             // find currency ID
             if ($key) {
                 $currency->rate = (double) $this->_matches[5][$key] / (double) $this->_matches[3][$key];
                 $result = $result && $currency->save(false, false);
                 if ($result) {
                     Yii::log('Refreshed', 'info', 'cron');
                 }
             } else {
                 Yii::log('Currency not found', 'info', 'cron');
             }
         }
     }
     return $result;
 }
 /**
  * Delete currency
  * @param array $id
  */
 public function actionDelete($id = array())
 {
     if (Yii::app()->request->isPostRequest) {
         $model = ShopCurrency::model()->findAllByPk($_REQUEST['id']);
         if (!empty($model)) {
             foreach ($model as $m) {
                 if ($m->main) {
                     throw new CHttpException(404, Yii::t('ShopModule.admin', 'Ошибка. Удаление главной валюты запрещено.'));
                 }
                 if ($m->default) {
                     throw new CHttpException(404, Yii::t('ShopModule.admin', 'Ошибка. Удаление валюты по умолчанию запрещено.'));
                 }
                 $m->delete();
             }
         }
         if (!Yii::app()->request->isAjaxRequest) {
             $this->redirect('index');
         }
     }
 }
 /**
  * @return array
  */
 public function loadCurrencies()
 {
     $currencies = Yii::app()->cache->get($this->cacheKey);
     if (!$currencies) {
         $currencies = ShopCurrency::model()->findAll();
         Yii::app()->cache->set($this->cacheKey, $currencies, Yii::app()->settings->get('core', 'cache_time'));
     }
     return $currencies;
 }
 public function getForm()
 {
     return new CMSForm(array('id' => __CLASS__, 'attributes' => array('class' => 'form-horizontal'), 'elements' => array('name' => array('type' => 'text'), 'switch' => array('type' => 'dropdownlist', 'items' => array(1 => Yii::t('app', 'YES'), 0 => Yii::t('app', 'NO'))), 'description' => array('type' => 'textarea'), 'currency_id' => array('type' => 'dropdownlist', 'items' => Html::listData(ShopCurrency::model()->findAll(), 'id', 'name')), 'payment_system' => array('type' => 'dropdownlist', 'empty' => '---', 'items' => $this->getPaymentSystemsArray(), 'rel' => $this->id), '<div id="payment_configuration"></div>'), 'buttons' => array('submit' => array('type' => 'submit', 'class' => 'btn btn-success', 'label' => $this->isNewRecord ? Yii::t('app', 'CREATE', 0) : Yii::t('app', 'SAVE')))), $this);
 }