3

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
  • Notified Inchoo about this as they are amazing Croatian company and have no doubt they will update extension in no time. Tried @ItsJhonny solution for now - and it works.
    – nordashi
    Mar 25, 2023 at 2:37

1 Answer 1

0

Not recommended as all new applications use laminas, it makes more sense for you to update your modules, if they are 2.4.6 compatible you shouldn't have any problems

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.