/** * @ describe the function UpdateCustomAttribute->. */ function onAction() { $EditCustomAttributeForm = array(); $EditCustomAttributeForm = $_POST; $EditCustomAttributeForm["ErrorsArray"] = array(); // check "Attribute Name" if (isEmptyKey('name', $EditCustomAttributeForm)) { // a required attribute $EditCustomAttributeForm["ErrorsArray"]["name"] = new ActionMessage("ADDCUSTOM_003"); } // check "Attribute Description" if (isEmptyKey('descr', $EditCustomAttributeForm)) { // a required attribute $EditCustomAttributeForm["ErrorsArray"]["descr"] = new ActionMessage("ADDCUSTOM_004"); } if (empty($EditCustomAttributeForm["ErrorsArray"])) { $EditCustomAttributeForm['input_type_values'] = isset($EditCustomAttributeForm['input_type_values']) ? $EditCustomAttributeForm['input_type_values'] : array(); if (!empty($EditCustomAttributeForm['input_type_values'])) { foreach ($EditCustomAttributeForm['input_type_values'] as $key => $item) { if (empty($item)) { unset($EditCustomAttributeForm['input_type_values'][$key]); } } } $custom_attributes = modApiFunc('Catalog', 'getTempCustomAttributes', $EditCustomAttributeForm['form_id']); $orig_attr = $custom_attributes[$EditCustomAttributeForm['view_tag']]; $attr = array('id' => $orig_attr['id'], 'pta_id' => $orig_attr['pta_id'], 'name' => prepareHTMLDisplay($EditCustomAttributeForm['name']), 'descr' => prepareHTMLDisplay($EditCustomAttributeForm['descr']), 'size' => $orig_attr['size'], 'min' => $orig_attr['min'], 'max' => $orig_attr['max'], 'view_tag' => $orig_attr['view_tag'], 'group' => $orig_attr['group'], 'required' => $orig_attr['required'], 'visible' => $orig_attr['visible'], 'default' => $orig_attr['default'], 'sort' => $orig_attr['sort'], 'type' => $orig_attr['type'], 'patt' => $orig_attr['patt'], 'patt_type' => $orig_attr['patt_type'], 'input_type_id' => $orig_attr['input_type_id'], 'input_type_name' => $orig_attr['input_type_name'], 'unit_type_value' => $orig_attr['unit_type_value'], 'vanishing' => $orig_attr['vanishing'], 'input_type_values' => $EditCustomAttributeForm['input_type_values']); modApiFunc('Catalog', 'updateTempCustomAttribute', $EditCustomAttributeForm['form_id'], $attr); $EditCustomAttributeForm["close"] = true; } modApiFunc('Session', 'set', 'EditCustomAttributeForm', $EditCustomAttributeForm); }
function onAction() { $AddCustomAttributeForm = array(); $AddCustomAttributeForm = $_POST; $AddCustomAttributeForm["ErrorsArray"] = array(); // convert to the universal user interface. $AddCustomAttributeForm['view_tag'] = _ml_ucfirst(_ml_strtolower($AddCustomAttributeForm['view_tag'])); // check "Attribute Tag" if (isEmptyKey('view_tag', $AddCustomAttributeForm)) { // a required attribute $AddCustomAttributeForm["ErrorsArray"]["view_tag"] = new ActionMessage("ADDCUSTOM_001"); } if (preg_match("/[^a-zA-Z0-9_]+/", $AddCustomAttributeForm['view_tag'])) { // the attribute should require the rules of naming the PHP variables $AddCustomAttributeForm["ErrorsArray"]["view_tag"] = new ActionMessage("ADDCUSTOM_002"); } if ($AddCustomAttributeForm['product_type_id'] != "") { // there should be no copies of real custom attributes... $product_type = modApiFunc('Catalog', 'getProductType', $AddCustomAttributeForm['product_type_id']); foreach ($product_type['attr'] as $key => $value) { if (_ml_strtolower($AddCustomAttributeForm['view_tag']) === _ml_strtolower($key)) { $AddCustomAttributeForm["ErrorsArray"]["view_tag"] = new ActionMessage(array("ADDCUSTOM_005", 'Product' . $AddCustomAttributeForm['view_tag'] . 'Custom')); break; } } // ... custom $custom_attributes = modApiFunc('Catalog', 'getTempCustomAttributes', $AddCustomAttributeForm['form_id']); if (is_array($custom_attributes) && array_key_exists($AddCustomAttributeForm['view_tag'], $custom_attributes)) { $AddCustomAttributeForm["ErrorsArray"]["view_tag"] = new ActionMessage(array("ADDCUSTOM_005", 'Product' . $AddCustomAttributeForm['view_tag'] . 'Custom')); } } else { // there should be no copies $custom_attributes = modApiFunc('Catalog', 'getTempCustomAttributes', $AddCustomAttributeForm['form_id']); if (is_array($custom_attributes) && array_key_exists($AddCustomAttributeForm['view_tag'], $custom_attributes)) { $AddCustomAttributeForm["ErrorsArray"]["view_tag"] = new ActionMessage(array("ADDCUSTOM_005", 'Product' . $AddCustomAttributeForm['view_tag'] . 'Custom')); } } // check "Attribute Tag" if (isEmptyKey('name', $AddCustomAttributeForm)) { // // a required attribute $AddCustomAttributeForm["ErrorsArray"]["name"] = new ActionMessage("ADDCUSTOM_003"); } // check "Attribute Description" if (isEmptyKey('descr', $AddCustomAttributeForm)) { // a required attribute $AddCustomAttributeForm["ErrorsArray"]["descr"] = new ActionMessage("ADDCUSTOM_004"); } if (empty($AddCustomAttributeForm["ErrorsArray"])) { $input_type_name = ""; $input_type_id = ""; switch ($AddCustomAttributeForm['type_id']) { case 1: $input_type_name = 'text'; $input_type_id = 1; break; case 2: $input_type_name = 'textarea'; $input_type_id = 2; break; case 3: $input_type_name = 'select'; $res = execQuery('SELECT_MAX_INPUT_TYPE_ID'); $input_type_id = $res[0]['max_id'] + 1; foreach ($AddCustomAttributeForm['input_type_values'] as $key => $item) { if (empty($item)) { unset($AddCustomAttributeForm['input_type_values'][$key]); } } break; default: $input_type_name = 'text'; } $AddCustomAttributeForm['input_type_values'] = isset($AddCustomAttributeForm['input_type_values']) ? $AddCustomAttributeForm['input_type_values'] : array(); $attr = array('id' => null, 'pta_id' => null, 'name' => prepareHTMLDisplay($AddCustomAttributeForm['name']), 'descr' => prepareHTMLDisplay($AddCustomAttributeForm['descr']), 'size' => 70, 'min' => 2, 'max' => 255, 'view_tag' => prepareHTMLDisplay($AddCustomAttributeForm['view_tag']), 'group' => array('id' => 6, 'name' => 'Custom Attributes', 'sort' => 6), 'required' => false, 'visible' => true, 'default' => '', 'sort' => 1, 'type' => 'custom', 'patt' => null, 'patt_type' => null, 'input_type_id' => $input_type_id, 'input_type_name' => $input_type_name, 'unit_type_value' => null, 'vanishing' => true, 'allow_html' => $input_type_id == 2 ? 1 : 0, 'input_type_values' => $AddCustomAttributeForm['input_type_values']); modApiFunc('Catalog', 'addTempCustomAttribute', $AddCustomAttributeForm['form_id'], $attr); $AddCustomAttributeForm["close"] = true; } modApiFunc('Session', 'set', 'AddCustomAttributeForm', $AddCustomAttributeForm); }
/** * @ describe the function SaveProduct->onAction. */ function onAction() { global $application; $request = $application->getInstance('Request'); $EditProductInfoForm = array(); if (modApiFunc('Session', 'is_Set', 'EditProductInfoForm')) { _fatal(array("CODE" => "CORE_050"), __CLASS__, __FUNCTION__); } $EditProductInfoForm = $_POST; $membership_vis = "-1"; // -1 means "product is visible for all customers" if (isset($EditProductInfoForm['MembershipVisibility'])) { $membership_vis = $EditProductInfoForm['MembershipVisibility']; } $EditProductInfoForm['MembershipVisibility'] = $membership_vis; $EditProductInfoForm["ViewState"]["ErrorsArray"] = array(); # force PerItemShippinfCost to 0.00 if FreeShipping is enabled if (isset($EditProductInfoForm['FreeShipping']) && $EditProductInfoForm['FreeShipping'] == "1") { $EditProductInfoForm['PerItemShippingCost'] = "0.00"; } switch ($request->getValueByKey('FormSubmitValue')) { case 'EnableEditor': modApiFunc('Session', 'set', 'ProductInfoWYSIWYGEditorEnabled', true); $this->uploadImages($EditProductInfoForm); break; case 'UploadImages': $this->uploadImages($EditProductInfoForm); break; case 'DeleteImage': $image = $EditProductInfoForm['ViewState']['LargeImage']; if (_ml_strpos(basename($image), 'tmp') === 0) { $images_dir = $application->getAppIni('PATH_IMAGES_DIR'); @unlink($images_dir . basename($image)); } $EditProductInfoForm['ViewState']['LargeImage'] = ''; break; case 'DeleteSmallImage': $image = $EditProductInfoForm['ViewState']['SmallImage']; if (_ml_strpos(basename($image), 'tmp') === 0) { $images_dir = $application->getAppIni('PATH_IMAGES_DIR'); @unlink($images_dir . basename($image)); } $EditProductInfoForm['ViewState']['SmallImage'] = ''; break; case 'UploadImagesAndSave': $nErrors = 0; $this->uploadImages($EditProductInfoForm); $product_type_id = $request->getValueByKey('TypeID'); $product_type = modApiFunc('Catalog', 'getProductType', $product_type_id); $product_id = $request->getValueByKey('ID'); $product_info = array(); foreach ($product_type['attr'] as $view_tag => $attr) { // skip invisible attributes if (!$attr['visible']) { continue; } $product_info[$view_tag] = $request->getValueByKey($view_tag); // check if it is reqiured if (isEmptyKey($view_tag, $product_info) && $attr['required']) { $EditProductInfoForm["ViewState"]["ErrorsArray"][$view_tag] = new ActionMessage(array("error.required", $attr['name'])); $nErrors++; } // validity check if (!isEmptyKey($view_tag, $product_info) && isset($attr['patt'])) { $product_info_view_tag_with_new_lines_stripped = str_replace("\n", "", $product_info[$view_tag]); if (!preg_match($attr['patt'], $product_info_view_tag_with_new_lines_stripped)) { // @ use the correct error codes. $EditProductInfoForm["ViewState"]["ErrorsArray"][$view_tag] = new ActionMessage(array('error.wrongPattern', $attr['name'], $attr['patt_type'])); $nErrors++; } } $product_info[$view_tag] = modApiFunc("Localization", "FormatStrToFloat", $product_info[$view_tag], $attr['patt_type']); $SessionPost[$view_tag] = modApiFunc("Localization", "FormatStrToFloat", $product_info[$view_tag], $attr['patt_type']); } $product_info['Name'] = $request->getValueByKey('Name'); $product_info['Name'] = $request->getValueByKey('Name'); if (!$this->isValidProdName($product_info['Name'])) { // an error message comes out if the product name is not displayed $EditProductInfoForm["ViewState"]["ErrorsArray"]['Name'] = new ActionMessage("PRDADD_004"); $nErrors++; } $nErrors = sizeof($EditProductInfoForm["ViewState"]["ErrorsArray"]); if ($nErrors == 0) { $product_info['LargeImage'] = $EditProductInfoForm['ViewState']['LargeImage']; $product_info['SmallImage'] = $EditProductInfoForm['ViewState']['SmallImage']; $membership_vis = "-1"; // -1 means "product is visible for all customers" if (isset($product_info['MembershipVisibility'])) { $membership_vis = $product_info['MembershipVisibility']; } $product_info['MembershipVisibility'] = $membership_vis; modApiFunc('Catalog', 'updateProductInfo', $product_id, $product_type_id, $product_info); //$EditProductInfoForm["ViewState"]["hasCloseScript"] = "true"; $redirect_request = new Request(); $redirect_request->setView('Catalog_EditProduct'); $redirect_request->setAction('SetCurrentProduct'); $redirect_request->setKey('prod_id', $product_id); $redirect_request->setKey('disable_url_mod', '1'); // URLModifier, GET $redirect_request->setKey('keep_editor_state', 'true'); modApiFunc('Session', 'set', 'SavedOk', 1); $application->redirect($redirect_request); modApiFunc('Session', 'set', 'mustReloadParent', 1); } break; } if (modApiFunc('Session', 'is_set', 'mustReloadParent')) { modApiFunc('Session', 'un_set', 'EditProductInfoForm'); } else { modApiFunc('Session', 'set', 'EditProductInfoForm', $EditProductInfoForm); } }