Skip to content

Commit

Permalink
#99 [RegistrationCertificate] fix: brand selection after form submit
Browse files Browse the repository at this point in the history
  • Loading branch information
Théo David committed Jan 17, 2023
1 parent 218ae71 commit 1eb0c30
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 16 deletions.
8 changes: 5 additions & 3 deletions class/actions_dolicar.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -420,12 +420,13 @@ public function printCommonFooter($parameters)
</script>
<?php
} else if ($parameters['currentcontext'] == 'registrationcertificatefrcard') {

//Filter products selector with product with "Vehicle" category
require_once __DIR__ . '/../../../categories/class/categorie.class.php';
$category = new Categorie($db);
$registration_certificate = new RegistrationCertificateFr($db);
GETPOST('id') > 0 ? $registration_certificate->fetch(GETPOST('id')) : '';

print ajax_combobox('selectd1_vehicle_brand');
$category->fetch($conf->global->DOLICAR_VEHICLE_TAG);
$objects_in_categ = $category->getObjectsInCateg('product');
$product_ids = array();
Expand All @@ -434,9 +435,8 @@ public function printCommonFooter($parameters)
$product_ids[$object_in_categ->id] = $object_in_categ->id;
}
}
$category->fetch($conf->global->DOLICAR_CAR_BRANDS_TAG);
$brands = $category->get_filles();

$brand_name = get_vehicle_brand(GETPOST('fk_product')?:$registration_certificate->fk_product);

?>
<script>
Expand All @@ -451,6 +451,8 @@ public function printCommonFooter($parameters)
let mainCategoryId = <?php echo json_encode($conf->global->DOLICAR_VEHICLE_TAG); ?>;
jQuery('#fk_product').closest('.valuefieldcreate').find('.butActionNew').attr('href',newProductHref + '&categories[]=' + mainCategoryId)

$('#d1_vehicle_brand').attr('value',<?php echo json_encode($brand_name); ?>)
$('#d1_vehicle_brand').prop("readonly", true)
</script>
<?php
}
Expand Down
24 changes: 24 additions & 0 deletions lib/dolicar_functions.lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -135,3 +135,27 @@ function dolicar_select_dictionary($htmlname, $dictionarytable, $keyfield = 'cod
dol_print_error($db);
}
}

function get_vehicle_brand($productId) {
global $conf, $db;

$product = new Product($db);
$category = new Categorie($db);
$brand_name = '';

if (!empty($productId) && $productId > 0) {
$product->fetch($productId);
$categories = $product->getCategoriesCommon('product');

if (is_array($categories) && !empty($categories)) {
foreach($categories as $categoryId) {
$category->fetch($categoryId);
if ($category->fk_parent == $conf->global->DOLICAR_CAR_BRANDS_TAG) {
$brand_name = $category->label;
}
}
}
}

return $brand_name;
}
Original file line number Diff line number Diff line change
Expand Up @@ -166,19 +166,7 @@

$productId = $data['productId'];

if (!empty($productId) && $productId > 0) {
$product->fetch($productId);
$categories = $product->getCategoriesCommon('product');

if (is_array($categories) && !empty($categories)) {
foreach($categories as $categoryId) {
$category->fetch($categoryId);
if ($category->fk_parent == $conf->global->DOLICAR_CAR_BRANDS_TAG) {
$brand_name = $category->label;
}
}
}
}
$brand_name = get_vehicle_brand($productId);
}

$triggermodname = 'DOLICAR_REGISTRATIONCERTIFICATEFR_MODIFY'; // Name of trigger action code to execute when we modify record
Expand Down

0 comments on commit 1eb0c30

Please sign in to comment.