I'm consuming json requests from an outside server to update products and such in Magento (please don't ask why we didn't just use the the api's ... ) and I'm now trying to update the attribute information and it seems to be failing the _uniqueCheck() method in the resource abstract. The problem is i don't know how to fix it. The following code
$attribute_model = Mage::getModel('eav/entity_attribute');
$attributeId = $attribute_model->getIdByCode('catalog_product', $attribute_code);
$attribute = $attribute_model->load($attributeId);
$attribute->setData($data)->save();
results in the following error:
[29-May-2013 16:32:00 UTC] PHP Fatal error: Uncaught exception 'Mage_Core_Exception' with message 'Attribute with the same code already exists.' in .../app/Mage.php:594
Stack trace:
#0 .../app/code/core/Mage/Core/Model/Resource/Db/Abstract.php(676): Mage::throwException('Attribute with ...')
#1 .../app/code/core/Mage/Core/Model/Resource/Db/Abstract.php(424): Mage_Core_Model_Resource_Db_Abstract->_checkUnique(Object(Mage_Eav_Model_Entity_Attribute))
#2 .../app/code/core/Mage/Core/Model/Abstract.php(318): Mage_Core_Model_Resource_Db_Abstract->save(Object(Mage_Eav_Model_Entity_Attribute))
#3 .../app/code/local/Valoran/Import/Model/Attribute.php(25): Mage_Core_Model_Abstract->save()
#4 .../app/code/local/Valoran/Harmony/Model/Messaging/Attributeset.php(115): Valoran_Import_Model_Attribute->_create(Array)
#5 .../app/code/local/Valoran/Harmony/Model/Messaging/Attributeset.php(23): Valoran_Harmony_Model_Messaging_Attribut in .../app/Mage.php on line 594
This is frustrating for me because I know the code all ready exists, I'm trying to do an update that's why I called ->load($id) ....
Does anyone have any thoughts on what I'm missing here? I'm now exploring using the Mage_Eav_Model_Entity_Setup::updateAttribute method to accomplish this but so far I'm running into the same error.
I see two possible reasons why this is happening. Both of them are related with the use of setData() method. When you call it with an array as argument it will just replace the protected property $_data of the model. This property contains all information that are loaded/saved to the database.
I suspect that in your $data variable you do not have entity_attribute_id key. If this is the case when calling setData() you are removing id of the loaded attribute. You might be using attribute_code that is already used by another attribute in the system.
Anyway when you are saving the attribute magento checks for entity_attribute_id and if it is empty magento assumes that you want to create new attribute so it performs validation for the new attribute. This results in finding an attribute with the same code which is illegal and throws error. This attribute might be the one you loaded but you have removed the entity_attribute_id property or another with the same attribute_code
If you do not want to use Mage_Eav_Model_Entity_Setup::updateAttribute you could try calling
$attribute = $attribute_model->load($attributeId);
$data['entity_attribute_id'] = $attribute->getEntityAttributeId();
$attribute->setData($data)->save();
Related
I am facing the issue with order placing on Magento ver. 2.2.2. After complete the payment when I will redirect to website https://domainname/paypal/express/placeOrder/ page and error display on that page.
Please check the error below,
Fatal error: Uncaught Error: Class 'Spyc' not found in
/public_html/app/code/DeviceDetector/Yaml/Spyc.php:17 Stack trace: #0
/public_html/app/code/DeviceDetector/Parser/ParserAbstract.php(155):
DeviceDetector\Yaml\Spyc->parseFile('/p...') #1
/public_html/app/code/DeviceDetector/Parser/ParserAbstract.php(243):
DeviceDetector\Parser\ParserAbstract->getRegexes() #2
/public_html/app/code/DeviceDetector/Parser/Bot.php(53):
DeviceDetector\Parser\ParserAbstract->preMatchOverall() #3
/public_html/app/code/DeviceDetector/DeviceDetector.php(623):
DeviceDetector\Parser\Bot->parse() #4
/public_html/app/code/DeviceDetector/DeviceDetector.php(587):
DeviceDetector\DeviceDetector->parseBot() #5
/public_html/app/code/MageWorx/OrdersBase/Observer/OrderPlaced.php(107):
DeviceDetector\DeviceDetector->parse() #6
/public_html/vendor/magento/framework/Event/Invoker/InvokerDefault.php(72):
MageWorx\OrdersBase\Observer\OrderPlaced- in
/public_html/app/code/DeviceDetector/Yaml/Spyc.php on line 17
The error is seems related to the DeviceDetector plugin but I don’t know why this issue happen & I have check the particular lines mentioned in error but no solution found.
Please let me know how to resolve this issue. Thanks in Advance!
Can you add more details here, after what action this error start appear?
If you inject this class somewhere in constructor then I suggest you to run rm -rf generated/* because M2 dont update generated folder automatically if you change class that already generated in generation.
If its not work please share some context.
I am getting this fatal error:
PHP Fatal error:
Uncaught exception 'Exception' with message
'Serialization of 'Mage_Core_Model_Config_Element' is not allowed'
in [no active file]:0 Stack trace: #0 {main}
thrown in [no active file] on line 0
I understand it is trying to serialize Mage_Core_Model_Config_Element and failing, yet I have never used getNode(), it's always getStoreConfig() for me.
I am happy to debug this, if I could just find WHERE it is being generated. Where is the Magento session being serialized?
Note: trying to echo the serialization in footer (like one thread suggested) does not work in this case. The session is not being set (cause of this error) and so there is no error when it gets to the footer...
I have found the error that caused this. However was interested in finding out where is the place to debug this, but as there is no proper answer to this, no reason to wait longer.
Anyways, the problem is adding a model object to session, which obviously then is a no-no. At one point or another it must contain that class of an element.
I am new to yii2 and php web app development. I am using dep-drop for selecting input
depending on parent selection. Now I get an error message in yii2 debugger,
exception 'yii\base\ErrorException' with message 'Class 'app\controllers\Response' not found' in G:\xampp\htdocs\project\controllers\SalesOrderController.php:129 Stack trace: #0 [internal function]: yii\base\ErrorHandler->handleFatalError() #1 {main}
Just adding an update because at least in one hand the answer from above can be misleading.
I think that beside issue you mentioned above you had additional issue which is resolved by adding "use yii\helpers\Json;" or something similar because Response is not within namespace you mentioned.
If you want to have a Json Output from your controller and if you want to use Response class for managing action output you will need to use
use yii\web\Response;
Additionally, example of usage:
public function actionApi() {
Yii::$app->response->format = Response::FORMAT_JSON;
return array(
"test" => "test",
"test2" => "test2"
);
}
Sorry It was my mistake.
I just included this :
use yii\helpers\Json;
Problem Solved. And dep dropdown is now working as expected
please use this code.
use yii\web\Response;
Receiving this fatal error when trying to access my planner.php and shared.php controllers. Any thoughts?
Fatal error: Uncaught exception 'Exception' with message 'Undefined method Ion_auth::get_user() called' in
/application/libraries/Ion_auth.php:88 Stack trace: #0
/application/core/MY_Controller.php(50): Ion_auth->__call('get_user', Array) #1
/application/core/MY_Controller.php(50): Ion_auth->get_user() #2
/application/controllers/user/planner.php(9): Common_Auth_Controller->__construct() #3
/system/core/CodeIgniter.php(288): Planner->__construct() #4 /index.php(202): require_once('/Users/lrussell...') #5 {main} thrown in/application/libraries/Ion_auth.php on line 88
Library Extension I'm Using for Ion Auth:
http://jondavidjohn.com/blog/2011/01/scalable-login-system-for-codeigniter-ion_auth
Planner Controller:
http://pastie.org/private/wc1bq6eiqb9hn8iubwdgq
Shared Controller:
http://pastie.org/private/uj3ta8dw3jl7kqxizs9n1a
Ion_auth Library Line 88 Segment:
http://pastie.org/private/mhgwdzjyhatwsdrux4gqpa
CRUD Model:
http://pastie.org/private/m2nhfqzabdsx5eiz6xqupw
Events Model:
http://pastie.org/private/b6ksjoowl7wde9errow
Shared Model:
http://pastie.org/private/f741jfnf8o2l5oxphnrl5w
Uhm, it happened to me the same exact thing. In the latest releases of this library, Ben Edmunds used php magic method __call() so that you don't have to call a model's method by using the regular syntax $this->ion_auth_model->method() but using instead $this->ion_auth->method(), as if it was a method belonging to the library.
But, actually, that method belongs to the model. So, if you go have a look at the model, you'll see that there's no get_user() method (nor is there in the library!), or at least in the version I talk about (the latest or the one just before. I downloaded a fresh copy one or two weeks ago).
I think there are some errors in the documentation he provided (though the overall work he did is awesome, kudos to Ben).
You can try using the user() model method, which should yield to the same result (it's the closer in functionality). So call $this->ion_auth->user() and see if that fits your needs.
EDIT
To clarify... instead of this...
$this->end_user = $this->ion_auth->current()->row();
do this...
$this->end_user = $this->ion_auth->user()->row();
This is my first experience using the Zend Framework. I am attempting to follow the Quick Start tutorial. Everything was working as expected until I reached the section on the Error Controller and View. When I navigate to a page that does not exist, instead of receiving the error page I get the Fatal Error screen dump (in all it's glory):
Fatal error: Uncaught exception 'Zend_Controller_Dispatcher_Exception'
with message 'Invalid controller specified (error)' in
/home/.fantasia/bcnewman/foo.com/library/Zend/Controller/Dispatcher/Standard.php:249
Stack trace: #0
/home/.fantasia/bcnewman/foo.com/library/Zend/Controller/Front.php(946):
Zend_Controller_Dispatcher_Standard->dispatch(Object(Zend_Controller_Request_Http),
Object(Zend_Controller_Response_Http)) #1
/home/.fantasia/bcnewman/foo.com/public/index.php(42):
Zend_Controller_Front->dispatch() #2 {main} thrown in
/home/.fantasia/bcnewman/foo.com/library/Zend/Controller/Dispatcher/Standard.php
on line 249
I do not believe this is caused by a syntax error on my part (a copied and pasted the example file's content from the tutorial) and I believe I have the application directory structure correct:
./application
./application/controllers
./application/controllers/IndexController.php
./application/controllers/ErrorHandler.php
./application/views
./application/views/scripts
./application/views/scripts/index
./application/views/scripts/index/index.phtml
./application/views/scripts/error
./application/views/scripts/error/error.phtml
./application/bootstrap.php
./public
./public/index.php
And finally, the IndexController and index.phtml view does work.
You have ErrorHandler.php. It should be ErrorController.php. Controllers all need to be named following the format of NameController.php. Since you don't have it named properly the dispatcher cannot find it.
Assuming that you have the ErrorController plugin loaded into your front controller, make sure that in your bootstrap that you do not have the following set:
$frontController->throwExceptions(true);
If this is set then Exceptions will always be thrown, regardless of whether or not you have an error controller set.