abdumalik LiteCart Fan De Sweden Miembro desde oct. 2021 abdumalik 11 dic. 2021 05:23 Hi When I opened product featured status is being 0 (no) when I saved it it is being 1 (yes). No matter what I selected. what is this reason, why ? you can see the problem in this video. Thanks 2021-12-11 09-20-01.mkv
tim Founder De Sweden Miembro desde may. 2013 tim 11 dic. 2021 16:47 Featured products doesn't have that feature. This is one of your add-ons doing it, or you did it yourself.
abdumalik LiteCart Fan De Sweden Miembro desde oct. 2021 abdumalik 11 dic. 2021 18:41 I added that toggle on image. [b]here is half of codes.[/b] $featuredlist = []; $query = database::query( "select value from ". DB_TABLE_PREFIX ."settings where `key` = 'featured_products';" ); while ($row = database::fetch($query)) { $featuredlist['featured_products'] = $row['value']; } $featuredlist['featured_products'] = explode(',', $featuredlist['featured_products']); // print_r($featuredlist['featured_products']);die; if(isset($_GET['product_id'])) { // featured status if(in_array($_GET['product_id'], $featuredlist['featured_products'])) { $featured_status = '1'; echo $featured_status; } else { $featured_status = '0'; echo $featured_status; } } switch (isset($_POST['featured_products'])) { case '1': // if the product exist or not if(in_array($_GET['product_id'], $featuredlist['featured_products'])) { // print_r($featuredlist['featured_products']);die; } else { // adding new product to featured list array_push($featuredlist['featured_products'], $_GET['product_id']); database::query( "update ". DB_TABLE_PREFIX ."settings set `value` = '". database::input(implode(',', $featuredlist['featured_products'])) ."' where `key` = 'featured_products' limit 1;" ); } break; case '0': if(in_array($_GET['product_id'], $featuredlist['featured_products'])) { $found = array_search($_GET['product_id'], $featuredlist['featured_products']); echo $found; unset($featuredlist['featured_products'][$found]); // print_r($featuredlist['featured_products']);die; database::query( "update ". DB_TABLE_PREFIX ."settings set `value` = '". database::input(implode(',', $featuredlist['featured_products'])) ."' where `key` = 'featured_products' limit 1;" ); } else { // adding new product to featured list // array_push($featuredlist['featured_products'], $_GET['product_id']); } break; default: echo 'nothing'; } //// ended here featured code if (!empty($_GET['product_id'])) { $product = new ent_product($_GET['product_id']); } else { $product = new ent_product(); } if (empty($_POST)) { foreach ($product->data as $key => $value) { $_POST[$key] = $value; } $_POST['keywords'] = implode(',', $_POST['keywords']); if (empty($product->data['id']) && isset($_GET['category_id'])) { $_POST['categories'][] = $_GET['category_id']; } } document::$snippets['title'][] = !empty($product->data['id']) ? language::translate('title_edit_product', 'Edit Product') . ': '. $product->data['name'][language::$selected['code']] : language::translate('title_add_new_product', 'Add New Product'); breadcrumbs::add(language::translate('title_catalog', 'Catalog'), document::link(WS_DIR_ADMIN, ['doc' => 'catalog'], ['app'])); breadcrumbs::add(!empty($product->data['id']) ? language::translate('title_edit_product', 'Edit Product') . ': '. $product->data['name'][language::$selected['code']] : language::translate('title_add_new_product', 'Add New Product')); if (isset($_POST['save'])) { try { if (empty($_POST['categories'])) $_POST['categories'] = []; if (empty($_POST['images'])) $_POST['images'] = []; if (empty($_POST['attributes'])) $_POST['attributes'] = []; if (empty($_POST['campaigns'])) $_POST['campaigns'] = []; if (empty($_POST['options'])) $_POST['options'] = []; if (empty($_POST['options_stock'])) $_POST['options_stock'] = []; if (!empty($_POST['code']) && database::num_rows(database::query("select id from ". DB_TABLE_PREFIX ."products where id != '". (int)$product->data['id'] ."' and code = '". database::input($_POST['code']) ."' limit 1;"))) throw new Exception(language::translate('error_code_database_conflict', 'Another entry with the given code already exists in the database')); if (!empty($_POST['sku']) && database::num_rows(database::query("select id from ". DB_TABLE_PREFIX ."products where id != '". (int)$product->data['id'] ."' and sku = '". database::input($_POST['sku']) ."' limit 1;"))) throw new Exception(language::translate('error_sku_database_conflict', 'Another entry with the given SKU already exists in the database')); if (!empty($_POST['mpn']) && database::num_rows(database::query("select id from ". DB_TABLE_PREFIX ."products where id != '". (int)$product->data['id'] ."' and mpn = '". database::input($_POST['mpn']) ."' limit 1;"))) throw new Exception(language::translate('error_mpn_database_conflict', 'Another entry with the given MPN already exists in the database')); if (!empty($_POST['gtin']) && database::num_rows(database::query("select id from ". DB_TABLE_PREFIX ."products where id != '". (int)$product->data['id'] ."' and gtin = '". database::input($_POST['gtin']) ."' limit 1;"))) throw new Exception(language::translate('error_gtin_database_conflict', 'Another entry with the given GTIN already exists in the database')); $_POST['keywords'] = preg_split('#\s*,\s*#', $_POST['keywords'], -1, PREG_SPLIT_NO_EMPTY); $fields = [ 'status', 'manufacturer_id', 'artist_id', 'supplier_id', 'delivery_status_id', 'sold_out_status_id', 'default_category_id', 'categories', 'attributes', 'keywords', 'date_valid_from', 'date_valid_to', 'quantity', 'quantity_adjustment', 'quantity_min', 'quantity_max', 'quantity_step', 'quantity_unit_id', 'purchase_price', 'purchase_price_currency_code', 'recommended_price', 'prices', 'campaigns', 'tax_class_id', 'code', 'sku', 'mpn', 'gtin', 'taric', 'dim_x', 'dim_y', 'dim_z', 'dim_class', 'weight', 'weight_class', 'name', 'short_description', 'description', 'technical_data', 'head_title', 'meta_description', 'images', 'options', 'options_stock', 'video' ]; foreach ($fields as $field) { if (isset($_POST[$field])) $product->data[$field] = $_POST[$field]; } if (!empty($_FILES['new_images']['tmp_name'])) { foreach (array_keys($_FILES['new_images']['tmp_name']) as $key) { $product->add_image($_FILES['new_images']['tmp_name'][$key]); } } /* msc for video */ if(!isset($_POST['video'])){ $product->remove_video(); } /* msc for video */ if(isset($_POST['new_video']) && is_array($_POST['new_video'])){ foreach($_POST['new_video'] as $video_code){ $product->add_video($video_code); } } $product->save(); notices::add('success', language::translate('success_changes_saved', 'Changes saved')); header('Location: '. document::link(WS_DIR_ADMIN, ['app' => $_GET['app'], 'doc' => 'catalog', 'category_id' => $_POST['categories'][0]])); exit; } catch (Exception $e) { notices::add('errors', $e->getMessage()); } } if (isset($_POST['delete'])) { try { if (empty($product->data['id'])) throw new Exception(language::translate('error_must_provide_product', 'You must provide a product')); $product->delete(); notices::add('success', language::translate('success_changes_saved', 'Changes saved')); header('Location: '. document::link(WS_DIR_ADMIN, ['app' => $_GET['app'], 'doc' => 'catalog', 'category_id' => $_POST['categories'][0]])); exit; } catch (Exception $e) { notices::add('errors', $e->getMessage()); } } list($product_image_width, $product_image_height) = functions::image_scale_by_width(320, settings::get('product_image_ratio')); $option_sort_options = [ [language::translate('title_list_order', 'List Order'), 'priority'], [language::translate('title_alphabetical', 'Alphabetical'), 'alphabetical'], ]; functions::draw_lightbox(); ?> <style> #categories { max-height: 310px; overflow-y: auto; overflow-x: hidden; transition: all 200ms linear; } #categories:hover { width: 150%; z-index: 999; } #categories label { white-space: nowrap; } #images .thumbnail { margin: 0; } #images .image { overflow: hidden; } #images .thumbnail { margin-inline-end: 15px; } #images img { max-width: 50px; max-height: 50px; } #images .actions { text-align: end; padding: 0.25em 0; } </style> <div class="panel panel-app"> <div class="panel-heading"> <?php echo $app_icon; ?> <?php echo !empty($product->data['id']) ? language::translate('title_edit_product', 'Edit Product') . ': '. $product->data['name'][language::$selected['code']] : language::translate('title_add_new_product', 'Add New Product'); ?> </div> <ul class="nav nav-tabs"> <li class="active"><a data-toggle="tab" href="#tab-general"><?php echo language::translate('title_general', 'General'); ?></a></li> <li><a data-toggle="tab" href="#tab-information"><?php echo language::translate('title_information', 'Information'); ?></a></li> <li><a data-toggle="tab" href="#tab-attributes"><?php echo language::translate('title_attributes', 'Attributes'); ?></a></li> <li><a data-toggle="tab" href="#tab-prices"><?php echo language::translate('title_prices', 'Prices'); ?></a></li> <li><a data-toggle="tab" href="#tab-options"><?php echo language::translate('title_options', 'Options'); ?></a></li> <li><a data-toggle="tab" href="#tab-stock"><?php echo language::translate('title_stock', 'Stock'); ?></a></li> </ul> <div class="panel-body"> <?php echo functions::form_draw_form_begin('product_form', 'post', false, true); ?> <div class="tab-content"> <div id="tab-general" class="tab-pane active" style="max-width: 960px;"> <div class="row"> <div class="col-md-4"> <div class="form-group"> <label><?php echo language::translate('title_status', 'Status'); ?></label> <?php echo functions::form_draw_toggle('status', isset($_POST['status']) ? $_POST['status'] : '0', 'e/d'); ?> </div> /// this is also featured code <div class="form-group"> <label><?php echo language::translate('title_featured', 'Featured'); ?></label> <?php echo functions::form_draw_toggle('featured_products', isset($_POST['featured_products']) ? $_POST['featured_products'] : '0', 'y/n'); ?> </div> //// ended <div class="form-group"> <label><?php echo language::translate('title_categories', 'Categories'); ?></label> <?php echo functions::form_draw_categories_list('categories[]', true, 'style="max-height: 480px;"'); ?> </div> <div class="form-group"> <label><?php echo language::translate('title_default_category', 'Default Category'); ?></label> <?php echo functions::form_draw_select_field('default_category_id', [], true); ?> </div> <div class="form-group"> <label><?php echo language::translate('title_date_valid_from', 'Date Valid From'); ?></label> <?php echo functions::form_draw_date_field('date_valid_from', true); ?> </div> <div class="form-group"> <label><?php echo language::translate('title_date_valid_to', 'Date Valid To'); ?></label> <?php echo functions::form_draw_date_field('date_valid_to', true); ?> </div>``` [b]What do you suggest to solve it ? [/b]
tim Founder De Sweden Miembro desde may. 2013 tim 11 dic. 2021 18:49 Seems yoou are missing to populate the reinserted POST parameter? https://github.com/litecart/litecart/blob/17cc70d20a80887328d59847c7a47eb320b64532/public_html/admin/catalog.app/edit_product.inc.php#L10-L12
abdumalik LiteCart Fan De Sweden Miembro desde oct. 2021 abdumalik 11 dic. 2021 18:54 when I printed that $product it showed me twice of one id. look at the image
abdumalik LiteCart Fan De Sweden Miembro desde oct. 2021 abdumalik 19 dic. 2021 23:45 @tim Heloooooo ?
tim Founder De Sweden Miembro desde may. 2013 tim 20 dic. 2021 00:20 Show me the code where you are reinserting featured products into the post parameters. I don't see it.
tim Founder De Sweden Miembro desde may. 2013 tim 20 dic. 2021 00:56 Or try this code instead of yours. <operation error="log"> <search position="after" index="1"><![CDATA[ 'status', ]]></search> <add><![CDATA[ 'featured', ]]></add> </operation> <operation error="log"> <search position="after" offset="1"><![CDATA[ <?php echo functions::form_draw_toggle('status', isset($_POST['status']) ? $_POST['status'] : '0', 'e/d'); ?> ]]></search> <add><![CDATA[ <div class="form-group"> <label><?php echo language::translate('title_featured', 'Featured'); ?></label> <?php echo functions::form_draw_toggle('featured', true, 'y/n'); ?> </div> ]]></add> </operation> </file> <file name="includes/entities/ent_product.inc.php"> <operation error="log"> <search position="after" index="1"><![CDATA[ $this->data['options_stock'] = []; ]]></search> <add><![CDATA[ $this->data['featured'] = false; ]]></add> </operation> <operation error="log"> <search position="after" offset="1"><![CDATA[ $this->data['images'][$image['id']] = $image; ]]></search> <add><![CDATA[ $this->data['featured'] = in_array($this->data['id'], preg_split('#\s*,\s*#', settings::get('featured_products'), -1, PREG_SPLIT_NO_EMPTY)); ]]></add> </operation> <operation error="log"> <search position="after" offset="2"><![CDATA[ unset($this->data['quantity_adjustment']); ]]></search> <add><![CDATA[ if ($this->data['featured']) { database::query( "update ". DB_TABLE_PREFIX ."settings set `value` = '". database::input(implode(',', array_merge(preg_split('#\s*,\s*#', settings::get('featured_products'), -1, PREG_SPLIT_NO_EMPTY), [$this->data['id']]))) ."' where `key` = 'featured_products' limit 1;" ); } else { database::query( "update ". DB_TABLE_PREFIX ."settings set `value` = '". database::input(implode(',', array_diff(preg_split('#\s*,\s*#', settings::get('featured_products'), -1, PREG_SPLIT_NO_EMPTY), [$this->data['id']]))) ."' where `key` = 'featured_products' limit 1;" ); } ]]></add> </operation> </file>
abdumalik LiteCart Fan De Sweden Miembro desde oct. 2021 abdumalik 20 dic. 2021 21:49 Look this code I have commented that one. $featuredlist = []; $query = database::query( "select value from ". DB_TABLE_PREFIX ."settings where `key` = 'featured_products';" ); while ($row = database::fetch($query)) { $featuredlist['featured_products'] = $row['value']; } $featuredlist['featured_products'] = explode(',', $featuredlist['featured_products']); // print_r($featuredlist['featured_products']);die; if(isset($_GET['product_id'])) { // featured status if(in_array($_GET['product_id'], $featuredlist['featured_products'])) { $featured_status = '1'; echo $featured_status; } else { $featured_status = '0'; echo $featured_status; } } switch (isset($_POST['featured_products'])) { case '1': // if the product exist or not if(in_array($_GET['product_id'], $featuredlist['featured_products'])) { // print_r($featuredlist['featured_products']);die; } else { // adding new product to featured list array_push($featuredlist['featured_products'], $_GET['product_id']); database::query( "update ". DB_TABLE_PREFIX ."settings set `value` = '". database::input(implode(',', $featuredlist['featured_products'])) ."' where `key` = 'featured_products' limit 1;" ); } break; case '0': if(in_array($_GET['product_id'], $featuredlist['featured_products'])) { $found = array_search($_GET['product_id'], $featuredlist['featured_products']); echo $found; unset($featuredlist['featured_products'][$found]); // print_r($featuredlist['featured_products']);die; database::query( "update ". DB_TABLE_PREFIX ."settings set `value` = '". database::input(implode(',', $featuredlist['featured_products'])) ."' where `key` = 'featured_products' limit 1;" ); } else { // adding new product to featured list // array_push($featuredlist['featured_products'], $_GET['product_id']); } break; default: echo 'nothing'; } //// ended here featured code if (!empty($_GET['product_id'])) { $product = new ent_product($_GET['product_id']); } else { $product = new ent_product(); } if (empty($_POST)) { foreach ($product->data as $key => $value) { $_POST[$key] = $value; } $_POST['keywords'] = implode(',', $_POST['keywords']); if (empty($product->data['id']) && isset($_GET['category_id'])) { $_POST['categories'][] = $_GET['category_id']; } } document::$snippets['title'][] = !empty($product->data['id']) ? language::translate('title_edit_product', 'Edit Product') . ': '. $product->data['name'][language::$selected['code']] : language::translate('title_add_new_product', 'Add New Product'); breadcrumbs::add(language::translate('title_catalog', 'Catalog'), document::link(WS_DIR_ADMIN, ['doc' => 'catalog'], ['app'])); breadcrumbs::add(!empty($product->data['id']) ? language::translate('title_edit_product', 'Edit Product') . ': '. $product->data['name'][language::$selected['code']] : language::translate('title_add_new_product', 'Add New Product')); if (isset($_POST['save'])) { try { if (empty($_POST['categories'])) $_POST['categories'] = []; if (empty($_POST['images'])) $_POST['images'] = []; if (empty($_POST['attributes'])) $_POST['attributes'] = []; if (empty($_POST['campaigns'])) $_POST['campaigns'] = []; if (empty($_POST['options'])) $_POST['options'] = []; if (empty($_POST['options_stock'])) $_POST['options_stock'] = []; if (!empty($_POST['code']) && database::num_rows(database::query("select id from ". DB_TABLE_PREFIX ."products where id != '". (int)$product->data['id'] ."' and code = '". database::input($_POST['code']) ."' limit 1;"))) throw new Exception(language::translate('error_code_database_conflict', 'Another entry with the given code already exists in the database')); if (!empty($_POST['sku']) && database::num_rows(database::query("select id from ". DB_TABLE_PREFIX ."products where id != '". (int)$product->data['id'] ."' and sku = '". database::input($_POST['sku']) ."' limit 1;"))) throw new Exception(language::translate('error_sku_database_conflict', 'Another entry with the given SKU already exists in the database')); if (!empty($_POST['mpn']) && database::num_rows(database::query("select id from ". DB_TABLE_PREFIX ."products where id != '". (int)$product->data['id'] ."' and mpn = '". database::input($_POST['mpn']) ."' limit 1;"))) throw new Exception(language::translate('error_mpn_database_conflict', 'Another entry with the given MPN already exists in the database')); if (!empty($_POST['gtin']) && database::num_rows(database::query("select id from ". DB_TABLE_PREFIX ."products where id != '". (int)$product->data['id'] ."' and gtin = '". database::input($_POST['gtin']) ."' limit 1;"))) throw new Exception(language::translate('error_gtin_database_conflict', 'Another entry with the given GTIN already exists in the database')); $_POST['keywords'] = preg_split('#\s*,\s*#', $_POST['keywords'], -1, PREG_SPLIT_NO_EMPTY); $fields = [ 'status', 'manufacturer_id', 'artist_id', 'supplier_id', 'delivery_status_id', 'sold_out_status_id', 'default_category_id', 'categories', 'attributes', 'keywords', 'date_valid_from', 'date_valid_to', 'quantity', 'quantity_adjustment', 'quantity_min', 'quantity_max', 'quantity_step', 'quantity_unit_id', 'purchase_price', 'purchase_price_currency_code', 'recommended_price', 'prices', 'campaigns', 'tax_class_id', 'code', 'sku', 'mpn', 'gtin', 'taric', 'dim_x', 'dim_y', 'dim_z', 'dim_class', 'weight', 'weight_class', 'name', 'short_description', 'description', 'technical_data', 'head_title', 'meta_description', 'images', 'options', 'options_stock', 'video' ]; foreach ($fields as $field) { if (isset($_POST[$field])) $product->data[$field] = $_POST[$field]; } if (!empty($_FILES['new_images']['tmp_name'])) { foreach (array_keys($_FILES['new_images']['tmp_name']) as $key) { $product->add_image($_FILES['new_images']['tmp_name'][$key]); } } /* msc for video */ if(!isset($_POST['video'])){ $product->remove_video(); } /* msc for video */ if(isset($_POST['new_video']) && is_array($_POST['new_video'])){ foreach($_POST['new_video'] as $video_code){ $product->add_video($video_code); } } $product->save(); notices::add('success', language::translate('success_changes_saved', 'Changes saved')); header('Location: '. document::link(WS_DIR_ADMIN, ['app' => $_GET['app'], 'doc' => 'catalog', 'category_id' => $_POST['categories'][0]])); exit; } catch (Exception $e) { notices::add('errors', $e->getMessage()); } } if (isset($_POST['delete'])) { try { if (empty($product->data['id'])) throw new Exception(language::translate('error_must_provide_product', 'You must provide a product')); $product->delete(); notices::add('success', language::translate('success_changes_saved', 'Changes saved')); header('Location: '. document::link(WS_DIR_ADMIN, ['app' => $_GET['app'], 'doc' => 'catalog', 'category_id' => $_POST['categories'][0]])); exit; } catch (Exception $e) { notices::add('errors', $e->getMessage()); } } list($product_image_width, $product_image_height) = functions::image_scale_by_width(320, settings::get('product_image_ratio')); $option_sort_options = [ [language::translate('title_list_order', 'List Order'), 'priority'], [language::translate('title_alphabetical', 'Alphabetical'), 'alphabetical'], ]; functions::draw_lightbox(); ?> <style> #categories { max-height: 310px; overflow-y: auto; overflow-x: hidden; transition: all 200ms linear; } #categories:hover { width: 150%; z-index: 999; } #categories label { white-space: nowrap; } #images .thumbnail { margin: 0; } #images .image { overflow: hidden; } #images .thumbnail { margin-inline-end: 15px; } #images img { max-width: 50px; max-height: 50px; } #images .actions { text-align: end; padding: 0.25em 0; } </style> <div class="panel panel-app"> <div class="panel-heading"> <?php echo $app_icon; ?> <?php echo !empty($product->data['id']) ? language::translate('title_edit_product', 'Edit Product') . ': '. $product->data['name'][language::$selected['code']] : language::translate('title_add_new_product', 'Add New Product'); ?> </div> <ul class="nav nav-tabs"> <li class="active"><a data-toggle="tab" href="#tab-general"><?php echo language::translate('title_general', 'General'); ?></a></li> <li><a data-toggle="tab" href="#tab-information"><?php echo language::translate('title_information', 'Information'); ?></a></li> <li><a data-toggle="tab" href="#tab-attributes"><?php echo language::translate('title_attributes', 'Attributes'); ?></a></li> <li><a data-toggle="tab" href="#tab-prices"><?php echo language::translate('title_prices', 'Prices'); ?></a></li> <li><a data-toggle="tab" href="#tab-options"><?php echo language::translate('title_options', 'Options'); ?></a></li> <li><a data-toggle="tab" href="#tab-stock"><?php echo language::translate('title_stock', 'Stock'); ?></a></li> </ul> <div class="panel-body"> <?php echo functions::form_draw_form_begin('product_form', 'post', false, true); ?> <div class="tab-content"> <div id="tab-general" class="tab-pane active" style="max-width: 960px;"> <div class="row"> <div class="col-md-4"> <div class="form-group"> <label><?php echo language::translate('title_status', 'Status'); ?></label> <?php echo functions::form_draw_toggle('status', isset($_POST['status']) ? $_POST['status'] : '0', 'e/d'); ?> </div> /// this is also featured code <div class="form-group"> <label><?php echo language::translate('title_featured', 'Featured'); ?></label> <?php echo functions::form_draw_toggle('featured_products', isset($_POST['featured_products']) ? $_POST['featured_products'] : '0', 'y/n'); ?> </div> //// ended <div class="form-group"> <label><?php echo language::translate('title_categories', 'Categories'); ?></label> <?php echo functions::form_draw_categories_list('categories[]', true, 'style="max-height: 480px;"'); ?> </div> <div class="form-group"> <label><?php echo language::translate('title_default_category', 'Default Category'); ?></label> <?php echo functions::form_draw_select_field('default_category_id', [], true); ?> </div> <div class="form-group"> <label><?php echo language::translate('title_date_valid_from', 'Date Valid From'); ?></label> <?php echo functions::form_draw_date_field('date_valid_from', true); ?> </div> <div class="form-group"> <label><?php echo language::translate('title_date_valid_to', 'Date Valid To'); ?></label> <?php echo functions::form_draw_date_field('date_valid_to', true); ?> </div> What do you suggest to solve it ?```
tim Founder De Sweden Miembro desde may. 2013 tim 21 dic. 2021 00:34 Just try my mod. I don't have the time to troubleshoot your code for you right now.