كيفية التحقق من القواعد الضريبية في صفحة فاتورة Prestashop 1.6
-
21-12-2019 - |
سؤال
أريد التحقق من القواعد الضريبية لكل منتج في صفحة الفاتورة.
هل هناك أي متغير يخزن القواعد الضريبية مثل 8% أو 18%؟
سيكون شيئا من هذا القبيل
{if $order_invoice->tax_rule == "18%"}
...
{/if}
المحلول
تحقق من المتغير الصحيح
لن تجد هذه البيانات في $order_invoice
.إذا كنت ترغب في الحصول على القواعد الضريبية لكل منتج، فستحتاج إلى التحقق من $order_detail
فار.استخراج من invoice.tpl
:
<!-- PRODUCTS -->
{foreach $order_details as $order_detail}
{cycle values='#FFF,#DDD' assign=bgcolor}
<tr style="line-height:6px;background-color:{$bgcolor};">
<!-- Here we've got one line, for one product -->
<!-- This product's datas are stored in $order_detail -->
</tr>
يمكنك العثور على معدل الضريبة في $order_detail.tax_rate
.لسوء الحظ، فإنه يعود دائما 0.000
.
نعم...لم يتم ملء هذه البيانات...يوم حزين...
يخترع OrderDetail
تجاوز
إنشاء OrderDetail.php
الملف في override/classes/order/
مجلد يحتوي على هذا الكود :
class OrderDetail extends OrderDetailCore
{
/**
* Get order products
*
* @return array Products with price, quantity (with taxe and without)
*/
public function getProducts($products = false, $selectedProducts = false, $selectedQty = false)
{
if (!$products)
$products = $this->getProductsDetail();
$order = new Order($this->id_order);
$customized_datas = Product::getAllCustomizedDatas($order->id_cart);
$resultArray = array();
foreach ($products as $row)
{
// Retrieve tax rate
$product = new Product($row['product_id']);
$row['tax_rate'] = $product->getTaxesRate();
// Change qty if selected
if ($selectedQty)
{
$row['product_quantity'] = 0;
foreach ($selectedProducts as $key => $id_product)
if ($row['id_order_detail'] == $id_product)
$row['product_quantity'] = (int)($selectedQty[$key]);
if (!$row['product_quantity'])
continue;
}
$this->setProductImageInformations($row);
$this->setProductCurrentStock($row);
$this->setProductCustomizedDatas($row, $customized_datas);
// Add information for virtual product
if ($row['download_hash'] && !empty($row['download_hash']))
{
$row['filename'] = ProductDownload::getFilenameFromIdProduct((int)$row['product_id']);
// Get the display filename
$row['display_filename'] = ProductDownload::getFilenameFromFilename($row['filename']);
}
$row['id_address_delivery'] = $order->id_address_delivery;
/* Stock product */
$resultArray[(int)$row['id_order_detail']] = $row;
}
if ($customized_datas)
Product::addCustomizationPrice($resultArray, $customized_datas);
return $resultArray;
}
}
يسمح لنا هذا التجاوز بتحرير ملف tax_rate
قيمة.
لقد قمت ببساطة بإضافة هذين السطرين في ملف getProducts()
وظيفة :
foreach ($products as $row)
{
// Retrieve tax rate
$product = new Product($row['product_id']);
$row['tax_rate'] = $product->getTaxesRate();
// ...
}
يخترع OrderInvoice
تجاوز
إنشاء OrderInvoice.php
الملف في override/classes/order/
مجلد.
سوف تحتوي هذه الفئة نفس الرمز كما تجاوز لدينا السابقة.فقط قم بتغيير الأسطر الأولى:
<?php
class OrderInvoice extends OrderInvoiceCore
{
// Copy/Paste the same code
}
والآن يمكنك عرض معدل الضريبة لكل منتج باستخدام {$order_detail.tax_rate}
!!
(مكافأة) قم بتحرير القالب الخاص بك
دعونا نغير هذا القالب (هنا: pdf/invoice.tpl
) لإضافة عمود "قاعدة الضريبة":
<tr style="line-height:4px;">
<!-- Remove 10% from the first column header width -->
<td style="text-align: left; background-color: #4D4D4D; color: #FFF; padding-left: 10px; font-weight: bold; width: {if !$tax_excluded_display}25%{else}35%{/if}">{l s='Product / Reference' pdf='true'}</td>
...
<!-- Add our new column header, 10% width -->
<td style="background-color: #4D4D4D; color: #FFF; text-align: right; font-weight: bold; width: 10%; white-space: nowrap;">{l s='Tax rate' pdf='true'}</td>
...
</tr>
<!-- PRODUCTS -->
{foreach $order_details as $order_detail}
{cycle values='#FFF,#DDD' assign=bgcolor}
<tr style="line-height:6px;background-color:{$bgcolor};">
<!-- Remove 10% from the first column width -->
<td style="text-align: left; width: {if !$tax_excluded_display}25%{else}35%{/if}">{$order_detail.product_name}{if isset($order_detail.product_reference) && !empty($order_detail.product_reference)} ({l s='Reference:' pdf='true'} {$order_detail.product_reference}){/if}</td>
...
<!-- Add our new column, 10% width -->
<td style="text-align: right; width: 10%; white-space: nowrap;">
{$order_detail.tax_rate}
</td>
...
</tr>
نصائح أخرى
أعتقد الطريقة الصحيحة هي تجاوز وظيفة GetPreducts () في orderinvoice.php
giveacodicetagpre.واستخدام قيمة معدل في. TPL
giveacodicetagpre.تذكر حذف ذاكرة التخزين المؤقت / class_index.php
ربما لديك قاعدة ضريبة المنتج اعتمادا على عنوان الشحن.حاول
giveacodicetagpre.{
giveacodicetagpre.