Closed thaohientruong closed 6 years ago
@thaohientruong Magento 2.0.7 default version has the same issue?
@mrkhoa99 yup. You can check again when edit value custom option of product (like image attach above )
@thaohientruong, thank you for your report. Please try to reproduce this issue on fresh and clean installation without any third-party dependencies. Please, add the following information:
@thaohientruong, we are closing this issue due to inactivity. If you'd like to update it, please reopen the issue.
Preconditions
I add a new module with same custom option. My module is add a questionnaire with multi option and choice values. I don't save value success. Magento same bug so. When product custom option are saved with same continuity value. The first value saved success, The continued value saved fail.
Steps to reproduce
Expected result
The option and value of the custom option run loop saved. After save always update Stored Data
public function afterSave() { $this->cleanModelCache(); $this->_eventManager->dispatch('model_save_after', ['object' => $this]); $this->_eventManager->dispatch('clean_cache_by_tags', ['object' => $this]); $this->_eventManager->dispatch($this->_eventPrefix . '_save_after', $this->_getEventData()); $this->updateStoredData(); return $this; } private function updateStoredData() { if (isset($this->_data)) { $this->storedData = $this->_data; } else { $this->storedData = []; } return $this; }
But set model for save of all custom option is one. (for both model saved option and values) `public function saveOptions() { foreach ($this->getOptions() as $option) { $this->_validatorBeforeSave = null; $this->setData( $option )->setData( 'product_id', $this->getProduct()->getId() )->setData( 'store_id', $this->getProduct()->getStoreId() ); /* Reset is delete flag from the previous iteration / $this->isDeleted(false);Before check defirrent change between new value and store data. `protected function prepareDataForUpdate($object) { $data = $object->getData(); foreach ($object->getStoredData() as $key => $value) { if (array_key_exists($key, $data) && $data[$key] === $value) { unset($data[$key]); } } $dataObject = clone $object; $dataObject->setData($data); $data = $this->_prepareDataForTable($dataObject, $this->getMainTable()); unset($data[$this->getIdFieldName()]); unset($dataObject);
` I fixed set new model with each loop. But it's not good solution. Do you have any solution?