private function generateCustomizeItemForm(array $item) { $defaultItem = array( 'name' => '', 'quantity' => 1, 'price' => '', 'productId' => '', 'variationOptions' => array(), 'variationId' => 0, 'configuration' => '', 'wrapping' => '', 'itemId' => '', 'quoteSession' => '', 'eventDate' => array(), 'eventName' => '', 'sku' => '', ); $item = array_merge($defaultItem, $item); $this->template->assign('item', $item); if($item['productId']) { $productClass = new ISC_PRODUCT($item['productId']); if(!$productClass->getProductId()) { $this->sendEditOrderResponse(array( 'errors' => array( getLang('InvalidProduct') ) )); } $this->template->assign('product', $productClass->getProduct()); $this->template->assign('variationOptions', $productClass->GetProductVariationOptions()); $this->template->assign('variationValues', $productClass->GetProductVariationOptionValues()); $configurableFields = $productClass->GetProductFields($item['productId']); foreach($configurableFields as &$field) { if($field['type'] == 'select') { $options = explode(',', $field['selectOptions']); $field['selectOptions'] = array_map('trim', $options); } } $this->template->assign('configurableFields', $configurableFields); // Event date if($productClass->getEventDateRequired()) { $eventDateFromStamp = $productClass->getEventDateLimitedStartDate(); $eventDateToStamp = $productClass->getEventDateLimitedEndDate(); $eventDate = array( 'fromStamp' => $eventDateFromStamp, 'toStamp' => $eventDateToStamp, 'yearFrom' => isc_date('Y', $eventDateFromStamp), 'yearTo' => isc_date('Y', $eventDateToStamp) ); // Generate a list of month options $eventDate['monthOptions'] = array(); for($i = 1; $i <= 12; ++$i) { $stamp = isc_gmmktime(0, 0, 0, $i, 1, 2000); $month = isc_date("M", $stamp); $eventDate['monthOptions'][$i] = $month; } $eventDateLimit = $productClass->getEventDateLimited(); if(empty($eventDateLimit)) { $eventDate['yearFrom'] = isc_date('Y'); $eventDate['yearTo'] = $eventDate['yearFrom'] + 5; } else { $eventDate['limitationType'] = $productClass->getEventDateLimitedType(); if($eventDate['limitationType'] == 1) { $eventDate['compDate'] = isc_date('Y/m/d', $eventDateFromStamp); $eventDate['compDateEnd'] = isc_date('Y/m/d', $eventDateToStamp); } else if($eventDate['limitationType'] == 2) { $eventDate['yearTo'] = $eventDate['yearFrom'] + 5; $eventDate['compDate'] = isc_date('Y/m/d', $eventDateFromStamp); } else if($eventDate['limitationType'] == 3) { $eventDate['yearFrom'] = isc_date('Y'); $eventDate['compDate'] = isc_date('Y/m/d', $eventDateToStamp); } } $this->template->assign('eventDate', $eventDate); } } if(!empty($item['quoteItem'])) { $allowableWrappingOptions = $item['quoteItem']->getGiftWrappingOptions(); } // Product still exists - get the gift wrapping options on the product if(isset($productClass)) { $product = $productClass->getProduct(); $allowableWrappingOptions = explode(',', $product['prodwrapoptions']); } if(!empty($allowableWrappingOptions)) { if(empty($allowableWrappingOptions) || in_array(0, $allowableWrappingOptions)) { $giftWrapWhere = "wrapvisible='1'"; } else { $wrappingOptions = implode(',', array_map('intval', $allowableWrappingOptions)); $giftWrapWhere = "wrapid IN (".$wrappingOptions.")"; } $query = " SELECT * FROM [|PREFIX|]gift_wrapping WHERE ".$giftWrapWhere." ORDER BY wrapname ASC "; $giftWrappingOptions = array(); $result = $GLOBALS['ISC_CLASS_DB']->Query($query); while($wrap = $GLOBALS['ISC_CLASS_DB']->Fetch($result)) { $giftWrappingOptions[$wrap['wrapid']] = $wrap; } $this->template->assign('giftWrappingOptions', $giftWrappingOptions); } return array( 'data' => $this->template->render('order.form.customizeitem.tpl'), 'width' => 600, 'height' => 500, ); }
/** * Show the window to configure an item (variations, configurable fields) etc in the * order that's being created/edited. */ private function OrderConfigureProduct() { if (!isset($_REQUEST['cartItemId']) || !isset($_REQUEST['orderSession'])) { exit; } // Initialize the cart management API $orderClass = GetClass('ISC_ADMIN_ORDERS'); $orderClass->GetCartApi($_REQUEST['orderSession']); $existingProduct = $orderClass->GetCartApi()->GetProductInCart($_REQUEST['cartItemId']); if (is_array($existingProduct)) { if (isset($_REQUEST['productId']) && $existingProduct['product_id'] != $_REQUEST['productId']) { $existingProduct = false; } else { $_REQUEST['productId'] = $existingProduct['product_id']; } } // Fetch the product class on the front end as it'll be doing most of the work for this page $productClass = new ISC_PRODUCT($_REQUEST['productId']); if (!$productClass->GetProductId()) { exit; } if (!is_array($existingProduct) && !isset($_REQUEST['productId'])) { exit; } else { if (is_array($existingProduct)) { $GLOBALS['EditingExistingProduct'] = 1; $GLOBALS['Intro'] = GetLang('OrderConfigureProductEdit'); $GLOBALS['ButtonLabel'] = GetLang('OrderConfigureProductEditButton'); $productPrice = $existingProduct['product_price']; $GLOBALS['VariationId'] = $existingProduct['variation_id']; } else { $GLOBALS['Intro'] = GetLang('OrderConfigureProduct'); $GLOBALS['ButtonLabel'] = GetLang('AddProductToOrder'); // Finally, determine the price based on the customer group $product = $productClass->GetProduct(); $productPrice = CalcProdCustomerGroupPrice($product, $product['prodcalculatedprice']); } } $GLOBALS['ProductPrice'] = FormatPrice($productPrice); $productVariations = $productClass->GetProductVariations(); $GLOBALS['ProductName'] = isc_html_escape($productClass->GetProductName()); $GLOBALS['ProductId'] = (int) $productClass->GetProductId(); $GLOBALS['OrderSession'] = isc_html_escape($_REQUEST['orderSession']); $GLOBALS['CartItemId'] = isc_html_escape($_REQUEST['cartItemId']); $GLOBALS['Quantity'] = (int) $_REQUEST['quantity']; $GLOBALS['ProductOptionRequired'] = 0; $GLOBALS['VariationList'] = ''; if (!empty($productVariations)) { // If we have an existing variation already, look up the combination $existingCombination = array(); if (is_array($existingProduct) && $existingProduct['variation_id']) { $query = "\n\t\t\t\t\t\tSELECT vcoptionids\n\t\t\t\t\t\tFROM [|PREFIX|]product_variation_combinations\n\t\t\t\t\t\tWHERE combinationid='" . (int) $existingProduct['variation_id'] . "'\n\t\t\t\t\t"; $existingCombination = explode(',', $GLOBALS['ISC_CLASS_DB']->FetchOne($query)); } if ($productClass->IsOptionRequired()) { $GLOBALS['ProductOptionRequired'] = 1; $GLOBALS['VariationRequired'] = '*'; } else { $GLOBALS['VariationRequired'] = ' '; } $GLOBALS['VariationNumber'] = 0; foreach ($productVariations as $name => $options) { $GLOBALS['VariationNumber']++; $optionList = ''; foreach ($options as $option) { $sel = ''; if (in_array($option['voptionid'], $existingCombination)) { $sel = 'selected="selected"'; } $optionList .= '<option value="' . $option['voptionid'] . '" ' . $sel . '>' . isc_html_escape($option['vovalue']) . '</option>'; } $GLOBALS['VariationOptions'] = $optionList; $GLOBALS['VariationName'] = isc_html_escape($name); $GLOBALS['VariationList'] .= $GLOBALS['ISC_CLASS_TEMPLATE']->GetSnippet('OrderProductConfigurationVariation'); } $GLOBALS['ProductVariationJavascript'] = $productClass->GetProductVariationCombinationJavascript(); } else { $GLOBALS['HideVariationList'] = 'display: none'; } $fields = $productClass->GetProductFields($_REQUEST['productId']); $GLOBALS['ProductFields'] = ''; if (!empty($fields)) { foreach ($fields as $field) { $GLOBALS['FieldId'] = $field['id']; $GLOBALS['FieldRequired'] = ' '; $requiredClass = ''; $GLOBALS['FieldName'] = isc_html_escape($field['name']) . ':'; $GLOBALS['HideFieldHelp'] = 'display: none'; $GLOBALS['FieldHelp'] = ''; $GLOBALS['HideFileCurrentValue'] = 'display: none'; $existingValue = ''; if (isset($existingProduct['product_fields'][$field['id']])) { if ($field['type'] == 'file') { $existingValue = isc_html_escape($existingProduct['product_fields'][$field['id']]['fileOriginName']); $existingFileName = $existingProduct['product_fields'][$field['id']]['fileName']; } else { $existingValue = isc_html_escape($existingProduct['product_fields'][$field['id']]['fieldValue']); } } if ($field['required'] == 1) { $requiredClass = 'FieldRequired'; $GLOBALS['FieldRequired'] = '*'; } switch ($field['type']) { case 'textarea': $inputField = '<textarea cols="30" rows="3" name="productFields[' . $field['id'] . ']" class="Field300 ' . $requiredClass . '">' . $existingValue . '</textarea>'; break; case 'file': if ($existingValue) { $requiredClass .= 'HasExistingValue'; } $inputField = '<input type="file" name="productFields[' . $field['id'] . ']" class="Field300 ' . $requiredClass . '" />'; $help = array(); if ($field['fileSize'] > 0) { $help[] = GetLang('MaximumSize') . ': ' . NiceSize($field['fileSize'] * 1024); } if ($field['fileType'] != '') { $help[] = GetLang('AllowedTypes') . ': ' . '<span class="FileTypes">' . isc_strtoupper(isc_html_escape($field['fileType']) . '</span>'); } $help = implode('. ', $help); if ($help != '') { $GLOBALS['HideFieldHelp'] = ''; $GLOBALS['FieldHelp'] = '<em>(' . $help . ')</em>'; } if ($existingValue) { $GLOBALS['HideFileCurrentValue'] = ''; if (!$field['required']) { $GLOBALS['HideRemoveFile'] = 'display: none'; } $GLOBALS['CurrentFileName'] = $existingValue; if (isset($existingProduct['product_fields'][$field['id']]['fieldExisting'])) { $fileDirectory = 'configured_products'; } else { $fileDirectory = 'configured_products_tmp'; } $GLOBALS['CurrentFileLink'] = GetConfig('ShopPath') . '/' . GetConfig('ImageDirectory') . '/' . $fileDirectory . '/' . $existingFileName; } break; case 'checkbox': $checked = ''; if ($existingValue) { $checked = 'checked="checked"'; } $inputField = '<label><input type="checkbox" name="productFields[' . $field['id'] . ']" ' . $checked . ' value="1" /> ' . GetLang('TickToSelect') . '</label>'; break; default: $inputField = '<input type="text" name="productFields[' . $field['id'] . ']" class="Field300 ' . $requiredClass . '" value="' . $existingValue . '"/>'; } $GLOBALS['InputField'] = $inputField; $GLOBALS['ProductFields'] .= $GLOBALS['ISC_CLASS_TEMPLATE']->GetSnippet('OrderProductConfigurationField'); } } else { $GLOBALS['HideConfigurableFields'] = 'display: none'; } if ($productClass->GetEventDateRequired() == 1) { $this->LoadEventDate($productClass, $existingProduct); } else { $GLOBALS['EventDate'] = ''; $GLOBALS['HideEventDate'] = 'display : none;'; } echo $GLOBALS['ISC_CLASS_TEMPLATE']->GetSnippet('OrderProductConfiguration'); exit; }