How can the Coupon Percentage/Value Display in invoice_items.php?


  • Default avatar
    marco93    
     11 days ago
    0

    Hi,

    i want to display the Coupon Value (in my case it is 10%) in the Virtuemart 2 confirmation email /tmpl/invoice_items.php. 

    How can I handle it?


    2. Is there a way to display the Coupon without Tax in the confirmation mail? Actually it displayed only including Tax.


    Regards

  • Your avatar
    seyi    
     11 days ago
    0

    Hello,

    Here is an example of a function that returns the coupon details given the order_id:

    <?php
        
    public function get_coupon_data($order_id) {
            $awocoupon_details JFactory::getDBO()
                ->setQuery'SELECT details FROM #__awocoupon_history WHERE order_id=' . (int) $order_id )
                ->loadResult()
            ;
            if (empty($awocoupon_details)) return;

            $awocoupon_details json_decode($awocoupon_details);
            return $awocoupon_details;
        }
    ?>

    print_r the return to see all the data.  It should contain everything you need.
  • Default avatar
    marco93    
     11 days ago
    0

    Thanks for your answer.


    But I don't understand where I have to put in the code? If I put I directly in the invoice_items.php then the invoice will no longer be displayed.

    Sorry, I am only mediocre with php.

    I try to show you the problem with a screenshot attached:

    wrong coupon price

    in the invoice the 10% coupon display 10% from the price including tax. But it should be display 10% of the price EXCLUSIVE tax. 

    By the way in the awocoupon configuration "coupon before tax" is switched on.


    Send you the invoice_item.php, may you can see the error:


    <?php
    /**** Order items view* @author Marco Schmidt*/
    // Check to ensure this file is included in Joomla!defined('_JEXEC') or die('Restricted access');
     if VmConfig::get('show_tax')) {    $colspan=7; } else {    $colspan=8; }
    ?>

    <table width="684" border="0" cellpadding="0" cellspacing="0" class="html-email">

    <tbody>

    <tr>

    <th width="50" align="center" nowrap scope="col">Abb.</th>

    <th width="179" align="left" nowrap scope="col">

    <?php
     
    echo JText::_('COM_VIRTUEMART_PRODUCT_NAME_TITLE'
    ?>
    </th>

    <th width="95" align="right" nowrap scope="col">

    <?php
     
    echo JText::_('COM_VIRTUEMART_ORDER_PRINT_LISTPRICE'
    ?>
    </th>

    <th width="95" align="right" nowrap scope="col">

    <?php
     
    echo JText::_('COM_VIRTUEMART_ORDER_PRINT_YOURPRICE'
    ?>
    </th>

    <th width="50" align="right" nowrap scope="col">

    <?php
     
    echo JText::_('COM_VIRTUEMART_ORDER_PRINT_QTY'
    ?>
    </th>

    <th width="95" align="right" nowrap scope="col">

    <?php
     
    echo JText::_('COM_VIRTUEMART_ORDER_PRINT_SUBTOTAL_DISCOUNT_AMOUNT'
    ?>
    </th>

    <th width="120" align="right" nowrap scope="col">

    <?php
     
    echo JText::_('COM_VIRTUEMART_ORDER_PRINT_TOTAL'
    ?>
    </th>

    </tr>

    <!--Z1 Produktarray Start-->

    <?php
                    
    foreach($this->orderDetails['items'] as $item) {                    $qtt $item->product_quantity ;                    $product_link JURI::root().'index.php?option=com_virtuemart&view=productdetails&virtuemart_category_id=' $item->virtuemart_category_id .                        '&virtuemart_product_id=' $item->virtuemart_product_id;
                    
    ?>

    <tr>

    <td align="center" valign="middle">

    <!--MarcoMod Produktbild einfügen -->

    <?php
                                 
    if (!empty($item->product_quantity)) {
                                     
    $ProductModelVmModel::getModel('product');                             $product $ProductModel->getProduct($item->virtuemart_product_id);                                 $db JFactory::getDBO();                                 $qs "SELECT file_url_thumb FROM #__virtuemart_medias WHERE virtuemart_media_id = (SELECT virtuemart_media_id FROM #__virtuemart_product_medias WHERE virtuemart_product_id =".$item->virtuemart_product_id.")"//print_r($qs);                                  $db->setQuery($qs);                                  $item2 = $db->loadAssocList();                                         foreach($item2 as $file_thumb){                                            //echo $file_thumb['file_url_thumb'];                                             
    ?>

       <img src="

    <?php
      echo JURI
    ::root () . $file_thumb['file_url_thumb'
    ?>
    " width="50" height="50" />

    <?php
                                                 
    }                                          }
                                            
    ?>

    <!--MarcoMod ENDE Produktbild einfügen -->

    </td>

    <td align="left" valign="middle">

    <strong><a href="

    <?php
     
    echo $product_link
    ?>
    ">
    <?php
     
    echo $item->order_item_name
    ?>
    </a></strong><br>

    <!--MarcoMod Kurzbeschreibung einfügen -->

    <?php
                                       $ProductModel
    VmModel::getModel('product');                                   $product $ProductModel->getProduct($item->virtuemart_product_id);                                echo shopFunctionsF::limitStringByWord($product->product_s_desc30'...')                             
    ?>

    <!-- oder wenn komplett dann nur: echo $product->product_s_desc; -->

    <!--MarcoMod ENDE Kurzbeschreibung einfügen -->

    </td>

    <td align="right" valign="middle">

    <span class="line-through" style="color: #999999;">

    <?php
     
    echo $this->currency->priceDisplay($item->product_item_price$this->currency); 
    ?>
    </span>

    </td>

    <td align="right" valign="middle">

    <?php
     
    echo $this->currency->priceDisplay($item->product_discountedPriceWithoutTax$this->currency); 
    ?>
    </td>

    <td align="center" valign="middle">

    <?php
     
    echo $qtt
    ?>
    </td>

    <td align="right" valign="middle">

    <?php
     
    echo  $this->currency->priceDisplay$item->product_subtotal_discount$this->currency ); 
    ?>

    </td>

    <td align="right" valign="middle">

    <?php
                                $item
    ->product_basePriceWithTax = (float) $item->product_basePriceWithTax;                            $class '';                            if(!empty($item->product_basePriceWithTax) && $item->product_basePriceWithTax != $item->product_final_price ) {              // MarcoMod Normalpreis Gesamt              // echo ''.$this->currency->priceDisplay($item->product_item_price,$this->currency,$qtt) .'
    ' ;                            }
                                echo $this->currency->priceDisplay($item->product_discountedPriceWithoutTax, $this->currency,$qtt); //No quantity or you must use product_final_price 
    ?>

    </td>

    </tr>

    <!--Z1 Produktarray Ende-->

    <tr>

    <td colspan="7"><hr></td>

    </tr>

    <?php
                        
    }                
    ?>

    <tr>

    <td colspan="6" align="right">

    <?php
     
    echo $this->orderDetails['shipmentName'
    ?>
    </td>

    <td align="right">

    <?php
     
    echo $this->currency->priceDisplay($this->orderDetails['details']['BT']->order_shipment$this->currency); 
    ?>
    </td>

    </tr>

    <tr>

    <td colspan="6" align="right">

    <?php
     
    echo JText::_('COM_VIRTUEMART_ORDER_PRINT_ZAHLART'
    ?>
    </td>

    <td align="right">

    <?php
     
    echo JText::_('COM_VIRTUEMART_ORDER_PRINT_ZAHLARTBILL'
    ?>
    </td>

    </tr>

    <tr>

    <td colspan="7" align="right">&nbsp;</td>

    </tr>

    <tr>

    <td colspan="6" align="right">

    <?php
     
    echo JText::_('COM_VIRTUEMART_ORDER_PRINT_PRODUCT_PRICES_TOTAL'); 
    ?>
    </td>

    <td align="right">

    <?php
     
    echo $this->currency->priceDisplay($this->orderDetails['details']['BT']->order_subtotal$this->currency
    ?>
    </td>

    </tr>

    <tr>

    <td colspan="6" align="right" style="font-size: 10px">

    <?php
     
    echo JText::_('COM_VIRTUEMART_ORDER_PRINT_GESAMTRABATT'); 
    ?>
    </td>

    <td align="right" style="font-size: 10px; color: #990000">(

    <?php
     
    echo $this->currency->priceDisplay($this->orderDetails['details']['BT']->order_billDiscountAmount$this->currency
    ?>
    )

    </td>

    </tr>

    <!--MarcoMod-->

    <tr>

    <td colspan="7"><hr></td>

    </tr>

            <!--MarcoMod Coupon/Gutschein-->

    <?php
                    
    if ($this->orderDetails['details']['BT']->coupon_discount  0.00) {                $coupon_code=$this->orderDetails['details']['BT']->coupon_code?' ('.$this->orderDetails['details']['BT']->coupon_code.')':'';                    
    ?>

    <tr>

    <td align="right" class="pricePad" colspan="6">

    <?php
     
    echo JText::_('COM_VIRTUEMART_COUPON_DISCOUNT').': '.$coupon_code 
    ?>
    </td>

    <td align="right" style="font-weight: bold;color: green;">

    <?php
                               
    //FOR SEYI                          echo ''.$this->currency->priceDisplay($this->orderDetails['details']['BT']->coupon_discount, $this->currency);               // echo ''.$this->currency->priceDisplay($this->orderDetails['details']['BT']->coupon_Value, $this->currency);               //echo $this->currency->priceDisplay($this->orderDetails['details']['BT']->order_subtotal * 0.1, $this->currency);                                                                          
    ?>

    </td>

    </tr>

    <?php
      

    ?>

    <!--MarcoMod-End-->

    <?php
                    
    foreach($this->orderDetails['calc_rules'] as $rule){                    if ($rule->calc_kind== 'DBTaxRulesBill') { 
    ?>

    <tr >

    <td colspan="6"  align="right" style="font-size: 10px">

    <?php
     
    echo $rule->calc_rule_name 
    ?>
    </td>

    <td align="right" style="font-size: 10px">

    <?php
     
    echo  $this->currency->priceDisplay($rule->calc_amount$this->currency);  
    ?>
    </td>

    </tr>

    <!--MarcoMod-->

    <?php
                    
    } elseif ($rule->calc_kind == 'taxRulesBill' or $rule->calc_kind == 'VatTax') { 
    ?>

            <!--MarcoMod-End-->

    <tr >

    <td colspan="6"  align="right" style="font-size: 10px">

    <?php
     
    echo $rule->calc_rule_name 
    ?>
    </td>

    <td align="right" style="font-size: 10px">

    <?php
     
    echo $this->currency->priceDisplay($this->orderDetails['details']['BT']->order_billTaxAmount$this->currency); 
    ?>

    </td>

    </tr>

    <?php
                     
    } elseif ($rule->calc_kind == 'DATaxRulesBill') { 
    ?>

    <tr >

    <td colspan="6"   align="right" style="font-size: 10px">

    <?php
     
    echo $rule->calc_rule_name 
    ?>
    </td>

    <td align="right" style="font-size: 10px">

    <?php
     
    echo $this->currency->priceDisplay($rule->calc_amount$this->currency);  
    ?>
    </td>

    </tr>

    <?php
                         
    }                }                
    ?>

    <tr>

    <td colspan="7" align="right" style="border-bottom:solid #dad8d8 1px;">&nbsp;</td>

    </tr>

    <tr>

    <td colspan="6" align="right"><strong>

    <?php
     
    echo JText::_('COM_VIRTUEMART_ORDER_PRINT_TOTAL_ZW'
    ?>
    </strong></td>

    <td align="right" bgcolor="#cccccc"><strong>

    <?php
     
    echo $this->currency->priceDisplay($this->orderDetails['details']['BT']->order_total$this->currency); 
    ?>
    </strong></td>

    </tr>

    </tbody>

    </table>


    <p style="text-align: center"><strong>

    <?php
     
    echo JText::_('COM_VIRTUEMART_ORDER_PRINT_RESUME'
    ?>
    </strong></p>


    regards
  • Your avatar
    seyi    
     10 days ago
    +1

    Hello,

    You really need a developer.  Will try one more time.  In the file, you commented out the coupon discount text:

    <?php
    //FOR SEYI                          echo ''.$this->currency->priceDisplay($this->orderDetails['details']['BT']->coupon_discount, $this->currency);               // echo ''.$this->currency->priceDisplay($this->orderDetails['details']['BT']->coupon_Value, $this->currency); .....
    ?>

    You can replace that with this, hopefully it works:
    <?php
        
    if ( ! function_exists'get_coupon_data' ) ) {
            function get_coupon_data($order_id) {
                $awocoupon_details JFactory::getDBO()
                    ->setQuery'SELECT details FROM #__awocoupon_history WHERE order_id=' . (int) $order_id )
                    ->loadResult()
                ;
                if (empty($awocoupon_details)) return;

                $awocoupon_details json_decode($awocoupon_details);
                return $awocoupon_details;
            }
        }
        $coupon_data get_coupon_data$this->orderDetails['details']['BT']->virtuemart_order_id );
        $coupon_notax $this->orderDetails['details']['BT']->coupon_value;
        if ( ! empty( $coupon_data ) ) {
            $coupon_notax $coupon_data->product_discount_notax $coupon_data->shipping_discount_notax $coupon_data->extra_discount_notax;
        }
        echo ''.$this->currency->priceDisplay$coupon_notax$this->currency );
    ?>

    Hopefully that works for you.
  • Default avatar
    marco93    
     10 days ago
    0

    Well, that is exactly the result that work!


    Thank you for your quick replay and help.