本文整理汇总了PHP中shipping::estimateShipping方法的典型用法代码示例。如果您正苦于以下问题:PHP shipping::estimateShipping方法的具体用法?PHP shipping::estimateShipping怎么用?PHP shipping::estimateShipping使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类shipping
的用法示例。
在下文中一共展示了shipping::estimateShipping方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: calculateGrandTotal
//.........这里部分代码省略.........
$this->orderitem[$i]->products_price_adjusted = $this->orderitem[$i]->products_price;
//$this->orderitem[$i]->products_price_original = $this->orderitem[$i]->product->getPrice();
$this->subtotal += $this->orderitem[$i]->products_price * $this->orderitem[$i]->quantity;
$this->surcharge_total += $this->orderitem[$i]->product->getSurcharge() * $this->orderitem[$i]->quantity;
}
for ($i = 0; $i < count($this->orderitem); $i++) {
//only allowing one discount for now, but in future we'll need to process
//multiple and accomdate the "weight" and 'allow other discounts' type settings
//this foreach will only fire once as of now, and will only hit on one or the other
//TODO: We need to use produce_price_adjusted in the loops to accomodate for more than one disocunt
//otherwise it's just resetting them now instead of adding them
foreach ($cartDiscounts as $od) {
//do not calculate invalid discounts, but don't remove either
$discount = new discounts($od->discounts_id);
/*$validateDiscountMessage = $discount->validateDiscount();
if($validateDiscountMessage != '') break;*/
//percentage discount
if ($discount->action_type == 3) {
$discount_amount = round($this->orderitem[$i]->products_price * ($discount->discount_percent / 100), 2);
// change the price of the orderitem..this is needed for when we calculate tax below.
$this->orderitem[$i]->products_price_adjusted = $this->orderitem[$i]->products_price - $discount_amount;
// keep a tally of the total amount being subtracted by this discount.
$this->total_discounts += $discount_amount * $this->orderitem[$i]->quantity;
}
//straight $$ discount
if ($discount->action_type == 4) {
$this->total_discounts = $discount->discount_amount;
//what % of the order is this product with all it's quantity
$percentOfTotalOrder = $this->orderitem[$i]->products_price * $this->orderitem[$i]->quantity / $this->subtotal;
//figoure out how much that'll be and what each quanityt piece will bare
$discountAmountPerItem = round($percentOfTotalOrder * $discount->discount_amount / $this->orderitem[$i]->quantity, 2);
//$discount_amount = $this->orderitem[$i]->products_price * ($discount->discount_percent / 100);
// change the price of the orderitem..this is needed for when we calculate tax below.
$this->orderitem[$i]->products_price_adjusted = $this->orderitem[$i]->products_price - $discountAmountPerItem;
// keep a tally of the total amount being subtracted by this discount.
//$this->total_discounts += $discountAmountPerItem * $this->orderitem[$i]->quantity; //eDebug($discountAmountPerItem);
}
}
// calculate the tax for this product
$taxclass = new taxclass($this->orderitem[$i]->product->tax_class_id);
$this->orderitem[$i]->products_tax = $taxclass->getProductTax($this->orderitem[$i]);
$this->tax += $this->orderitem[$i]->products_tax * $this->orderitem[$i]->quantity;
//save out the order item
$this->orderitem[$i]->save();
}
// add the "cart discounts" - percentage for sure, but straight can work also should be added after the final total is calculated,
//including tax but not shipping
// $this->updateOrderDiscounts();
/*foreach ($cartDiscounts as $od)
{
$discount = new discounts($od->discounts_id);
if ($discount->action_type == 4)
{
$this->total_discounts += $discount->discount_amount;
}
} */
// calculate the shipping costs - need to check shipping discounts here in the future
$estimate_shipping = false;
if ($this->shipping_required) {
$shippingmethods = $this->getShippingMethods();
if (count($shippingmethods) > 0) {
foreach ($shippingmethods as $sm_id) {
$method = new shippingmethod($sm_id, true);
if ($method->requiresShipping($this)) {
/*
//need to implement handling
$shippingCalc = new shippingcalculator($method->shippingcalculator_id);
$calc = new $shippingCalc->calculator_name($method->shippingcalculator_id);
eDebug($calc,true);*/
$this->shipping_total += $method->shipping_cost;
// + $method->calculator->getHandling();
}
}
} else {
$estimate_shipping = true;
}
}
$this->shipping_total_before_discounts = $this->shipping_total;
if (isset($cartDiscounts)) {
foreach ($cartDiscounts as $od) {
$discount = new discounts($od->discounts_id);
$this->shipping_total = $discount->calculateShippingTotal($this->shipping_total);
}
}
$this->shippingDiscount = $this->shipping_total_before_discounts - $this->shipping_total;
//check here to make sure we don't discount ourselves into oblivion
$orderTotalPreDiscounts = $this->subtotal + $this->tax + $this->shipping_total;
if ($this->total_discounts > $orderTotalPreDiscounts) {
$this->total_discounts = $orderTotalPreDiscounts;
}
$this->total = $this->subtotal - $this->total_discounts;
if ($estimate_shipping) {
$this->shipping_total = shipping::estimateShipping($this);
}
// figure out which tax zones apply to this order.
$this->taxzones = taxclass::getCartTaxZones($this);
$this->grand_total = $this->subtotal - $this->total_discounts + $this->tax + $this->shipping_total + $this->surcharge_total;
//if($validateDiscountMessage != '') flash('message',$validateDiscountMessage);
//eDebug($this, true);
}