इनवॉइस ईमेल टेम्पलेट में उत्पाद छवि


11

मैं चालान ईमेल टेम्प्लेट के लिए उत्पाद छवियां प्राप्त करने का प्रयास कर रहा हूं। मैंने कोड के नीचे इस्तेमाल किया। लेकिन मुझे ईमेल टेम्पलेट में केवल Magento प्लेसहोल्डर छवि मिल रही है।

<td>
    <?php 
    $objectManager = \Magento\Framework\App\ObjectManager::getInstance();
    $product_id = $_item->getOrderItem()->getProduct();
    $product = $objectManager->get('Magento\Catalog\Model\Product')->load($product_id);

    $_imagehelper = $objectManager->get('Magento\Catalog\Helper\Image');
    $image_url = $_imagehelper->init($product, 'cart_page_product_thumbnail')->getUrl();

    ?>
      <img src="<?php echo $image_url; ?>" alt="<?php echo $product->getName(); ?>" />
</td>

आप ईमेल टेम्पलेट में PHP का उपयोग नहीं कर सकते
फिलिप सैंडर

मैंने सीधे अपने ईमेल टेम्प्लेट में उपयोग नहीं किया, मैंने अपनी फ़ाइल "Magento_Sales / टेम्पलेट्स / ईमेल / आइटम / शिपमेंट / default.phtml" में इस कोड को जोड़ा
प्रिया

क्या आपका मतलब ऑर्डर ईमेल है?
डेव गॉर्डन

नीचे दिए गए उत्तर का प्रयास करें और अपनी पूरी phtml
Prathap

जवाबों:


3

मुझे इसका समाधान मिला लेकिन यह पैरेंट थंबनेल इमेज मिल रही है, मुझे यह पसंद है कि अगर उत्पाद को स्वैच विकल्प में चुना गया है, तो उस स्वैच विकल्प को प्रदर्शित करना होगा।

उदाहरण: यदि मैं लाल रंग का चयन करता हूं, तो लाल रंग की स्वैच छवि को प्रदर्शित करने की आवश्यकता है।


$productId = $_item->getProductId();
$objectManagerHere = \Magento\Framework\App\ObjectManager::getInstance();
$product = $objectManagerHere->get('Magento\Catalog\Model\Product')->load($productId);

$_objectManager = \Magento\Framework\App\ObjectManager::getInstance();
$imageHelper  = $_objectManager->get('\Magento\Catalog\Helper\Image');
$image_url = $imageHelper->init($product, 'product_thumbnail_image')->setImageFile($product->getFile())->resize(80, 80)->getUrl();

<img src="<?php echo $image_url; ?>" alt="<?php echo $product->getName(); ?>" />

3

मैं ओवरराइड कर चुका हूं DefaultInvoice

class DefaultInvoice extends \Magento\Sales\Model\Order\Pdf\Items\Invoice\DefaultInvoice
{
    public function draw()
    {
        $order = $this->getOrder();
        $item = $this->getItem();
        $pdf = $this->getPdf();
        $page = $this->getPage();
        $lines = [];


        // draw Product image
        $productImage = $this->getProductImage($item, $page);

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

        $lines[0][] = array(
            'text'  => $productImage,
            'is_image'  => 1,
            'feed'  => 200
        );

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

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

        // draw item Prices
        $i = 0;
        $prices = $this->getItemPricesForDisplay();
        $feedPrice = 425;
        $feedSubtotal = $feedPrice + 140;
        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' => 515,
            '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],1);

        $this->setPage($page);
    }


    /*
     * Return Value of custom attribute
     * */
    private function getProductImage($item,  &$page)
    {
        $objectManager = \Magento\Framework\App\ObjectManager::getInstance();
        $productId = $item->getOrderItem()->getProductId();
        $image = $objectManager->get('Magento\Catalog\Model\Product')->load($productId);

        if (!is_null($image)) {
            try{

                $imagePath = '/catalog/product/'.$image->getSmallImage();

                $filesystem = $objectManager->get('Magento\Framework\Filesystem');
                $media_dir = $filesystem->getDirectoryRead(\Magento\Framework\App\Filesystem\DirectoryList::MEDIA);

                if ($media_dir->isFile($imagePath)) {
                    return $media_dir->getAbsolutePath($imagePath);
                }
                else
                    return null;
            }
            catch (Exception $e) {
                return false;
            }
        }
    }
}

जो मुझे इस तरह पीडीएफ लौटाता है। (इमेज रोटेशन पर काम करते हुए :))

यहाँ छवि विवरण दर्ज करें

UPDATED

वेरिएंट आधारित उत्पाद के लिए - कॉन्फ़िगर उत्पाद की विशेषता चयन पर आधारित

class DefaultInvoice extends \Magento\Sales\Model\Order\Pdf\Items\Invoice\DefaultInvoice
{
    public function draw()
    {
        $order = $this->getOrder();
        $item = $this->getItem();
        $pdf = $this->getPdf();
        $page = $this->getPage();
        $lines = [];


        // draw Product image
        $productImage = $this->getProductImage($item, $page);

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

        $lines[0][] = array(
            'text'  => $productImage,
            'is_image'  => 1,
            'feed'  => 200
        );

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

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

        // draw item Prices
        $i = 0;
        $prices = $this->getItemPricesForDisplay();
        $feedPrice = 425;
        $feedSubtotal = $feedPrice + 140;
        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' => 515,
            '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],1);

        $this->setPage($page);
    }


    /*
     * Return Value of custom attribute
     * */
    private function getProductImage($item,  &$page)
    {
        $objectManager = \Magento\Framework\App\ObjectManager::getInstance();
        $productId = $item->getOrderItem()->getProductId();
        $data = $objectManager->get('Magento\Catalog\Model\ProductRepository')->get($item->getSku());
        $image = $data->getImage();

        if (!is_null($image)) {
            try{

                $imagePath = '/catalog/product/'.$image;

                $filesystem = $objectManager->get('Magento\Framework\Filesystem');
                $media_dir = $filesystem->getDirectoryRead(\Magento\Framework\App\Filesystem\DirectoryList::MEDIA);

                if ($media_dir->isFile($imagePath)) {
                    return $media_dir->getAbsolutePath($imagePath);
                }
                else
                    return null;
            }
            catch (Exception $e) {
                return false;
            }
        }
    }
}

यहाँ कॉन्फ़िगर उत्पाद के वैरिएंट चयन के आधार पर इनवॉइस में सरल उत्पाद की छवि है।

यहाँ छवि विवरण दर्ज करें

अधिक सन्दर्भ

संदर्भ 1 , संदर्भ 2 , संदर्भ 3


0

आप अपने कोड में निम्नलिखित लाइन को बदल सकते हैं

$product = $objectManagerHere->get('Magento\Catalog\Model\Product')->load($productId);

निम्नलिखित पंक्ति के साथ

$product = $objectManagerHere->get('Magento\Catalog\Model\ProductRepository')->get($_item->getSku());

इसके साथ, आप विन्यास योग्य उत्पाद का उचित सरल उत्पाद प्राप्त कर सकते हैं।


0

मुझे लगता है कि आपको अपने उत्पाद की छवि कोड प्राप्त करने के cart_page_product_thumbnailबजाय कोशिश करनी चाहिए product_thumbnail_image

आपका कोड इस तरह होना चाहिए।

$image_url = $imageHelper->init($product, 'cart_page_product_thumbnail')->setImageFile($product->getFile())->resize(80, 80)->getUrl();

मैंने ईमेल टेम्पलेट में उत्पाद छवि प्रदर्शित करने के लिए उपरोक्त कोड का उपयोग किया है और यह विन्यास योग्य उत्पादों के साथ ठीक काम कर रहा है। और मुझे लगता है कि यह चालान ईमेल टेम्पलेट के लिए भी काम करता है।

मैंने भी देखा है कि कई उपयोगकर्ता cart_page_product_thumbnailसंदर्भ लिंक के नीचे कृपया जाँच करें।

मुझे उम्मीद है यह मदद करेगा!

हमारी साइट का प्रयोग करके, आप स्वीकार करते हैं कि आपने हमारी Cookie Policy और निजता नीति को पढ़ और समझा लिया है।
Licensed under cc by-sa 3.0 with attribution required.