Question

Errors during compilation: Amy\InvoicePdfPcb\Model\Order\Pdf\Invoice Incompatible argument type: Required type: \Magento\Store\Model\StoreManagerInterface. Actual type: array; File: /var/www/html/magento2/app/code/Amy/InvoicePdfPcb/Model/Order/Pdf/Invoice.php

<?php
/**
 * Copyright © Magento, Inc. All rights reserved.
 * See COPYING.txt for license details.
 */
namespace Amy\InvoicePdfPcb\Model\Order\Pdf;

use Magento\Sales\Model\Order\Pdf\Config;

/**
 * Sales Order Invoice PDF model
 * @SuppressWarnings(PHPMD.CouplingBetweenObjects)
 */
class Invoice extends \Magento\Sales\Model\Order\Pdf\Invoice
{
    /**
     * @var \Magento\Store\Model\StoreManagerInterface
     */
    protected $_storeManager;
/**
 * @var \Magento\Framework\Locale\ResolverInterface
 */
protected $_localeResolver;

/**
 * @param \Magento\Payment\Helper\Data $paymentData
 * @param \Magento\Framework\Stdlib\StringUtils $string
 * @param \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig
 * @param \Magento\Framework\Filesystem $filesystem
 * @param Config $pdfConfig
 * @param \Magento\Sales\Model\Order\Pdf\Total\Factory $pdfTotalFactory
 * @param \Magento\Sales\Model\Order\Pdf\ItemsFactory $pdfItemsFactory
 * @param \Magento\Framework\Stdlib\DateTime\TimezoneInterface $localeDate
 * @param \Magento\Framework\Translate\Inline\StateInterface $inlineTranslation
 * @param \Magento\Sales\Model\Order\Address\Renderer $addressRenderer
 * @param \Magento\Store\Model\StoreManagerInterface $storeManager
 * @param \Magento\Framework\Locale\ResolverInterface $localeResolver
 * @param array $data
 *
 * @SuppressWarnings(PHPMD.ExcessiveParameterList)
 */
public function __construct(
    \Magento\Payment\Helper\Data $paymentData,
    \Magento\Framework\Stdlib\StringUtils $string,
    \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig,
    \Magento\Framework\Filesystem $filesystem,
    Config $pdfConfig,
    \Magento\Sales\Model\Order\Pdf\Total\Factory $pdfTotalFactory,
    \Magento\Sales\Model\Order\Pdf\ItemsFactory $pdfItemsFactory,
    \Magento\Framework\Stdlib\DateTime\TimezoneInterface $localeDate,
    \Magento\Framework\Translate\Inline\StateInterface $inlineTranslation,
    \Magento\Sales\Model\Order\Address\Renderer $addressRenderer,
    \Magento\Store\Model\StoreManagerInterface $storeManager,
    \Magento\Framework\Locale\ResolverInterface $localeResolver,
    array $data = []
) {
    $this->_storeManager = $storeManager;
    $this->_localeResolver = $localeResolver;
    parent::__construct(
        $paymentData,
        $string,
        $scopeConfig,
        $filesystem,
        $pdfConfig,
        $pdfTotalFactory,
        $pdfItemsFactory,
        $localeDate,
        $inlineTranslation,
        $addressRenderer,
        $data
    );
}

/**
 * Draw header for item table
 *
 * @param \Zend_Pdf_Page $page
 * @return void
 */
protected function _drawHeader(\Zend_Pdf_Page $page)
{
    /* Add table head */
    $this->_setFontRegular($page, 10);
    $page->setFillColor(new \Zend_Pdf_Color_RGB(0.93, 0.92, 0.92));
    $page->setLineColor(new \Zend_Pdf_Color_GrayScale(0.5));
    $page->setLineWidth(0.5);
    $page->drawRectangle(25, $this->y, 570, $this->y - 15);
    $this->y -= 10;
    $page->setFillColor(new \Zend_Pdf_Color_RGB(0, 0, 0));

    //columns headers
    $lines[0][] = ['text' => __('Products'), 'feed' => 35];

    $lines[0][] = ['text' => __('PCB Master'), 'feed' => 190, 'align' => 'right'];

    $lines[0][] = ['text' => __('SKU'), 'feed' => 290, 'align' => 'right'];

    $lines[0][] = ['text' => __('Qty'), 'feed' => 435, 'align' => 'right'];

    $lines[0][] = ['text' => __('Price'), 'feed' => 360, 'align' => 'right'];

    $lines[0][] = ['text' => __('Tax'), 'feed' => 495, 'align' => 'right'];

    $lines[0][] = ['text' => __('Subtotal'), 'feed' => 565, 'align' => 'right'];

    $lineBlock = ['lines' => $lines, 'height' => 5];

    $this->drawLineBlocks($page, [$lineBlock], ['table_header' => true]);
    $page->setFillColor(new \Zend_Pdf_Color_GrayScale(0));
    $this->y -= 20;
}

/**
 * Return PDF document
 *
 * @param array|Collection $invoices
 * @return \Zend_Pdf
 */
public function getPdf($invoices = [])
{
    $this->_beforeGetPdf();
    $this->_initRenderer('invoice');

    $pdf = new \Zend_Pdf();
    $this->_setPdf($pdf);
    $style = new \Zend_Pdf_Style();
    $this->_setFontBold($style, 10);

    foreach ($invoices as $invoice) {
        if ($invoice->getStoreId()) {
            $this->_localeResolver->emulate($invoice->getStoreId());
            $this->_storeManager->setCurrentStore($invoice->getStoreId());
        }
        $page = $this->newPage();
        $order = $invoice->getOrder();
        /* Add image */
        $this->insertLogo($page, $invoice->getStore());
        /* Add address */
        $this->insertAddress($page, $invoice->getStore());
        /* Add head */
        $this->insertOrder(
            $page,
            $order,
            $this->_scopeConfig->isSetFlag(
                self::XML_PATH_SALES_PDF_INVOICE_PUT_ORDER_ID,
                \Magento\Store\Model\ScopeInterface::SCOPE_STORE,
                $order->getStoreId()
            )
        );
        /* Add document text and number */
        $this->insertDocumentNumber($page, __('Invoice # ') . $invoice->getIncrementId());
        /* Add table */
        $this->_drawHeader($page);
        /* Add body */
        foreach ($invoice->getAllItems() as $item) {
            if ($item->getOrderItem()->getParentItem()) {
                continue;
            }
            /* Draw item */
            $this->_drawItem($item, $page, $order);
            $page = end($pdf->pages);
        }
        /* Add totals */
        $this->insertTotals($page, $invoice);
        if ($invoice->getStoreId()) {
            $this->_localeResolver->revert();
        }
    }
    $this->_afterGetPdf();
    return $pdf;
}

/**
 * Create new page and assign to PDF object
 *
 * @param  array $settings
 * @return \Zend_Pdf_Page
 */
public function newPage(array $settings = [])
{
    /* Add new table head */
    $page = $this->_getPdf()->newPage(\Zend_Pdf_Page::SIZE_A4);
    $this->_getPdf()->pages[] = $page;
    $this->y = 800;
    if (!empty($settings['table_header'])) {
        $this->_drawHeader($page);
    }
    return $page;
}

}

Incompatible argument type: Required type: \Magento\Framework\Stdlib\StringUtils. Actual type: \Magento\Framework\Model\ResourceModel\AbstractResource; File: /var/www/html/magento2/app/code/Amy/InvoicePdfPcb/Model/Order/Pdf/items/Invoice/DefaultInvoice.php

<?php
/**
 * Copyright © Magento, Inc. All rights reserved.
 * See COPYING.txt for license details.
 */
namespace Amy\InvoicePdfPcb\Model\Order\Pdf\Items\Invoice;

/**
 * Sales Order Invoice Pdf default items renderer
 */
class DefaultInvoice extends \Magento\Sales\Model\Order\Pdf\Items\Invoice\DefaultInvoice
{
    /**
     * Core string
     *
     * @var \Magento\Framework\Stdlib\StringUtils
     */
    protected $string;

    /**
     * @param \Magento\Framework\Model\Context $context
     * @param \Magento\Framework\Registry $registry
     * @param \Magento\Tax\Helper\Data $taxData
     * @param \Magento\Framework\Filesystem $filesystem
     * @param \Magento\Framework\Filter\FilterManager $filterManager
     * @param \Magento\Framework\Stdlib\StringUtils $string
     * @param \Magento\Framework\Model\ResourceModel\AbstractResource $resource
     * @param \Magento\Framework\Data\Collection\AbstractDb $resourceCollection
     * @param array $data
     */
    public function __construct(
        \Magento\Framework\Model\Context $context,
        \Magento\Framework\Registry $registry,
        \Magento\Tax\Helper\Data $taxData,
        \Magento\Framework\Filesystem $filesystem,
        \Magento\Framework\Filter\FilterManager $filterManager,
        \Magento\Framework\Stdlib\StringUtils $string,
        \Magento\Framework\Model\ResourceModel\AbstractResource $resource = null,
        \Magento\Framework\Data\Collection\AbstractDb $resourceCollection = null,
        array $data = []
    ) {
        $this->string = $string;
        parent::__construct(
            $context,
            $registry,
            $taxData,
            $filesystem,
            $filterManager,
            $resource,
            $resourceCollection,
            $data
        );
    }

    /**
     * Draw item line
     *
     * @return void
     */
    public function draw()
    {
        $order = $this->getOrder();
        $item = $this->getItem();
        $pdf = $this->getPdf();
        $page = $this->getPage();
        $lines = [];
        $id = $item->getProductid();
        $objectManager = \Magento\Framework\App\ObjectManager::getInstance();
        $product = $objectManager->get('Magento\Catalog\Model\Product')->load($id);
        $PcbMaster = $product->getData('pcb_master');

        // draw Product name
        $lines[0] = [['text' => $this->string->split($item->getName(), 35, true, true), 'feed' => 35]];


        $lines[0][] = [
        'text' => $PcbMaster,
        'feed' => 190,
        'align' => 'right',
    ];

        // draw SKU
        $lines[0][] = [
            'text' => $this->string->split($this->getSku($item), 17),
            'feed' => 290,
            'align' => 'right',
        ];

        // draw QTY
        $lines[0][] = ['text' => $item->getQty() * 1, 'feed' => 435, 'align' => 'right'];

        // draw item Prices
        $i = 0;
        $prices = $this->getItemPricesForDisplay();
        $feedPrice = 395;
        $feedSubtotal = $feedPrice + 170;
        foreach ($prices as $priceData) {
            if (isset($priceData['label'])) {
                // draw Price label
                $lines[$i][] = ['text' => $priceData['label'], 'feed' => $feedPrice, 'align' => 'right'];
                // draw Subtotal label
                $lines[$i][] = ['text' => $priceData['label'], 'feed' => $feedSubtotal, 'align' => 'right'];
                $i++;
            }
            // draw Price
            $lines[$i][] = [
                'text' => $priceData['price'],
                'feed' => $feedPrice,
                'font' => 'bold',
                'align' => 'right',
            ];
            // draw Subtotal
            $lines[$i][] = [
                'text' => $priceData['subtotal'],
                'feed' => $feedSubtotal,
                'font' => 'bold',
                'align' => 'right',
            ];
            $i++;
        }

        // draw Tax
        $lines[0][] = [
            'text' => $order->formatPriceTxt($item->getTaxAmount()),
            'feed' => 495,
            'font' => 'bold',
            'align' => 'right',
        ];

        // custom options
        $options = $this->getItemOptions();
        if ($options) {
            foreach ($options as $option) {
                // draw options label
                $lines[][] = [
                    'text' => $this->string->split($this->filterManager->stripTags($option['label']), 40, true, true),
                    'font' => 'italic',
                    'feed' => 35,
                ];

                if ($option['value']) {
                    if (isset($option['print_value'])) {
                        $printValue = $option['print_value'];
                    } else {
                        $printValue = $this->filterManager->stripTags($option['value']);
                    }
                    $values = explode(', ', $printValue);
                    foreach ($values as $value) {
                        $lines[][] = ['text' => $this->string->split($value, 30, true, true), 'feed' => 40];
                    }
                }
            }
        }

        $lineBlock = ['lines' => $lines, 'height' => 20];

        $page = $pdf->drawLineBlocks($page, [$lineBlock], ['table_header' => true]);
        $this->setPage($page);
    }
}
Was it helpful?

Solution

Try the below code for your class

Amy\InvoicePdfPcb\Model\Order\Pdf\Invoice

parent::__construct(
    $paymentData,
    $string,
    $scopeConfig,
    $filesystem,
    $pdfConfig,
    $pdfTotalFactory,
    $pdfItemsFactory,
    $localeDate,
    $inlineTranslation,
    $addressRenderer,
    $storeManager,
    $localeResolver,
    $data
);

And Try the below code for your class

Amy\InvoicePdfPcb\Model\Order\Pdf\Items\Invoice\DefaultInvoice

parent::__construct(
    $context,
    $registry,
    $taxData,
    $filesystem,
    $filterManager,
    $string,
    $resource,
    $resourceCollection,
    $data
);

And now run setup upgrade, di compile and other required commands.

Licensed under: CC-BY-SA with attribution
Not affiliated with magento.stackexchange
scroll top