Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 5 You must be signed in to fork a gist
  • Save matheusgontijo/96e2b44fb19ec4e41c291f4933d204e5 to your computer and use it in GitHub Desktop.
Save matheusgontijo/96e2b44fb19ec4e41c291f4933d204e5 to your computer and use it in GitHub Desktop.
Magento 2 Debugging Tricks - setData, DataObject.php & xDebug by Matheus Gontijo
Magento 2 Debugging Tricks - setData, DataObject.php & xDebug by Matheus Gontijo
Video: https://www.youtube.com/watch?v=eo8N7e9eEPI
-----------------------------------------------
What is "stripos"?
<?php
// https://www.php.net/stripos
// Find the position of the first occurrence of a case-insensitive substring in a string
// PHP could have a function called "contains"
stripos('hello world', 'o') // position 4
stripos('hello world', 'wor') // position 6
stripos('hello world', 'hel') // position 0
stripos('hello world', 'aaa') // position "false"
// "Contains" concept
stripos('hello world 123 magento', 'world') !== false // position 6
?>
-----------------------------------------------
1) Try to track directly into the concrete object
vendor/magento/module-catalog/Model/Category.php
->setName or ->setDescription
-----------------------------------------------
2) Try to track on the parent classes
->setData (parent classes)
- vendor/magento/framework/Model/AbstractModel.php
- vendor/magento/framework/DataObject.php
<?php
// first try : vendor/magento/framework/Model/AbstractModel.php
// second try: vendor/magento/framework/DataObject.php
if (is_scalar($key)) {
$breakpoint = null; // is_scalar($value) && stripos($value, 'montana') !== false
} else if (is_array($key)) {
foreach ($key as $k => $v) {
$breakpoint = null; // is_scalar($v) && stripos($v, 'montana') !== false
}
}
?>
-----------------------------------------------
Real World examples:
Example 01 | Who is setting filter "LumaTech"?
Example 02 | Who is setting product price "56.99"?
Example 03 | Who is setting product configurable option as "Yellow"?
Example 04 | Who is setting the "reviews"?
-----------------------------------------------
<?php
// first form: array
$object->setData([
'entity_id' => 9999,
'name' => 'xdebug is awesome',
'title' => 'you should use it!',
]);
// second form: key + value
$object->setData('entity_id', 9999);
$object->setData('name', 'xdebug is awesome');
$object->setData('title', 'you should use it!');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment