I'm trying to get config values using:
$this->_scopeConfig->getValue(
$config_path,
\Magento\Store\Model\ScopeInterface::SCOPE_STORE
);
& it returns the cached value.
Is there any way to make it skip the cache without disabling it?
*I want the cache to be enabled but still bypass it for this value only.
**I also don't want to always clear the cache programmatically before getting it.
-- Any idea?
What you basically need is to query the database directly.
So Inject a Magento\Config\Model\ResourceModel\Config\Data\CollectionFactory in your class.
Then you can query the database :
$collection = $collectionFactory->create();
$collection->addScopeFilter($scope, $scopeId, $section)
The $section is the path,
$scopeId the id of the store or website depending on the scope
& $scope is either "stores" or "website" or "default".
Related
In SilverStripe 3.4.1 I want to control _config.php file values through the Admin settings. I want to set some variables in Admin > Settings > MyTab and then access these variables in _config.php.
Is there a way to access SiteConfig variables in the _config.php file?
I tried to use several different ways to get the config data:
Config::inst()
print_r/var_dump gives all the values as an array
Config::inst()->get($this->class, 'PropertyName') or $this->config()-> get('PropertyName')
Returns empty
SiteConfig::current_site_config() or any other similar variations based on the previous two
Internal Server Error
The reason I want to do this is I have a plugin that replaces some SilverStripe default action but it requires some data to be inserted. If this data is not inserted it should stay as default.
Here are some resources I have read through to try to find a solution:
http://api.silverstripe.org/3.3/class-Config.html
https://docs.silverstripe.org/en/3.0/topics/configuration/
https://docs.silverstripe.org/en/3.4/developer_guides/configuration/configuration/
https://docs.silverstripe.org/en/3.4/developer_guides/configuration/siteconfig/
The issue is DB::connect is not called at that stage in _config.php. Therefore we cannot retrieve items from the database.
What we can do is call DB::connect in our _config.php before we retrieve our SiteConfig.
Assuming our database config settings are stored in $databaseConfig, here is the code to fetch our SiteConfig:
DB::connect($databaseConfig);
$siteConfig = SiteConfig::current_site_config();
Then we can retrieve SiteConfig variables like so:
$siteConfig->Title;
I have created CRUD for global configuration parameters. I want to apply this parameters value as main config params (main.php).
I have found some way like add value of these parameters to any .inc file and perform read/write operation. Can anybody help me how can I achieve this? I am beginner in yii.
I have created table structure :
global_config :
Field | Value
pageSize | 20
admin_email| admin#example.com
main.php file as below :
.
.
{
'params' = array(
'pageSize' => 10,
'admin_email' => 'admin#example.com',
);
}
.
.
I am using config file as show above, I want to change it dynamically that it should get value from database.
So that I can make changes in config file from front-end side. I don't need to perform open/write action on main.php
In yii1 you can use params you can set this in main.php
'params'=>array(
'your_param'=>'your_value ',
...
Yii::app()->params['your_param'];
and you can set this value like a simple array poplulating the value form database
$param['yuor_param' =>$your_db_value];
You can't do this for params. As Application parameters are not really meant to be altered and if you change a value, it does not persist across different requests.
These are treated as constant in Yii, So you can't define them after running the script as config files runs at first as your code runs.
Finally, I found solution as per my requirement. I followed given below link from yii forum.
Link : http://www.yiiframework.com/wiki/304/setting-application-parameters-dynamically-in-the-back-end/
Thanks.
Following is the configuration Code for my DB cache in Yii
'dbcache'=>array(
'class'=>'system.db.CDbConnection',
'connectionString'=>'sqlite:/' . str_replace('\\','/',str_replace('C:\\','',getcwd()).'/protected/data/cache.db'),
),
And the following is my code for getting the record set and setting in the cache:
$recordset = Table1::model ()->cache(0)->find ( "primary_id=:id", array (":id" => $id) );
I have used 0 for the cache duration because I need to make it for infinite period.
Now I need to refresh my Cache. on some condition. How can I refresh the query Cache in Yii if its duration is infinite. Please help :)
First of all, setting the value as 0 doesn't mean that you are setting for Infinite Period. It does mean that you have simply Disabled the cache.
Refer the Code: Class Reference - CActiveRecord
If you want to refresh the Schema Cache, use the code as Yii::app()->schema->refresh()
I have spent hours searching to find where magento stores full county name.
We can get a full list of countries using this code:
$_countries = Mage::getResourceModel('directory/country_collection')
->loadData()
->toOptionArray(false);
This will return an array with country code and name, I investigated the directory module, and found out this call gets data from the table
directory_county
But this table don't have full county name! So where is it stored?
and how is it retrieved using that call?
Thanks in advance.
Ok so to compensate for my wrong answer. Here is how this works:
/lib/Zend/Locale/Data/en.xml - if your store is in english, else another xml in the same directoery is read. Every country is there and its code under the xml tag <territory>
The xml is cached using the Zend_Cache_Core class.
/lib/Zend/Locale.php - function getTranslation invokes the lib/Zend/Cache/Core.php class
to load from the cache.
Example: If you change the name of some country in en.xml and clear the magento cache. You will see the change when u invoke your code again.
Full country names are not stored in database. Magento uses inbuilt Zend functionality.
Check file: lib/Zend/Locale/Data/Translation.php for full list.
Use the Zend_Local translation.
<?php
$code = 'EN';
echo Mage::app()->getLocale()->getTranslation($code, 'Territory', null, 2);
?>
Use the column 'iso2_code' from the table 'directory_country' for your $code.
Magneto only stores country codes in DB, and relies for names on Zend's Locale module to provide translated names, for different locale.
By the toOptionArray method it invokes the Zend_Locale class to get the translated value.
Refer $name = Mage::app()->getLocale()->getCountryTranslation($data['value']);, which gets to Mage_Core_Model_Locale and then to Zend_Locale.
It decides which of the node from the data to read, by the switch case statement in Zend_Locale_Data::getContent() line# 962, 963
Magento caches the names, so if you make any change to XML files, make sure to clean your cache folder to get what you seek.
I am currently making a module that requires me to take an order object and make it reorder itself.. thus, creating a new order in the backend with the exact same items and credentials.
This is the code that i have thus far… it doesn’t seem to reorder the item or create and add another backend order.
$personsOrder = Mage::getModel(’sales/order’);
$personsOrder->loadByIncrementId($order[’model_order_id’]);
$order_model = Mage::getSingleton(’adminhtml/sales_order_create’);
$personsOrder->setReordered(true);
$order_model->initFromOrder($personsOrder);
/*
$order_model->save();
$order_model->place();
$order_model->sendNewOrderEmail();
*/
Any help is greatly appreciated!!
$orderId= $YOUR_ORDER_NUMBER;
$personsOrder = Mage::getModel('sales/order')->load($orderId);
$order_model = Mage::getSingleton('adminhtml/sales_order_create');
$personsOrder->setReordered(true);
$order_model->initFromOrder($personsOrder);
$order_model->createOrder();
My first thought is that you should be using $order->getIncrementId() on line 2 rather than $order['model_order_id'], but I'm not sure where you're getting $order from in the first place. Have you checked that $order['model_order_id'] is actually returning a valid increment ID? I don't see model_order_id as a field in the database anywhere...
I'd be suggesting that you getting your IDE and XDebug working so that you can inspect the objects as you work with them and understand what's going on.
Cheers,
JD
If the order that you have placed the first time around is also created through coding and not from store front then you need to make sure that you have added an entry in the sales_flat_quote_item table. Otherwise that order cannot be reordered. So make sure it's not the case with your order creation.