cancel
Showing results for 
Search instead for 
Did you mean: 

Magento 2.4.6 update - extension problem - zendframework replaced with laminas

Magento 2.4.6 update - extension problem - zendframework replaced with laminas

l just updated Magento to version 2.4.6. Everything works fine but i have problem with one extension, it is very important to me and there is no substitute for it. Problem is that zendframework is replaced with laminas.

 

There are two files that have old clases of zend. Can you guys help me with that please.

 

Conversion.php - at the end of file was "Zend_Locale_Data"

 

<?php

declare(strict_types=1);

namespace Inchoo\DualPrices\Helper;

use Magento\Framework\App\Config\ScopeConfigInterface;

class Conversion
{

    const HRK_EUR_CONVERSION_RATE = 7.53450;

    const XML_PATH_CATALOG_DUAL_PRICES_SIDE_CURRENCY = 'currency/dual_prices/side_currency';

    const XML_PATH_CATALOG_DUAL_PRICES_SEPARATOR = 'currency/dual_prices/separator';

    /**
     * @var ScopeConfigInterface
     */
    protected $scopeConfig;

    /**
     * Conversion constructor.
     * @param ScopeConfigInterface $scopeConfig
     */
    public function __construct(
        ScopeConfigInterface $scopeConfig
    ) {
        $this->scopeConfig = $scopeConfig;
    }

    /**
     * @param float $amount
     * @return string
     */
    public function formatSidePrice(float $amount): string
    {
        $sideCurrencyInfo = $this->getSideCurrencyInfo();

        return sprintf(
            '<span class="side-price">%s%s%s</span>',
            $sideCurrencyInfo['separator'] ?
                "<span class=\"side-price-separator\">{$sideCurrencyInfo['separator']}</span>" :
                ' ',
            number_format(
                round($amount * $sideCurrencyInfo['rate'], 2),
                2,
                ',',
                '.'
            ),
            $sideCurrencyInfo['symbol']
        );
    }

    /**
     * @return array
     */
    public function getSideCurrencyInfo(): array
    {
        $currency = $this->scopeConfig->getValue(self::XML_PATH_CATALOG_DUAL_PRICES_SIDE_CURRENCY);
        return [
            'rate'   => $currency == 'HRK' ? self::HRK_EUR_CONVERSION_RATE : 1/self::HRK_EUR_CONVERSION_RATE,
            'symbol' => \Zend_Locale_Data::getContent('hr_HR', 'currencysymbol', $currency),
            'separator' => trim((string)$this->scopeConfig->getValue(self::XML_PATH_CATALOG_DUAL_PRICES_SEPARATOR))
        ];
    }
}

Invoice.php - in the midle of the file there is "\Zend_Pdf_Font::fontWithPath("

<?php

declare(strict_types=1);

namespace Inchoo\DualPrices\Model\Sales\Order\Pdf;

use Magento\Sales\Model\Order\Pdf\Invoice as Original;
use Magento\Sales\Model\AbstractModel;

class Invoice extends Original
{

    /**
     * Insert totals to pdf page
     *
     * @param  \Zend_Pdf_Page $page
     * @param  AbstractModel $source
     * @return \Zend_Pdf_Page
     */
    protected function insertTotals($page, $source) //phpcs:ignore
    {
        $order = $source->getOrder();
        $totals = $this->_getTotalsList();
        $lineBlock = ['lines' => [], 'height' => 15];
        foreach ($totals as $total) {
            $total->setOrder($order)->setSource($source);

            if ($total->canDisplay()) {
                $total->setFontSize(10);
                foreach ($total->getTotalsForDisplay() as $totalData) {
                    $euroAmount = sprintf(' / %0.2f€', round((float)$total->getAmount() / 7.5345, 2));

                    $lineBlock['lines'][] = [
                        [
                            'text' => $totalData['label'],
                            'feed' => 475,
                            'align' => 'right',
                            'font_size' => $totalData['font_size'],
                            'font' => 'bold',
                        ],
                        [
                            'text' => $totalData['amount'],
                            'feed' => 565 - $this->widthForStringUsingFontSize(
                                $euroAmount,
                                \Zend_Pdf_Font::fontWithPath(
                                    $this->_rootDirectory->getAbsolutePath('lib/internal/GnuFreeFont/FreeSerif.ttf')
                                ),
                                9
                            ),
                            'align' => 'right',
                            'font_size' => $totalData['font_size'],
                            'font' => 'bold'
                        ],
                        [
                            'text' => $euroAmount,
                            'feed' => 565,
                            'align' => 'right',
                            'font_size' => 9,
                        ]
                    ];
                }
            }
        }

        $this->y -= 20;
        $page = $this->drawLineBlocks($page, [$lineBlock]);
        return $page;
    }
}
1 REPLY 1

Re: Magento 2.4.6 update - extension problem - zendframework replaced with laminas

Since Zend Framework has been replaced with Laminas in Magento 2.4.6, you need to update the code of your extension to use the Laminas classes instead of Zend classes.

For the first file Conversion.php, replace the line:

'Zend_Locale_Data::getContent('hr_HR', 'currencysymbol', $currency),

with:

\Laminas\I18n\Translator\Resources::factory('hr_HR')['Currency'][$currency],

For the second file Invoice.php, replace the line:

\Zend_Pdf_Font::fontWithPath(
$this->_rootDirectory->getAbsolutePath('lib/internal/GnuFreeFont/FreeSerif.ttf')
),

with: 

$this->_pdf->getFont(
    $this->_setFontRegular(),
    \LaminasPdf\Resource\Font\AbstractFont::EMBED_DONT_CACHE,
    $this->_rootDirectory->getAbsolutePath('lib/internal/GnuFreeFont/FreeSerif.ttf')
),

Note that you need to add the following use statements at the beginning of each file:

 

use Laminas\I18n\Translator\Resources;
use LaminasPdf\Resource\Font\AbstractFont;

After making these changes, clear the cache and test your extension to make sure it works as expected.

Hit the Kudos button and Accept as Solution if it works.