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

Fixed undefined array key "values" in Mage_Catalog_Model_Product_Attribute_Backend_Media #4125

Merged
merged 9 commits into from
Sep 16, 2024

Conversation

S0FTWEX
Copy link
Contributor

@S0FTWEX S0FTWEX commented Jul 28, 2024

There were still some warnings after product import without providing images additional data.

fixed undefined array key "values" in /app/code/core/Mage/Catalog/Model/Product/Attribute/Backend/Media.php on line 113
and
fixed foreach() argument must be of type array|object, null given in /app/code/core/Mage/Catalog/Model/Product/Attribute/Backend/Media.php on line 167.

S0FTWEX and others added 5 commits October 15, 2020 19:51
Removed unnecessary 'includes' folder, because Compiler was removed lately
fix undefined array key "values"  in /app/code/core/Mage/Catalog/Model/Product/Attribute/Backend/Media.php on line 113
and
fixed  foreach() argument must be of type array|object, null given  in /app/code/core/Mage/Catalog/Model/Product/Attribute/Backend/Media.php on line 167
@github-actions github-actions bot added the Component: Catalog Relates to Mage_Catalog label Jul 28, 2024
@alexh-swdev
Copy link
Contributor

alexh-swdev commented Jul 28, 2024

I have a simmilar PR pending, array_key_exists and if required is_null is prefererred over isset...

#4121 (comment)

@S0FTWEX
Copy link
Contributor Author

S0FTWEX commented Jul 28, 2024

I just followed the rest of the code (see few lines of code above where isset is used as well)

@sreichel
Copy link
Contributor

sreichel commented Jul 28, 2024

@sreichel
Copy link
Contributor

May I ask where this error comes from?

Seems to be 3rd-party code. (?)

@S0FTWEX
Copy link
Contributor Author

S0FTWEX commented Jul 29, 2024

May I ask where this error comes from?

Seems to be 3rd-party code. (?)

Yes, errors may come from 3rd-party code, the old module CommerceExtensions_Productimportexport for importing products via Dataflow Profiles.

@sreichel
Copy link
Contributor

sreichel commented Jul 29, 2024

Can you post a stacktrace and maybe share it?

However. Adding checks for existing array-key does not harm.

@S0FTWEX
Copy link
Contributor Author

S0FTWEX commented Jul 29, 2024

Can you post a stacktrace and maybe share it?

However. Adding checks for existing array-key to harm.

Errors are in system.log. There are only these warnings there (repeating many times), but without stacktrace :-(

@empiricompany
Copy link
Contributor

Could you please fill out the template we use for PRs?
Specifically, I don't know the steps to reproduce the issues.

@github-actions github-actions bot added the Component: Adminhtml Relates to Mage_Adminhtml label Aug 1, 2024
@alexh-swdev
Copy link
Contributor

Can you post a stacktrace and maybe share it?
However. Adding checks for existing array-key to harm.

Errors are in system.log. There are only these warnings there (repeating many times), but without stacktrace :-(

You could temporarily add a "debug trap" like so:

if (!array_key_exists('value', $option)) {
    $lbl = array_key_exists('label', $option) ? $option['label'] : "-unknown-";
    Mage::log(sprintf("Value does not exist for '%s': %s", $lbl, print_r(debug_backtrace(2), true)), Zend_Log::ALERT);
}

In my above mentioned PR, the issue is coming from an old unused ama pay plugin. But nevertheless, imho the OM core should be able to handle such things in a proper way

@github-actions github-actions bot removed the Component: Adminhtml Relates to Mage_Adminhtml label Aug 4, 2024
@S0FTWEX
Copy link
Contributor Author

S0FTWEX commented Aug 4, 2024

Here is the result of the "debug trap". Softwex_Core_Model_Convert_Adapter_Productimport is my custom profile for importing products via Dataflow Advanced Profiles.

Array
(
    [0] => Array
        (
            [file] => /app/code/core/Mage/Eav/Model/Entity/Abstract.php
            [line] => 640
            [function] => beforeSave
            [class] => Mage_Catalog_Model_Product_Attribute_Backend_Media
            [type] => ->
        )

    [1] => Array
        (
            [file] => /app/code/core/Mage/Eav/Model/Entity/Abstract.php
            [line] => 1628
            [function] => walkAttributes
            [class] => Mage_Eav_Model_Entity_Abstract
            [type] => ->
        )

    [2] => Array
        (
            [file] => /app/code/core/Mage/Catalog/Model/Resource/Product.php
            [line] => 167
            [function] => _beforeSave
            [class] => Mage_Eav_Model_Entity_Abstract
            [type] => ->
        )

    [3] => Array
        (
            [file] => /app/code/core/Mage/Eav/Model/Entity/Abstract.php
            [line] => 1090
            [function] => _beforeSave
            [class] => Mage_Catalog_Model_Resource_Product
            [type] => ->
        )

    [4] => Array
        (
            [file] => /app/code/core/Mage/Core/Model/Abstract.php
            [line] => 379
            [function] => save
            [class] => Mage_Eav_Model_Entity_Abstract
            [type] => ->
        )

    [5] => Array
        (
            [file] => /app/code/local/Softwex/Core/Model/Convert/Adapter/Productimport.php
            [line] => 1121
            [function] => save
            [class] => Mage_Core_Model_Abstract
            [type] => ->
        )

    [6] => Array
        (
            [file] => /app/code/core/Mage/Adminhtml/controllers/System/Convert/ProfileController.php
            [line] => 252
            [function] => saveRow
            [class] => Softwex_Core_Model_Convert_Adapter_Productimport
            [type] => ->
        )

    [7] => Array
        (
            [file] => /app/code/core/Mage/Core/Controller/Varien/Action.php
            [line] => 424
            [function] => batchRunAction
            [class] => Mage_Adminhtml_System_Convert_ProfileController
            [type] => ->
        )

    [8] => Array
        (
            [file] => /app/code/local/Mage/Core/Controller/Varien/Router/Standard.php
            [line] => 262
            [function] => dispatch
            [class] => Mage_Core_Controller_Varien_Action
            [type] => ->
        )

    [9] => Array
        (
            [file] => /app/code/core/Mage/Core/Controller/Varien/Front.php
            [line] => 181
            [function] => match
            [class] => Mage_Core_Controller_Varien_Router_Standard
            [type] => ->
        )

    [10] => Array
        (
            [file] => /app/code/core/Mage/Core/Model/App.php
            [line] => 358
            [function] => dispatch
            [class] => Mage_Core_Controller_Varien_Front
            [type] => ->
        )

    [11] => Array
        (
            [file] => /app/Mage.php
            [line] => 737
            [function] => run
            [class] => Mage_Core_Model_App
            [type] => ->
        )

    [12] => Array
        (
            [file] => /index.php
            [line] => 114
            [function] => run
            [class] => Mage
            [type] => ::
        )
)

IMHO, I agree with @alexh-swdev, OpenMage core should be able to handle such things in a proper way...

@sreichel
Copy link
Contributor

sreichel commented Aug 4, 2024

OpenMage core should be able to handle such things in a proper way

Imho checks for existing keys should be covered by OM.

Copy link
Contributor

@kiatng kiatng left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@sreichel
Copy link
Contributor

I have a simmilar PR pending, array_key_exists and if required is_null is prefererred over isset...

#4121 (comment)

I think it is bit different there, b/c there are additional checks to make sure the array-value is not null.

$value['values'] = null;

if (!is_array($value['values']) && strlen($value['values']) > 0) {
}

In this case we would pass null to strlen, that also deprecated.

Copy link
Contributor

@sreichel sreichel left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tested.

@sreichel sreichel merged commit 22c15d7 into OpenMage:main Sep 16, 2024
17 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Component: Catalog Relates to Mage_Catalog
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants