Pergunta

Estou adicionando um arquivo PDF para todos os meus vendas de e-mails no momento, mas eu só quero estes PDFs para ser adicionado caso o pedido contenha pelo menos um produto virtual.Como posso implent isso no seguinte instrução if?

    if (Mage::getStoreConfig('sales_email/' . $configPath . '/attachpdf', $storeId)) {

        //Create Pdf and attach to email - play nicely with PdfCustomiser

        $pdf = Mage::getModel('emailattachments/order_pdf_order')->getPdf(array($order));
        Mage::helper('emailattachments')->addAttachment(
            $pdf, $mailTemplate, $this->getOrderAttachmentName($order)
        );
    }
Foi útil?

Solução

    $isVirtual = false;
    foreach ($order->getAllItems() as $items) {            
        if ($items->getProductType() == 'virtual') {
            $isVirtual = true; 
            break;
        }
    }

    if (Mage::getStoreConfig('sales_email/' . $configPath . '/attachpdf', $storeId) && $isVirtual) {

        //Create Pdf and attach to email - play nicely with PdfCustomiser

        $pdf = Mage::getModel('emailattachments/order_pdf_order')->getPdf(array($order));
        Mage::helper('emailattachments')->addAttachment(
            $pdf, $mailTemplate, $this->getOrderAttachmentName($order)
        );
    }
Licenciado em: CC-BY-SA com atribuição
Não afiliado a magento.stackexchange
scroll top