Hot answers tagged

17

This is how it can be done with customer save method: /** @var \Magento\Customer\Model\CustomerFactory $customerFactory */ /** @var \Magento\Customer\Model\Customer $customer */ /** @var \Magento\Customer\Model\Data\Customer $customerData */ $customer = $customerFactory->create() $customerData = $customer->getDataModel(); $customerData->...


15

looks like the issue was due to the fact your attributes are not assigned to the customer attribute set. the following code is needed in your install: I added full code for you at https://bitbucket.org/magstaging/newcustomerattribute $eavSetup->addAttributeToSet( CustomerMetadataInterface::ENTITY_TYPE_CUSTOMER, ...


12

Load is pretty expensive memory wise. You can use this for a faster update: Mage::getSingleton('catalog/product_action')->updateAttributes( array($productId), array('name' => $storeSpecificName), $storeId );


12

Use insertMultiple function of class Magento\Framework\App\ResourceConnection protected $connection; protected $resource; public function __construct( ... \Magento\Framework\App\ResourceConnection $resource, ... ) { $this->connection = $resource->getConnection(); $this->resource = $resource; } public function insertMultiple($...


11

No. Noooo. Not the right approach. You haven't given much information about exactly what problem you are trying to solve, but you should never be loading or saving any model directly in a template. The correct process depends on the circumstances, but you should be running your product logic in a context where you can take advantage of Dependency Injection ...


10

We forgot to unset data model after saving. $productModel->save(); $productModel->unsetData(); [EDIT] Using model Factory can solve our issue. For example, inject Company\Module\Model\ProductFactory in constructor . Inside the loop, we just need to create the factory. $product = $this->productFactory->create(); $product->setData(....); $...


9

I found the answer finally. adding: $attributeMyhkt->addData([ 'attribute_set_id' => 1, 'attribute_group_id' => 1 ]); below: $attribute->setData('used_in_forms', ['adminhtml_customer']);


9

Add the following code in your execute function of Save Controller (Module/Controller/Adminhtml/Example/Save.php) public function execute() { $resultRedirect = $this->resultRedirectFactory->create(); $data = $this->getRequest()->getPostValue(); if ($data) { try{ $id = $data['id']; ...


6

Found it! Thanks to https://magento.stackexchange.com/a/90342/4090 $_product = Mage::getModel('catalog/product')->setStoreId($storeId)->load($productId); $_product->setName($storeSpecificName); $_product->getResource()->saveAttribute($_product, 'name');


6

It is recommended to use dependency injection rather than directly using object Manager. Example: In your controller file you can use following code : protected $_product; public function __construct( \Magento\Framework\View\Element\Template\Context $context, \Magento\Catalog\Model\Product $productFactory, array $data = [] ) { ...


6

Okay, here's the situation: Because of how the product save works, $this->_productRepository->save($newProduct); does not reflect changes back onto your $newProduct. It's actually creating a new Product instance and copying your data onto it inside there. Sound slow and inefficient? Yeah. This approach probably makes data integrity easier to maintain ...


5

I'm running into this issue while upgrading from EE 1.13.0.2 to 1.14.1.0 right now. We experience this when bulk updating product attributes and stock in cronjobs. In 1.13, the jobs take ~3 seconds and ~90 seconds respectively. In 1.14, it's more like ~10 minutes and I-don't-want-to-know-how-long. There is an EE patch PATCH_SUPEE-4945_EE_1.14.0.1_v2.sh ...


5

you can used _beforeSave and _afterSave in your ResourceModel <?php namespace Spacename\Modulename\Model\ResourceModel; class Test extends \Magento\Framework\Model\ResourceModel\Db\AbstractDb { protected function _beforeSave(\Magento\Framework\Model\AbstractModel $object) { // do your logic here } ...


5

In that case you have to save() your entities, so you'll definitely have to call that method. The native core Magento file you linked is not the only one that does that, especially the mass actions action classes. The only alternative is to add a saveAttribute method to your CRUD resource model based on the one implemented in app/code/Magento/Sales/Model/...


5

You have an issue in magento log tables. first Take backup of below tables log_customer log_visitor log_visitor_info log_url log_url_info log_quote Then truncate the tables. This will resolved your issue.


5

catalog_product_save_before is one of standard events called by the Mage_Core_Model_Abstract class in its _beforeSave() method. The line looks like this: Mage::dispatchEvent($this->_eventPrefix.'_save_before', $this->_getEventData()); For every model that extends Mage_Core_Model_Abstract a set of standard events are run which other modules may hook ...


5

It's not recommended to use EntityManager and its infrastructure for your entities persistence. In the nearest future, new Persistence Entity Manager would be released which will cover all the requirements for persistence layer along with Query API as performance efficient APIs for Read scenarios. Currently, it's recommended to use Resource Model ...


4

This is a working example wich i use: $product = Mage::getModel('catalog/product'); $product->setWebsiteIds(array(1)); $product->setTypeId('simple'); $product->setName('name'); $product->setDescription('xyz'); $product->setShortDescription('&nbsp;'); ...


4

Here is a tutorial http://www.atwix.com/magento/inline-editing-in-magento-backend-grids/ It suggests you override the column renderers Mage_Adminhtml_Block_Widget_Grid_Column_Renderer_Input to allow inline editing, it will save the data as each control is edited rather than at the end with a save button.


4

This $this->_prepareDownloadResponse('invoice'.Mage::getSingleton('core/date')->date('Y-m-d_H-i-s'). '.pdf', $pdf->render(), 'application/pdf'); would send it to the browser. The below would write to a file in the var directory instead: $name = 'invoice'.Mage::getSingleton('core/date')->date('Y-m-d_H-i-s'). '.pdf'; file_put_contents(Mage::...


4

You can create a function in one of your javascript files like this: function savePackage(){ disableElements('save'); if (editForm.submit() == false){ enableElements('save'); } varienGlobalEvents.attachEventHandler('formValidateAjaxComplete', function (){ enableElements('save'); }); } Then, in your Edit.php block for ...


4

if you look at the documentation you'll find that actually the email is not optional so is needed in order to update the customer customer-data-customer-interface { id (integer, optional): Customer id , groupId (integer, optional): Group id , defaultBilling (string, optional): Default billing address id , defaultShipping (string, optional): Default shipping ...


4

Have you checked if your Custom Category Attribute has actually been added to the database because if it hasn't you should update your version number in the module.xml and run setup:upgrade Example module files for Custom Category Attribute. app/code/Vendor/Module/etc/module.xml <?xml version="1.0" ?> <config xmlns:xsi="http://www.w3.org/...


4

The product is Configurable only if it has children, otherwise, it is "converted" into a Simple product. vendor/magento/module-configurable-product/Model/Product/TypeTransitionManager/Plugin/Configurable.php public function aroundProcessProduct( \Magento\Catalog\Model\Product\TypeTransitionManager $subject, Closure $proceed, \Magento\Catalog\...


4

To fix this issue i created a custom module. https://github.com/khasru/magento2UrlRewritebug Hope it helps.


3

final update: I actually solved the problem after some heavy debugging The problem was caused after hiding "Position" column on grid by using an extension. As it turns out, Magento checks for the existence of position input field, which is included in "Position" grid column, before saving a Category Product. If the position input does not exist, it ...


3

You need to add the attribute to the quote to order service model configuration: <global> <fieldsets> <sales_convert_quote> <delivery_date> <to_order>*</to_order> </delivery_date> </sales_convert_quote> </fieldsets> </global>


3

<?php define('MAGENTO', realpath(dirname(__FILE__))); require_once MAGENTO . '/app/Mage.php'; umask(0); Mage::app()->setCurrentStore(Mage_Core_Model_App::ADMIN_STORE_ID); $count = 0; $file = fopen(MAGENTO . '/var/import/updateStockLevels.csv', 'r'); while (($line = fgetcsv($file)) !== FALSE) { if ($count == 0) { foreach ($line as $key=>...


3

My best guess is that you are hooking into an event that is working inside a transaction. In that case transaction has started at the beginning of the process and until it is committed no data are actually save into the database. Once you removed the die() the code reached commit call and you were able to see new data in the database. [EDIT answering PVL ...


3

An old post, but I was looking for the solution few days ago, so maybe I can help someone. I had a similar issue with Magento and it turned out it was not Magento's problem. It was ModSecurity installed on the server which prevented all the requests containing "select" and "from" words in this order. They were considered as "SQL injection" risky requests so ...


Only top voted, non community-wiki answers of a minimum length are eligible