GWM:CHANGES-in-product-module-vendor-selection
This commit is contained in:
parent
52e4ab8ec0
commit
28fe55efa7
@ -128,15 +128,51 @@ class Products extends BaseController
|
||||
{
|
||||
|
||||
$model_ids = $this->request->getPost('model_ids');
|
||||
|
||||
$make_id = $this->request->getPost('make_id');
|
||||
$vendorModel = new VendorModel();
|
||||
$vendors = $vendorModel->get_vendors_by_model( $model_ids);
|
||||
$Vendors = $vendorModel->where('branch_id',$this->session->get('logged_user_branch_id'))->findAll();
|
||||
if($Vendors){
|
||||
|
||||
$data = [];
|
||||
|
||||
if ($vendors) {
|
||||
foreach ($model_ids as $modelKey => $modelValue)
|
||||
{
|
||||
foreach ($Vendors as $vendorsKey => $vendorsValue)
|
||||
{
|
||||
$modelsArray = json_decode($vendorsValue['model'], true);
|
||||
if (is_array($modelsArray))
|
||||
{
|
||||
$findIfModelExist = array_search($modelValue, $modelsArray);
|
||||
if ($findIfModelExist !== false)
|
||||
{
|
||||
array_push($data,$vendorsValue);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (count($data)) {
|
||||
|
||||
$arrayOfArrays = array_map(function($obj) {
|
||||
return (array) $obj;
|
||||
}, $data);
|
||||
|
||||
// Remove duplicates based on string representation of each object
|
||||
$uniqueArray = array_map('unserialize', array_unique(array_map('serialize', $arrayOfArrays)));
|
||||
|
||||
// Convert the unique array of associative arrays back to an array of objects
|
||||
$uniqueObjectsArray = array_map(function($arr) {
|
||||
return (object) $arr;
|
||||
}, $uniqueArray);
|
||||
|
||||
return $this->response->setJSON($uniqueArray);
|
||||
|
||||
} else {
|
||||
|
||||
return $this->response->setJSON($vendors);
|
||||
} else {
|
||||
|
||||
return $this->response->setJSON([]);
|
||||
}
|
||||
}else {
|
||||
|
||||
return $this->response->setJSON([]);
|
||||
}
|
||||
}
|
||||
|
||||
@ -222,14 +222,15 @@ $(document).ready(function() {
|
||||
$('#model').change(function() {
|
||||
|
||||
var model_ids = $('#model').val(); // Get the selected model IDs
|
||||
console.log(model_ids);
|
||||
var make_id = $('#make').val();
|
||||
console.log(model_ids);
|
||||
|
||||
// AJAX request to get vendors based on the selected model ID
|
||||
$.ajax({
|
||||
url: '<?php echo base_url('get_vendors_by_model') ?>', // URL to your CodeIgniter controller method
|
||||
type: 'POST',
|
||||
dataType: 'json',
|
||||
data: { model_ids: model_ids }, // Send the selected make ID and model IDs to the controller
|
||||
data: { model_ids: model_ids , make_id : make_id }, // Send the selected make ID and model IDs to the controller
|
||||
success: function(response) {
|
||||
// Update vendor dropdown based on the response
|
||||
if (response) {
|
||||
|
||||
Loading…
Reference in New Issue
Block a user