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 passing null for number_format is deprecated for downloadable products #3340

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Copy link
Contributor

Choose a reason for hiding this comment

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

Is it better to fix it here:

public function getPriceValue($value)
{
return number_format($value, 2, null, '');

Copy link
Contributor

Choose a reason for hiding this comment

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

how would you do that? cause if $value is null I don't see what we should return

Copy link
Contributor

Choose a reason for hiding this comment

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

Ref https://onlinephp.io/c/5e8d8, when $value = null, it used to return '0.00'. Also, see the docblock:

   /**
     * Return formatted price with two digits after decimal point
     *
     * @param float $value
     * @return string
     */
    public function getPriceValue($value)
    {
       // suggestion:
        if (!$value) {
            return '0.00';
        }
        return number_format($value, 2, null, '');
    }

Note that when $value = '': we have

Fatal error: Uncaught TypeError: number_format(): Argument #1 ($num) must be of type float, string given in /home/user/scripts/code.php:3
Stack trace:
#0 /home/user/scripts/code.php(3): number_format('', 2, NULL, '')

Original file line number Diff line number Diff line change
Expand Up @@ -151,18 +151,19 @@ public function getLinkData()
$links = $productType->getLinks($this->getProduct());
$priceWebsiteScope = Mage::helper('downloadable')->getIsPriceWebsiteScope();
foreach ($links as $item) {
$price = $item->getPrice();
$tmpLinkItem = [
'link_id' => $item->getId(),
'title' => $this->escapeHtml($item->getTitle()),
'price' => $this->getCanReadPrice() ? $this->getPriceValue($item->getPrice()) : '',
'link_id' => $item->getId(),
'title' => $this->escapeHtml($item->getTitle()),
'price' => (isset($price) && $this->getCanReadPrice()) ? $this->getPriceValue($price) : '',
'number_of_downloads' => $item->getNumberOfDownloads(),
'is_shareable' => $item->getIsShareable(),
'link_url' => $item->getLinkUrl(),
'link_type' => $item->getLinkType(),
'sample_file' => $item->getSampleFile(),
'sample_url' => $item->getSampleUrl(),
'sample_type' => $item->getSampleType(),
'sort_order' => $item->getSortOrder(),
'link_url' => $item->getLinkUrl(),
'link_type' => $item->getLinkType(),
'sample_file' => $item->getSampleFile(),
'sample_url' => $item->getSampleUrl(),
'sample_type' => $item->getSampleType(),
'sort_order' => $item->getSortOrder(),
];

if ($item->getLinkFile()) {
Expand All @@ -181,10 +182,10 @@ public function getLinkData()
]) . '">' . Mage::helper('downloadable/file')->getFileFromPathFile($item->getLinkFile()) . '</a>';
$tmpLinkItem['file_save'] = [
[
'file' => $item->getLinkFile(),
'name' => $name,
'size' => filesize($file),
'status' => 'old'
'file' => $item->getLinkFile(),
'name' => $name,
'size' => filesize($file),
'status' => 'old',
]
];
}
Expand All @@ -197,10 +198,10 @@ public function getLinkData()
if (is_file($sampleFile)) {
$tmpLinkItem['sample_file_save'] = [
[
'file' => $item->getSampleFile(),
'name' => Mage::helper('downloadable/file')->getFileFromPathFile($item->getSampleFile()),
'size' => filesize($sampleFile),
'status' => 'old'
'file' => $item->getSampleFile(),
'name' => Mage::helper('downloadable/file')->getFileFromPathFile($item->getSampleFile()),
'size' => filesize($sampleFile),
'status' => 'old',
]
];
}
Expand Down
Loading