PDA

View Full Version : تغییر ماژول تخفیف به کارمزد



kamiar3712
دوشنبه 05 آبان 1393, 16:50 عصر
سلام دوباره دوستان
در وردرپرس و افزونه ووکامرس:

برای بخش کارمزد بنده افزونه تخفیف را woocommerce-bulk-discount به کارمزد تغییر دادم یعنی در بخشی که قرار است بصورت تخفیف مبلغ کسر شود, مبلغ اضافه میشود:



public function filter_cart_product_subtotal( $subtotal, $_product, $quantity ) {

if ( !$_product || !$quantity ) {
return $subtotal;
}
if ( $this->coupon_check() ) {
return $subtotal;
}
if ( get_post_meta( $_product->id, "_bulkdiscount_enabled", true ) != '' && get_post_meta( $_product->id, "_bulkdiscount_enabled", true ) !== 'yes' ) {
return $subtotal;
}

$coeff = $this->discount_coeffs[$this->get_actual_id( $_product )]['coeff'];
if ( ( get_option( 'woocommerce_t4m_discount_type', '' ) == 'flat' ) ) {
$newsubtotal = woocommerce_price( max( 0, ( $_product->get_price() * $quantity ) + $coeff ) );
} else {
$newsubtotal = woocommerce_price( $_product->get_price() * $quantity * $coeff );
}

return $newsubtotal;

همان طور که متوجه شده اید با + $coeff مبلغ اضافه میشود و اتفاقا در صدور
فاکتور در ردیف کالا, مشکلی وجود ندارد و بدرستی کارمزد اضافه میشود اما در
جمع کل سبد خرید دوباره مبلغ کسر میشود و بشکلی که انگار مبلغ کالا به
صورت تخفیف محاسبه شده, بیان میشود.
در تصویر هم مشخص است.

http://s5.picofile.com/file/8147425292/Error.JPG (http://go.persianscript.ir/index.php?url=http://s5.picofile.com/file/8147425292/Error.JPG)

دوستان نظری دارند؟

مشکل بسیار کوچک است و شاید یکساعت کار داشته باشد اما متاسفانه به علت درگیری کاری نمیتوانم وقت برای آن بگذارم.

اگر عزیزی میتواند مورد را حل کند لطفا هزینه را پ.خ کند.

kamiar3712
سه شنبه 06 آبان 1393, 09:43 صبح
دوستان PHP کار نبود؟

us1234
سه شنبه 06 آبان 1393, 15:04 عصر
حدسی که میزنم این است که یک تابع دیگر مشابه این باید وجود داشته باشد .
این کدها به نظر میرسد که درست است .

kamiar3712
سه شنبه 06 آبان 1393, 15:44 عصر
بله تقریبا سه تا چهار فایل درگیر هستند که آخرین کدی که به آن رسیدیم بصورت زیر است که در اینجا قرار میدهم:

ابتدا تابع wc_cart_totals_subtotal_html(); :




<tr class="cart-subtotal">
<th><?php _e( 'Cart Subtotal', 'woocommerce' ); ?></th>
<td><?php wc_cart_totals_subtotal_html(); ?></td>

</tr>



و سپس:




function wc_cart_totals_subtotal_html() {
echo WC()->cart->get_cart_subtotal();
}





و در نهایت که فکر میکنم باید در این بخش به دنبال مشکل گشت:



/**
* Gets the sub total (after calculation).
*
* @params bool whether to include compound taxes
* @return string formatted price
*/
public function get_cart_subtotal( $compound = false ) {

// If the cart has compound tax, we want to show the subtotal as
// cart + shipping + non-compound taxes (after discount)
if ( $compound ) {

$cart_subtotal = wc_price( $this->cart_contents_total + $this->shipping_total + $this->get_taxes_total( false, false ) );

// Otherwise we show cart items totals only (before discount)
} else {

// Display varies depending on settings
if ( $this->tax_display_cart == 'excl' ) {

$cart_subtotal = wc_price( $this->subtotal_ex_tax );

if ( $this->tax_total > 0 && $this->prices_include_tax ) {
$cart_subtotal .= ' <small>' . WC()->countries->ex_tax_or_vat() . '</small>';
}

} else {

$cart_subtotal = wc_price( $this->subtotal );

if ( $this->tax_total > 0 && !$this->prices_include_tax ) {
$cart_subtotal .= ' <small>' . WC()->countries->inc_tax_or_vat() . '</small>';
}

}
}

us1234
سه شنبه 06 آبان 1393, 20:13 عصر
شما تخفیف ( که تبدیل کردید به کارمزد ) را به صورت flat ( همون ثابت خودمون ) تعریف کردید یا به صورت درصدی ؟

فکر کنم درصدی تعریف کردید و مقدار در عدد عشاری که ضرب میشود مقدار کمتر میشود .

kamiar3712
سه شنبه 06 آبان 1393, 23:28 عصر
خود ماژول به صورت پیش فرض درصد و مقدار ثابت دارد که دستی آن را مقدار ثابت (مثلا 5000 تومان) تعریف کرده ام.

به صورت معمول در هر ردیف فاکتور برای یک خرید درست حساب میشود اما در جمع کل فاکتور (تصویر در پست نخست است.) تغییر میکند و دوباره محاسبه میشود.
بنظر منطقی نیست که دوبار یک عملیات (محاسبه مبلغ کارمزد تا تخفیف) انجام گیرد!! یکبار برای هر کالا و دوباره در جمع کل!

kamiar3712
شنبه 10 آبان 1393, 09:41 صبح
دوستان کسی نبود؟