Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Product save via Repository on defined storeID-> Attributes with default value gets set. #12881

Closed
versdivers opened this issue Dec 26, 2017 · 14 comments
Assignees
Labels
Issue: Clear Description Gate 2 Passed. Manual verification of the issue description passed Issue: Format is valid Gate 1 Passed. Automatic verification of issue format passed Issue: Ready for Work Gate 4. Acknowledged. Issue is added to backlog and ready for development Reproduced on 2.1.x The issue has been reproduced on latest 2.1 release Reproduced on 2.2.x The issue has been reproduced on latest 2.2 release Reproduced on 2.3.x The issue has been reproduced on latest 2.3 release

Comments

@versdivers
Copy link

versdivers commented Dec 26, 2017

I know some topics on this github does 'address' these problems. But they don't seem to cover it all or provide any kind of quickfix.

Since this is a BIG issue within Magento 2 we need a steady fix.

What happends is when you save a product trough the productrepository (or even trough other means) the product data contains all the values. Even if in the backend 'use default value' is checked then the getData() shows that they return the value of their parent.

When you save this product with limited information it does save all the data and it will save the data from the default config in the store view instead.

This combined with the fact that you can not save a price / website but you need to save a price / storeview this is a big big big issue!!

Preconditions

  1. Magento 2.2.1 CE
  2. PHP 7+

Steps to reproduce

  1. Create a website with multiple store views
  2. Use product repository to get product
  3. setPrice() of the product
  4. setStoreId() of the product
  5. save the product using product repository

Expected result

  1. Price and price only has been changed for the storeview

Actual result

  1. All the attributes with a default value are saved and changed under the storeview overwriting the Default Value and unchecking the checkbox 'use default value';

Code that is used (shortened)

// Magento\Catalog\Model\ProductRepository
 $productrep = $this->_productRepository;
// Magento\Catalog\Model\Product
$productarray = $this->_magentoproducts;

 $product = $productrep->get($sku, true , $storeid);
$productarray
 ->setId($product->getId())
->setStoreId($storeid)
->setSku($product->getSku())
->setPrice($price);

//or

$product
->setPrice($price)
->setStoreId($storeid);

 $productrep->save($productarray);

// or

$productrep->save($product);

@versdivers
Copy link
Author

versdivers commented Dec 26, 2017

I would appriciate any kind of help to get a quickfix for this. I tried numerous things but didn't manage to have a stable fix.

If anyone can comfirm if this is fixed in Magento 2.2.2 or even if this is scheduled for 2.3 please let me know

@magento-engcom-team magento-engcom-team added the Issue: Format is valid Gate 1 Passed. Automatic verification of issue format passed label Dec 26, 2017
@versdivers
Copy link
Author

For someone who wants to score some points on stackexchange :

https://magento.stackexchange.com/questions/207123/product-update-storeview-vs-default-config-value

@versdivers
Copy link
Author

The only solution that i found was to work with the recource model of the product and using 'insert' and 'update' function directly into the database table. Which is a bad practice

@koenner01
Copy link
Contributor

related to #9186, #9389, #8897

we have also reported this issue on the magento cloud support and there supposedly is a fix in 'triage' (meaning that they still have to start on fixing this)

@koenner01
Copy link
Contributor

snippet of the wall of text from our cloud support ticket:

  1. Setup a clean 2.2.2 installation

  2. Create a new (extra) storeview:
    => Store='Main Website Store'
    => Name='Some Random Storeview'
    => Code='random'
    => Status='Enabled'
    => Sort Order='0'

  3. Make sure the shop is using flat tables
    => Stores > Configuration > Catalog > Catalog > Storefront > Use Flat Catalog Category = Yes
    => Stores > Configuration > Catalog > Catalog > Storefront > Use Flat Catalog Product = Yes

  4. Create a simple product and save it
    => Fill in all required attributes with random stuff
    => Fill in all fields with storeview/website scope in all the closed tabs
    => Make sure to add 2 random images and set the 1th as base/small_image/thumbnail/swatch

  5. Take note of the values in the database:

  • catalog_product_entity_int
  • catalog_product_entity_text
  • catalog_product_entity_text

Break stuff through the backend:

  1. Switch the storeview to our newly created 'random' storeview
    => Don't change any data AND DON'T OPEN ANY TABS

  2. Save the product on storeview scope
    => If you look at the closed tabs after the product save reloaded the page, you will see that the 'use default value' checkboxes have all been unchecked

  3. Take note of the values in:

  • catalog_product_entity_int
  • catalog_product_entity_text
  • catalog_product_entity_text
    => All attributes from the closed tabs that have storeview/website scope have just had a value saved to the database
  1. Switch back to the 'All store views' scope

  2. Change all product attributes that have scope storeview or website with new values and save the product
    => Make sure to select the 2th image as base/small_image/thumbnail/swatch!
    => Make sure to change the meta_title, meta_keywords and meta_description

  3. Take note of the values in:

  • catalog_product_entity_int
  • catalog_product_entity_text
  • catalog_product_entity_text
    => The values with store_id 0 will contain the correct value
    => values saved to the database for our new storeview during step 7 are incorrect
  1. Look at the frontend where the product is using the incorrect data on our 'random' storeview
    => the image used as base/small_image/thumbail/swatch is wrong
    => the meta data in the header is wrong

The problem can be split into multiple origins:

  • Part of the problem lies with the fact that closed tabs will uncheck all 'use default value' checkboxes. This causes discrepancies between values on storeviews because (unwanted) values are being saved to the database.
    You cannot assume that a user will open all tabs when he is editting a product, just to make sure the 'use default value' checkboxes get saved properly

  • Another part of the problem is the fact that for images there is no 'use default value' option. This will cause problems on the frontend when the user assumes the value of default is being used, while actually an incorrectly saved value is being used.

Break stuff through the api:

  1. Update the product's name through the api:
    => PUT '../rest/{OurRandomStoreviewCode}/V1/products/{createdProductSku}
    => request body: {"product":{"name":"Test API"}}

  2. Take note of the values in:

  • catalog_product_entity_int
  • catalog_product_entity_text
  • catalog_product_entity_text
    => Besides the product's name being updated on the storeview, the database tables got filled with unwanted values for attributes that have scope storeview/website

I can't even wrap my head around this problem.
We are updating 1 attribute but the database is being filled with a lot of other (unwanted) values. If we now check the product through the adminhtml the same behaviour as the closed tabs was reproduced. All attributes in the closed tabs have had their 'use default value' checkbox unchecked...

@magento-engcom-team magento-engcom-team added the Issue: Clear Description Gate 2 Passed. Manual verification of the issue description passed label Mar 2, 2018
@magento-engcom-team
Copy link
Contributor

@versdivers, thank you for your report.
We've acknowledged the issue and added to our backlog.

@magento-engcom-team magento-engcom-team added Issue: Ready for Work Gate 4. Acknowledged. Issue is added to backlog and ready for development Issue: Confirmed Gate 3 Passed. Manual verification of the issue completed. Issue is confirmed Reproduced on 2.1.x The issue has been reproduced on latest 2.1 release Reproduced on 2.2.x The issue has been reproduced on latest 2.2 release Reproduced on 2.3.x The issue has been reproduced on latest 2.3 release labels Mar 2, 2018
@Chuvisco88
Copy link

What is the estimate for this issue?

@versdivers
Copy link
Author

Any updates?

@mad-develop
Copy link

mad-develop commented Jun 8, 2018

Fieldsets seem to only render form fields when getting expanded. If its not expanded, there seem to be some values missing in the POST.

Creating a little mixin for the fieldset component, so the form fields gets created automatically, seem to fix this specific issue.

I'm still testing, but it seems to be a valid (maybe dirty) solution, until it gets fixed the way it should.

Magento Version 2.2.4

Step1: Create Module
Step2: Create Mixin

File: Vender\Module\view\adminhtml\requirejs-config.js

var config = {
    'config': {
        'mixins': {
            'Magento_Ui/js/form/components/fieldset': {
                'Vender_Module/js/form/components/fieldset': true
            }
        }
    }
};

File: Vender\Module\view\adminhtml\web\js\form\components\fieldset.js

define([], function () {
    'use strict';
    return function (Fieldset) {
        return Fieldset.extend({
            defaults: {
                initializeFieldsetDataByDefault: true
            }
        });
    };
});

Note: There is another bug with url_key getting saved as "NULL" for storeviews, but i think its mostly unrelated.
See: #13581

@dwaynebartels
Copy link

dwaynebartels commented Aug 9, 2018

Please update or better yet solve the issue.
Since this is a problem of the core application it surprises me that it's still on the backlog.

We use the API to update products and have the same issues.

@riyuk
Copy link

riyuk commented Mar 21, 2019

Reported 2017, Confirmed 2018, Solved.... maybe 2019? Critical Bugs never get fixed fast

@dajve
Copy link

dajve commented Aug 29, 2019

While it doesn't help with actively saving a complete product against a store view, the Magento\Catalog\Model\ResourceModel\Product\Action::updateAttributes($entityIds, $attrData, $storeId) method will (in 2.3.x, at least - not sure of earlier versions) allow saving of attributes at a store level programmatically.
Eg

/** @var \Magento\Catalog\Model\ResourceModel\Product\Action $productAction */
/** @var \Magento\Catalog\Model\Product $product */
$storeId = 10;
$attributeData = [
    'sku' => $sku,
    'price' => $price,
];
$productAction->updateAttributes($product->getId(), $attributeData, $storeId);

@engcom-Alfa engcom-Alfa self-assigned this Dec 27, 2019
@m2-assistant
Copy link

m2-assistant bot commented Dec 27, 2019

Hi @engcom-Alfa. Thank you for working on this issue.
Looks like this issue is already verified and confirmed. But if you want to validate it one more time, please, go though the following instruction:

  • 1. Add/Edit Component: XXXXX label(s) to the ticket, indicating the components it may be related to.

  • 2. Verify that the issue is reproducible on 2.4-develop branch

    Details- Add the comment @magento give me 2.4-develop instance to deploy test instance on Magento infrastructure.
    - If the issue is reproducible on 2.4-develop branch, please, add the label Reproduced on 2.4.x.
    - If the issue is not reproducible, add your comment that issue is not reproducible and close the issue and stop verification process here!

  • 3. If the issue is not relevant or is not reproducible any more, feel free to close it.


@engcom-Alfa engcom-Alfa removed the Issue: Confirmed Gate 3 Passed. Manual verification of the issue completed. Issue is confirmed label Dec 27, 2019
@engcom-Alfa
Copy link
Contributor

Duplicate of #8897

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Issue: Clear Description Gate 2 Passed. Manual verification of the issue description passed Issue: Format is valid Gate 1 Passed. Automatic verification of issue format passed Issue: Ready for Work Gate 4. Acknowledged. Issue is added to backlog and ready for development Reproduced on 2.1.x The issue has been reproduced on latest 2.1 release Reproduced on 2.2.x The issue has been reproduced on latest 2.2 release Reproduced on 2.3.x The issue has been reproduced on latest 2.3 release
Projects
None yet
Development

No branches or pull requests

9 participants