本文整理汇总了PHP中OrderDetail::delete方法的典型用法代码示例。如果您正苦于以下问题:PHP OrderDetail::delete方法的具体用法?PHP OrderDetail::delete怎么用?PHP OrderDetail::delete使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类OrderDetail
的用法示例。
在下文中一共展示了OrderDetail::delete方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: reinjectQuantity
/**
* @param OrderDetail $order_detail
* @param int $qty_cancel_product
* @param bool $delete
*/
protected function reinjectQuantity($order_detail, $qty_cancel_product, $delete = false)
{
// Reinject product
$reinjectable_quantity = (int) $order_detail->product_quantity - (int) $order_detail->product_quantity_reinjected;
$quantity_to_reinject = $qty_cancel_product > $reinjectable_quantity ? $reinjectable_quantity : $qty_cancel_product;
// @since 1.5.0 : Advanced Stock Management
$product_to_inject = new Product($order_detail->product_id, false, (int) $this->context->language->id, (int) $order_detail->id_shop);
$product = new Product($order_detail->product_id, false, (int) $this->context->language->id, (int) $order_detail->id_shop);
if (Configuration::get('PS_ADVANCED_STOCK_MANAGEMENT') && $product->advanced_stock_management && $order_detail->id_warehouse != 0) {
$manager = StockManagerFactory::getManager();
$movements = StockMvt::getNegativeStockMvts($order_detail->id_order, $order_detail->product_id, $order_detail->product_attribute_id, $quantity_to_reinject);
$left_to_reinject = $quantity_to_reinject;
foreach ($movements as $movement) {
if ($left_to_reinject > $movement['physical_quantity']) {
$quantity_to_reinject = $movement['physical_quantity'];
}
$left_to_reinject -= $quantity_to_reinject;
if (Pack::isPack((int) $product->id)) {
// Gets items
if ($product->pack_stock_type == 1 || $product->pack_stock_type == 2 || $product->pack_stock_type == 3 && Configuration::get('PS_PACK_STOCK_TYPE') > 0) {
$products_pack = Pack::getItems((int) $product->id, (int) Configuration::get('PS_LANG_DEFAULT'));
// Foreach item
foreach ($products_pack as $product_pack) {
if ($product_pack->advanced_stock_management == 1) {
$manager->addProduct($product_pack->id, $product_pack->id_pack_product_attribute, new Warehouse($movement['id_warehouse']), $product_pack->pack_quantity * $quantity_to_reinject, null, $movement['price_te'], true);
}
}
}
if ($product->pack_stock_type == 0 || $product->pack_stock_type == 2 || $product->pack_stock_type == 3 && (Configuration::get('PS_PACK_STOCK_TYPE') == 0 || Configuration::get('PS_PACK_STOCK_TYPE') == 2)) {
$manager->addProduct($order_detail->product_id, $order_detail->product_attribute_id, new Warehouse($movement['id_warehouse']), $quantity_to_reinject, null, $movement['price_te'], true);
}
} else {
$manager->addProduct($order_detail->product_id, $order_detail->product_attribute_id, new Warehouse($movement['id_warehouse']), $quantity_to_reinject, null, $movement['price_te'], true);
}
}
$id_product = $order_detail->product_id;
if ($delete) {
$order_detail->delete();
}
StockAvailable::synchronize($id_product);
} elseif ($order_detail->id_warehouse == 0) {
StockAvailable::updateQuantity($order_detail->product_id, $order_detail->product_attribute_id, $quantity_to_reinject, $order_detail->id_shop);
if ($delete) {
$order_detail->delete();
}
} else {
$this->errors[] = Tools::displayError('This product cannot be re-stocked.');
}
}
示例2: _deleteProduct
/**
* DOES delete the product
*
* @param OrderDetail $order_detail
* @param int $quantity
* @return bool
* @throws PrestaShopException
*/
protected function _deleteProduct($order_detail, $quantity)
{
$product_price_tax_excl = $order_detail->unit_price_tax_excl * $quantity;
$product_price_tax_incl = $order_detail->unit_price_tax_incl * $quantity;
/* Update cart */
$cart = new Cart($this->id_cart);
$cart->updateQty($quantity, $order_detail->product_id, $order_detail->product_attribute_id, false, 'down');
// customization are deleted in deleteCustomization
$cart->update();
/* Update order */
$shipping_diff_tax_incl = $this->total_shipping_tax_incl - $cart->getPackageShippingCost($this->id_carrier, true, null, $this->getCartProducts());
$shipping_diff_tax_excl = $this->total_shipping_tax_excl - $cart->getPackageShippingCost($this->id_carrier, false, null, $this->getCartProducts());
$this->total_shipping -= $shipping_diff_tax_incl;
$this->total_shipping_tax_excl -= $shipping_diff_tax_excl;
$this->total_shipping_tax_incl -= $shipping_diff_tax_incl;
$this->total_products -= $product_price_tax_excl;
$this->total_products_wt -= $product_price_tax_incl;
$this->total_paid -= $product_price_tax_incl + $shipping_diff_tax_incl;
$this->total_paid_tax_incl -= $product_price_tax_incl + $shipping_diff_tax_incl;
$this->total_paid_tax_excl -= $product_price_tax_excl + $shipping_diff_tax_excl;
$this->total_paid_real -= $product_price_tax_incl + $shipping_diff_tax_incl;
$fields = array('total_shipping', 'total_shipping_tax_excl', 'total_shipping_tax_incl', 'total_products', 'total_products_wt', 'total_paid', 'total_paid_tax_incl', 'total_paid_tax_excl', 'total_paid_real');
/* Prevent from floating precision issues */
foreach ($fields as $field) {
if ($this->{$field} < 0) {
$this->{$field} = 0;
}
}
/* Prevent from floating precision issues */
foreach ($fields as $field) {
$this->{$field} = number_format($this->{$field}, _PS_PRICE_COMPUTE_PRECISION_, '.', '');
}
/* Update order detail */
$order_detail->product_quantity -= (int) $quantity;
if ($order_detail->product_quantity == 0) {
if (!$order_detail->delete()) {
return false;
}
if (count($this->getProductsDetail()) == 0) {
$history = new OrderHistory();
$history->id_order = (int) $this->id;
$history->changeIdOrderState(Configuration::get('PS_OS_CANCELED'), $this);
if (!$history->addWithemail()) {
return false;
}
}
return $this->update();
} else {
$order_detail->total_price_tax_incl -= $product_price_tax_incl;
$order_detail->total_price_tax_excl -= $product_price_tax_excl;
$order_detail->total_shipping_price_tax_incl -= $shipping_diff_tax_incl;
$order_detail->total_shipping_price_tax_excl -= $shipping_diff_tax_excl;
}
return $order_detail->update() && $this->update();
}