function cw_group_edit_update_category($ge_id, $cat, $fields, $data)
{
    if (!$ge_id || !$cat || !count($fields)) {
        return;
    }
    global $tables, $config, $edited_language;
    $query_fields = cw_query_column("desc {$tables['categories']}", 'Field');
    $to_update = array_intersect($query_fields, array_keys($fields));
    # kornev, add attributes to update
    if ($edited_language != $config['default_admin_language']) {
        cw_unset($to_update, 'category', 'description');
    }
    if ($to_update) {
        cw_group_edit_copy($ge_id, 'categories', 'category_id', $cat, $to_update);
    }
    if ($fields['membership_ids']) {
        while ($id = cw_group_edit_each($ge_id, 1, $cat)) {
            cw_membership_update('categories', $id, $data['membership_ids'], 'category_id');
        }
    }
    if ($fields['avail']) {
        while ($id = cw_group_edit_each($ge_id, 1, $cat)) {
            cw_category_update_status($id, $data['avail']);
        }
    }
    if ($fields['category'] || $fields['description']) {
        $to_update = array_intersect(array('category', 'description'), array_keys($fields));
        cw_group_edit_copy($ge_id, 'categories_lng', 'category_id', $cat, $to_update, "code='{$edited_language}'");
    }
    if ($fields['image']) {
        cw_group_edit_copy($ge_id, 'categories_images_thumb', 'id', $cat);
    }
    cw_attributes_group_update($ge_id, $cat, 'C', $fields);
}
Exemplo n.º 2
0
        } else {
            $membership_ids_where = "IN ('" . implode("','", $membership_ids) . "') ";
        }
        if (cw_query_first_cell("SELECT COUNT(*) FROM {$tables['tax_rates']} LEFT JOIN {$tables['tax_rate_memberships']} ON {$tables['tax_rates']}.rate_id = {$tables['tax_rate_memberships']}.rate_id WHERE {$tables['tax_rates']}.tax_id = '{$tax_id}' AND {$tables['tax_rates']}.rate_id != '{$rate_id}' AND {$tables['tax_rates']}.zone_id = '{$zone_id}' AND {$tables['tax_rate_memberships']}.membership_id " . $membership_ids_where) == 0) {
            $rate_formula = preg_replace("/^=/", "", $rate_formula);
            $query_data = array("zone_id" => $zone_id, "formula" => $rate_formula, "rate_value" => $rate_value, "rate_type" => $rate_type);
            if (!empty($rate_id)) {
                cw_array2update("tax_rates", $query_data, "rate_id='{$rate_id}' ");
                db_query("DELETE FROM {$tables['tax_rate_memberships']} WHERE rate_id='{$rate_id}'");
                $top_message['content'] = cw_get_langvar_by_name("msg_tax_rate_upd");
            } else {
                $query_data['tax_id'] = $tax_id;
                $rate_id = cw_array2insert("tax_rates", $query_data);
                $top_message['content'] = cw_get_langvar_by_name("msg_tax_rate_add");
            }
            cw_membership_update("tax_rate", $rate_id, $membership_ids, "rate_id");
        } else {
            $top_message['content'] = cw_get_langvar_by_name("msg_err_tax_rate_add");
            $top_message['type'] = "E";
        }
        $top_message['anchor'] = "rates";
        $redirect_to = "&tax_id={$tax_id}";
    }
    cw_header_location('index.php?target=' . $target . $redirect_to);
}
if ($mode == "add" || !empty($tax_id)) {
    $location[] = array(cw_get_langvar_by_name('lbl_taxes'), 'index.php?target=' . $target);
    $location[] = array(cw_get_langvar_by_name('lbl_tax_details'), '');
    if (!empty($tax_id)) {
        $tax_details = cw_query_first("SELECT * FROM {$tables['taxes']} WHERE tax_id='{$tax_id}'");
        $tax_details['tax_display_name'] = cw_get_languages_alt('tax_' . $tax_id);
     }
     cw_header_location("index.php?target={$target}&mode={$mode}&cat={$cat}&ge_id={$ge_id}");
 }
 if ($mode == 'add') {
     $cat = cw_array2insert('categories', array('parent_id' => $cat));
     cw_category_update_path($cat);
 }
 $update_fields = array('category', 'description', 'featured', 'order_by', 'short_list');
 array_push($update_fields, 'meta_descr', 'meta_keywords');
 if ($edited_language != $config['default_admin_language']) {
     cw_unset($update_fields, 'category', 'description');
 }
 cw_array2update('categories', $category_update, "category_id='{$cat}'", $update_fields);
 cw_category_update_status($cat, $category_update['status']);
 cw_category_update_path($cat);
 cw_membership_update('categories', $cat, $category_update['membership_ids'], 'category_id');
 $category_lng = array();
 $category_lng['code'] = $edited_language;
 $category_lng['category_id'] = $cat;
 $category_lng['category'] = $category_update['category'];
 $category_lng['description'] = $category_update['description'];
 cw_array2insert('categories_lng', $category_lng, true, array('code', 'category_id', 'category', 'description'));
 if (cw_image_check_posted($file_upload_data['categories_images_thumb'])) {
     cw_image_save($file_upload_data['categories_images_thumb']);
 }
 $parent_categories = cw_category_get_path($cat);
 if (is_array($parent_categories)) {
     cw_recalc_subcat_count($parent_categories);
 }
 cw_func_call('cw_items_attribute_classes_save', array('item_id' => $cat, 'attribute_class_ids' => $category_update['attribute_class_ids'], 'item_type' => 'C'));
 if ($replicate_attribute_classes == "Y") {
                    if ($quote['quote']) {
                        $quote_id = cw_array2insert('payment_quotes', array('quote' => $quote['quote'], 'payment_id' => $payment_id));
                    } else {
                        continue;
                    }
                }
                cw_array2update('payment_quotes', $quote, "quote_id='{$quote_id}'", array('quote', 'inc_payment_id', 'exp_days', 'start_exp_days', 'fixed_days', 'is_net', 'is_vat', 'is_fee', 'commission'));
            }
            $check_fields = array('is_net', 'is_vat', 'is_fee', 'commission');
            foreach ($check_fields as $field) {
                if (cw_query_first_cell("select sum({$field}) from {$tables['payment_quotes']} where payment_id='{$payment_id}'") != 100) {
                    $top_message['content'] .= cw_get_langvar_by_name('err_payment_quotes_' . $field) . '<br />';
                }
            }
        }
        cw_membership_update('payment_methods', $payment_id, $posted_data['membership_ids'], 'payment_id');
        db_query("delete from {$tables['payments_shippings']} where payment_id='{$payment_id}'");
        if (is_array($posted_data['shippings_ids'])) {
            foreach ($posted_data['shippings_ids'] as $val) {
                cw_array2insert('payments_shippings', array('payment_id' => $payment_id, 'shipping_id' => $val), true);
            }
        }
        cw_call('cw_attributes_save', array('item_id' => $payment_id, 'item_type' => 'G', 'attributes' => $attributes, 'language' => $edited_language));
    } else {
        $top_message = array('content' => $fillerror, 'type' => 'E');
        $payment_modified_data = $posted_data;
    }
    cw_header_location("index.php?target={$target}&mode={$mode}&payment_id={$payment_id}&js_tab={$js_tab}");
}
$location[] = array(cw_get_langvar_by_name('lbl_payment_methods'), '');
if (isset($payment_id)) {
 if (!$addons['warehouse']) {
     $query_fields[] = 'avail';
 }
 if (!$is_variant) {
     $query_fields[] = 'weight';
 }
 cw_array2update('products', $product_data, "product_id = '{$product_id}'", $query_fields);
 // TODO: move to addon
 if ($addons['faq']) {
     cw_load('faq');
     cw_faq_create_product($product_id);
 }
 if (AREA_TYPE == 'A') {
     cw_insert_product_to_sections($product_id, $ins_sections);
 }
 cw_membership_update('products', $product_id, $product_data['membership_ids'], 'product_id');
 if ($fields['membership_ids']) {
     cw_group_edit_copy_memberships($product_data['membership_ids']);
 }
 if (!empty($fields)) {
     $do_not_update = array('price', 'thumbnail', 'product_image', 'category_id', 'category_ids', 'membership_ids');
     $to_update = array_intersect($query_fields, array_keys($fields));
     $to_update = array_intersect($to_update, array_diff($to_update, $do_not_update));
     if (count($to_update)) {
         cw_group_edit_copy($ge_id, 'products', 'product_id', $product_id, $to_update);
     }
 }
 if ($config['Appearance']['categories_in_products'] == '1') {
     cw_recalc_subcat_count($category_id);
     if (is_array($old_product_categories)) {
         $category_ids = cw_array_merge($old_product_categories, $category_ids);