Skip to content
Permalink
Browse files

Shop (fixed #2196, fixed #1726): it was not possible to edit orders w…

…hich have products with product options

git-svn-id: http://svn.contrexxlabs.com/contrexx/branches/contrexx_3_2@31703 5ce06e5d-2b28-0410-aa6a-b3cd9cf52d8a
  • Loading branch information...
Ueli Kramer
Ueli Kramer committed Jul 10, 2014
1 parent 3b78558 commit 6477d4b81d048af0cef9b1ea5952f652b982560b
@@ -2492,14 +2492,6 @@ function view_order_details($edit=false)
} elseif ($result === true) {
$edit = false;
}
if($edit){
$order_id = intval($_REQUEST['order_id']);
$objOrder = Order::getById($order_id);
$options = $objOrder->getOptionArray();
if(!empty($options[$order_id])){
$edit = false;
}
}
if ($edit) {
self::$pageTitle = $_ARRAYLANG['TXT_EDIT_ORDER'];
self::$objTemplate->loadTemplateFile('module_shop_order_edit.html');
@@ -659,6 +659,7 @@
$_ARRAYLANG['TXT_SHOP_ORDER_STATUS_SHIPPED'] = "versandt";
$_ARRAYLANG['TXT_SHOP_ORDER_SUM'] = "Summe";
$_ARRAYLANG['TXT_SHOP_ORDER_TIME'] = "Bestellungszeit";
$_ARRAYLANG['TXT_SHOP_ORDER_ITEM_HAS_OPTIONS'] = "Dieses Produkt wurde mit Optionen bestellt und kann deshalb nicht bearbeitet werden!";
$_ARRAYLANG['TXT_SHOP_ORDER_WARNING_NO_ITEM'] = "Der Bestellung sind keine Artikel zugeordnet";
$_ARRAYLANG['TXT_SHOP_ORDERITEMS_AMOUNT_MAX'] = "Maximaler Betrag für bestellte Artikel";
$_ARRAYLANG['TXT_SHOP_ORDERITEMS_AMOUNT_MAX_NOTE'] = "Hinweis: Lassen Sie den Wert leer oder setzen Sie ihn auf 0 (Null), um die Beschränkung ausser Kraft zu setzen.";
@@ -658,6 +658,7 @@
$_ARRAYLANG['TXT_SHOP_ORDER_STATUS_SHIPPED'] = "shipped";
$_ARRAYLANG['TXT_SHOP_ORDER_SUM'] = "Sum";
$_ARRAYLANG['TXT_SHOP_ORDER_TIME'] = "Order time";
$_ARRAYLANG['TXT_SHOP_ORDER_ITEM_HAS_OPTIONS'] = "This product has been ordered with product options. You can't edit it here!";
$_ARRAYLANG['TXT_SHOP_ORDER_WARNING_NO_ITEM'] = "Warning: there are no products assigned to this order";
$_ARRAYLANG['TXT_SHOP_ORDERITEMS_AMOUNT_MAX'] = "Maximum product amount per order";
$_ARRAYLANG['TXT_SHOP_ORDERITEMS_AMOUNT_MAX_NOTE'] = "Note: Leave this field empty, or set it to 0 (zero) to disable the limit.";
@@ -409,10 +409,11 @@ static function update($objCustomer)
$total_discount_amount = 0;
//DBG::log("Cart::update(): Products: ".var_export($products, true));
// Loop 1: Collect necessary Product data
foreach ($_SESSION['shop']['cart']['items'] as $cart_id => $product) {
$products = $_SESSION['shop']['cart']['items']->toArray();
foreach ($products as $cart_id => &$product) {
$objProduct = Product::getById($product['id']);
if (!$objProduct) {
unset($_SESSION['shop']['cart']['items'][$cart_id]);
unset($products[$cart_id]);
continue;
}
// Limit Products in the cart to the stock available if the
@@ -423,7 +424,7 @@ static function update($objCustomer)
}
// Remove Products with quatities of zero or less
if ($product['quantity'] <= 0) {
unset($_SESSION['shop']['cart']['items'][$cart_id]);
unset($products[$cart_id]);
continue;
}
$options_price = 0;
@@ -514,6 +515,7 @@ static function update($objCustomer)
);
//DBG::log("Cart::update(): Loop 1: Product: ".var_export(self::$products[$cart_id], true));
}
$_SESSION['shop']['cart']['items'] = $products;
// Loop 2: Calculate Coupon discounts and VAT
$objCoupon = null;
$hasCoupon = false;
@@ -655,7 +657,7 @@ static function get_product_id($cart_id)
*/
static function get_products_array()
{
return $_SESSION['shop']['cart']['items'];
return $_SESSION['shop']['cart']['items']->toArray();
}
@@ -1158,6 +1158,8 @@ static function storeFromPost()
}
// store the product details and add the price of each product
// to the total order sum $totalOrderSum
$order = self::getById($order_id);
$orderOptions = $order->getOptionArray();
foreach ($_REQUEST['product_list'] as $orderItemId => $product_id) {
if ($orderItemId != 0 && $product_id == 0) {
// delete the product from the list
@@ -1184,8 +1186,16 @@ static function storeFromPost()
continue;
}
$product_name = $objProduct->name();
$price = Currency::formatPrice(
$_REQUEST['productPrice'][$orderItemId]);
$productPrice = $price = $_REQUEST['productPrice'][$orderItemId];
if (isset($orderOptions[$orderItemId])) {
foreach ($orderOptions[$orderItemId] as $optionValues) {
foreach ($optionValues as $value) {
$price += $value['price'];
}
}
}
$price = Currency::formatPrice($price);
$productPrice = Currency::formatPrice($productPrice);
$quantity = max(1,
intval($_REQUEST['productQuantity'][$orderItemId]));
$totalOrderSum += $price * $quantity;
@@ -1196,13 +1206,13 @@ static function storeFromPost()
if ($orderItemId == 0) {
// Add a new product to the list
if (!self::insertItem($order_id, $product_id, $product_name,
$price, $quantity, $vat_rate, $weight, array())) {
$productPrice, $quantity, $vat_rate, $weight, array())) {
return false;
}
} else {
// Update the order item
if (!self::updateItem($orderItemId, $product_id,
$product_name, $price, $quantity, $vat_rate, $weight, array())) {
$product_name, $productPrice, $quantity, $vat_rate, $weight, array())) {
return false;
}
}
@@ -1549,6 +1559,10 @@ static function updateItem($item_id, $product_id, $name, $price, $quantity,
if (!$objResult) {
return Message::error($_ARRAYLANG['TXT_SHOP_ORDER_ITEM_ERROR_UPDATING']);
}
// don't save options if there is none
if (empty($arrOptions)) return true;
if (!self::deleteOptions($item_id)) return false;
foreach ($arrOptions as $attribute_id => $arrOptionIds) {
if (!self::insertAttribute($item_id, $attribute_id, $arrOptionIds)) {
@@ -2032,6 +2046,8 @@ function view_items($objTemplate, $edit, $total_weight=0, $i=0)
$total_weight += $weight * $quantity;
}
}
$itemHasOptions = !empty($arrProductOptions[$item_id]);
$objTemplate->setVariable(array(
'SHOP_PRODUCT_ID' => $product_id,
'SHOP_ROWCLASS' => 'row'.(++$i % 2 + 1),
@@ -2040,7 +2056,7 @@ function view_items($objTemplate, $edit, $total_weight=0, $i=0)
'SHOP_PRODUCT_PRICE' => Currency::formatPrice($price),
'SHOP_PRODUCT_SUM' => Currency::formatPrice($row_net_price),
'SHOP_P_ID' => ($edit
? $objResult->fields['id'] // Item ID
? $item_id // Item ID
// If we're just showing the order details, the
// product ID is only used in the product ID column
: $objResult->fields['product_id']), // Product ID
@@ -2055,10 +2071,13 @@ function view_items($objTemplate, $edit, $total_weight=0, $i=0)
// Get a product menu for each Product if $edit-ing.
// Preselect the current Product ID.
if ($edit) {
if ($itemHasOptions && $objTemplate->blockExists('order_item_product_options_tooltip')) {
$objTemplate->touchBlock('order_item_product_options_tooltip');
}
$objTemplate->setVariable(
'SHOP_PRODUCT_IDS_MENU', Products::getMenuoptions(
$product_id, null,
$_ARRAYLANG['TXT_SHOP_PRODUCT_MENU_FORMAT']));
$_ARRAYLANG['TXT_SHOP_PRODUCT_MENU_FORMAT'], false));
}
$objTemplate->parse('order_item');
$objResult->MoveNext();
@@ -1041,19 +1041,26 @@ static function getJavascriptArray($groupCustomerId=0, $isReseller=false)
* inactive (false) Products only.
* Ignored if null. Defaults to null
* @param string $format The optional sprintf() format
* @param boolean $showAllOptions Show all options and not only the selected
* @return array The HTML options string on success,
* null otherwise
* @global ADONewConnection
* @author Reto Kohli <reto.kohli@comvation.com>
*/
static function getMenuoptions($selected=null, $active=null, $format='%2$s')
static function getMenuoptions($selected=null, $active=null, $format='%2$s', $showAllOptions = true)
{
global $_ARRAYLANG;
$arrName =
array(0 => $_ARRAYLANG['TXT_SHOP_PRODUCT_NONE']) +
self::getNameArray($active, $format);
if ($arrName === false) return null;
if ($selected && !$showAllOptions) {
$arrName = array();
$product = \Product::getById($selected);
$arrName[$product->id()] = $product->name();
}
return Html::getOptions($arrName, $selected);
}
@@ -229,6 +229,9 @@
size="1" onchange="changeProduct({SHOP_P_ID},this.value);">
{SHOP_PRODUCT_IDS_MENU}
</select>
<!-- BEGIN order_item_product_options_tooltip -->
<span class="icon-info tooltip-trigger"></span><span class="tooltip-message">{TXT_SHOP_ORDER_ITEM_HAS_OPTIONS}</span>
<!-- END order_item_product_options_tooltip -->
</td>
<!--td>
<input type="text" size="50" id="product_name-{SHOP_P_ID}"

0 comments on commit 6477d4b

Please sign in to comment.
You can’t perform that action at this time.