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


  • Default avatar
    marco93    
     5 years 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    
     5 years 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    
     5 years 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
    </p><p>/**</p><p>*</p><p>* Order items view</p><p>* @author Marco Schmidt</p><p>*/</p><p>
    </
    p><p>// Check to ensure this file is included in Joomla!</p><p>defined('_JEXEC') or die('Restricted access');</p><p>
    </p><p> if VmConfig::get('show_tax')) {</p><p>    $colspan=7;</p><p> } else {</p><p>    $colspan=8;</p><p> }</p><p>
    ?>

    <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
    </p><p><span class="Apple-tab-span" style="white-space:pre;">                </span>foreach($this->orderDetails['items'] as $item) {</p><p><span class="Apple-tab-span" style="white-space:pre;">                    </span>$qtt $item->product_quantity ;</p><p><span class="Apple-tab-span" style="white-space:pre;">                    </span>$product_link JURI::root().'index.php?option=com_virtuemart&view=productdetails&virtuemart_category_id=' $item->virtuemart_category_id .</p><p><span class="Apple-tab-span" style="white-space:pre;">                        </span>'&virtuemart_product_id=' $item->virtuemart_product_id;</p><p>
    </
    p><p><span class="Apple-tab-span" style="white-space:pre;">                </span>
    ?>

    <tr>

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

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

    <?php
    </p><p><span class="Apple-tab-span" style="white-space:pre;">                            </span> if (!empty($item->product_quantity)) {</p><p>
    </
    p><p><span class="Apple-tab-span" style="white-space:pre;">                                </span$ProductModelVmModel::getModel('product');</p><p>       <span class="Apple-tab-span" style="white-space:pre;">                    </span $product $ProductModel->getProduct($item->virtuemart_product_id);</p><p><span class="Apple-tab-span" style="white-space:pre;">                                </span$db JFactory::getDBO();</p><p><span class="Apple-tab-span" style="white-space:pre;">                                </span$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);</p><p><span class="Apple-tab-span" style="white-space:pre;">                                </span>  $db->setQuery($qs);</p><p><span class="Apple-tab-span" style="white-space:pre;">                                </span>  $item2 = $db->loadAssocList();</p><p><span class="Apple-tab-span" style="white-space:pre;">                                        </span> foreach($item2 as $file_thumb){</p><p><span class="Apple-tab-span" style="white-space:pre;">                                            </span>//echo $file_thumb['file_url_thumb'];</p><p><span class="Apple-tab-span" style="white-space:pre;">                                            </span> 
    ?>

       <img src="

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

    <?php
    </p><p><span class="Apple-tab-span" style="white-space:pre;">                                            </span> }</p><p><span class="Apple-tab-span" style="white-space:pre;">                                        </span }</p><p>
    </
    p><p><span class="Apple-tab-span" style="white-space:pre;">                                        </span>
    ?>

    <!--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
     
    </p><p>      <span class="Apple-tab-span" style="white-space:pre;">                            </span>$ProductModelVmModel::getModel('product');</p><p>       <span class="Apple-tab-span" style="white-space:pre;">                            </span>$product $ProductModel->getProduct($item->virtuemart_product_id);</p><p><span class="Apple-tab-span" style="white-space:pre;">                                </span>echo shopFunctionsF::limitStringByWord($product->product_s_desc30'...') </p><p><span class="Apple-tab-span" style="white-space:pre;">                            </span>
    ?>

    <!-- 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
    </p><p><span class="Apple-tab-span" style="white-space:pre;">                            </span>$item->product_basePriceWithTax = (float) $item->product_basePriceWithTax;</p><p><span class="Apple-tab-span" style="white-space:pre;">                            </span>$class '';</p><p><span class="Apple-tab-span" style="white-space:pre;">                            </span>if(!empty($item->product_basePriceWithTax) && $item->product_basePriceWithTax != $item->product_final_price ) {</p><p>              // MarcoMod Normalpreis Gesamt</p><p>              // echo '<span class="line-through">'.$this->currency->priceDisplay($item->product_item_price,$this->currency,$qtt) .'</span>
    ' ;</p><p><span class="Apple-tab-span" style="white-space:pre;">                            </span>}</p><p>
    </p><p><span class="Apple-tab-span" style="white-space:pre;">                            </span>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
    </p><p><span class="Apple-tab-span" style="white-space:pre;">                    </span>}</p><p><span class="Apple-tab-span" style="white-space:pre;">                </span>
    ?>

    <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
    </p><p><span class="Apple-tab-span" style="white-space:pre;">                </span>if ($this->orderDetails['details']['BT']->coupon_discount <> 0.00) {</p><p>    <span class="Apple-tab-span" style="white-space:pre;">            </span>$coupon_code=$this->orderDetails['details']['BT']->coupon_code?' ('.$this->orderDetails['details']['BT']->coupon_code.')':'';</p><p><span class="Apple-tab-span" style="white-space:pre;">                    </span>
    ?>

    <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
     
    </p><p><span class="Apple-tab-span" style="white-space:pre;">                        </span //FOR SEYI</p><p><span class="Apple-tab-span" style="white-space:pre;">                        </span>  echo ''.$this->currency->priceDisplay($this->orderDetails['details']['BT']->coupon_discount, $this->currency); </p><p>              // echo ''.$this->currency->priceDisplay($this->orderDetails['details']['BT']->coupon_Value, $this->currency); </p><p>              //echo $this->currency->priceDisplay($this->orderDetails['details']['BT']->order_subtotal * 0.1, $this->currency);</p><p><span class="Apple-tab-span" style="white-space:pre;">                        </span>  <span class="Apple-tab-span" style="white-space:pre;">                    </span>  </p><p><span class="Apple-tab-span" style="white-space:pre;">                        </span>  
    ?>

    </td>

    </tr>

    <?php
      

    ?>

    <!--MarcoMod-End-->

    <?php
    </p><p><span class="Apple-tab-span" style="white-space:pre;">                </span>foreach($this->orderDetails['calc_rules'] as $rule){</p><p><span class="Apple-tab-span" style="white-space:pre;">                    </span>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
    </p><p><span class="Apple-tab-span" style="white-space:pre;">                </span>} 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
    </p><p><span class="Apple-tab-span" style="white-space:pre;">                </span> } 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
    </p><p><span class="Apple-tab-span" style="white-space:pre;">                    </span> }</p><p><span class="Apple-tab-span" style="white-space:pre;">                </span>}</p><p><span class="Apple-tab-span" style="white-space:pre;">                </span>
    ?>

    <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    
     5 years 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    
     5 years ago
    0

    Well, that is exactly the result that work!


    Thank you for your quick replay and help.