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

Integer attribute values being cast to decimal in some very specific cases #3704

Closed
digitalpianism opened this issue Mar 9, 2016 · 2 comments
Assignees

Comments

@digitalpianism
Copy link
Contributor

Everything you need to know is listed under this Magento Stack Exchange question: http://magento.stackexchange.com/questions/105244/magento-1-admin-product-grid-column-value-disappear-on-name-search/105421

Even though the question I asked was about Magento 1, it seems like this bug is still present in Magento 2 and I'm about to make a PR to fix it.

digitalpianism pushed a commit to digitalpianism/magento2 that referenced this issue Mar 9, 2016
@digitalpianism
Copy link
Contributor Author

Quick side note on how to quickly replicate the issue on Magento 2:

This is a quick dirty script I've created in order to show the problem on M2:

Create the following file: /dev/tests/unit/test.php:

<?php
require "../../../app/bootstrap.php";
class Test extends \PHPUnit_Framework_TestCase
{
    public function testExample()
    {
        $bootstrap = \Magento\Framework\App\Bootstrap::create(BP, $_SERVER);

        $obj = $bootstrap->getObjectManager();

        $prod = $obj->create('\Magento\Catalog\Model\ProductFactory');

        $col = $prod->create()->getCollection()->addAttributeToSelect('tax_class_id')->addAttributeToSort('name')->addAttributeToSelect('price')->setPageSize(1);

        var_dump($col->getFirstItem()->getData('tax_class_id'));

        $col = $prod->create()->getCollection()->addAttributeToSelect('tax_class_id')->addAttributeToSort('name')->setPageSize(1);

        var_dump($col->getFirstItem()->getData('tax_class_id'));

    }
}

When you run phpunit test.php from the dev/tests/unit folder, you will get the following result:

string(1) "2"
string(6) "2.0000"

As you can see, without the addAttributeToSelect('price') call, the result is what we expect, the value of the tax_class_id attribute as it is supposed to be: an integer.

However, when you add the addAttributeToSelect('price'), the result differs and we get a tax_class_id value casted as a decimal.

@piotrekkaminski
Copy link
Contributor

Closing in favor of PR #3705

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants