I have set the session like this
$loc_details = array(
'maincity_id' =>$maincity_id,
'mainzoneid' => $mainzoneid,
'mainproductid' => $productid,
);
$this->session->set_userdata($loc_details);
Here i have retrieved the values like this
$maincity_id=$this->session->userdata('maincity_id');
//$mainzone_id=$this->session->userdata('mainzone_id');
$mainproduct_id=$this->session->userdata('mainproductid');
but if i see the output the session is not set can any one help with this
You need to do like this..........
$loc_details = array(
'maincity_id' =>$maincity_id,
'mainzoneid' => $mainzoneid,
'mainproductid' => $productid,
);
$this->session->set_userdata('loc_details',$loc_details);
$loc_details = $this->session->userdata("loc_details");
$maincity_id = $loc_details['maincity_id'];
$mainproduct_id = $loc_details['mainproductid'];
Related
controller
i need to insert store_merchant_id from $data..but in my coding it takes only the first id..
$data = array(
'merchant_firstname' => $merchant_firstname,
'merchant_lastname' => $merchant_lastname,
'merchant_password' => $merchant_password,
'merchant_email'=>$merchant_email,
);
$merchant_id = Merchant_model::merchant_submit($data);
$data1 = array(
'store_merchant_id'=>$merchant_id,
'store_name'=>$store_name,
'store_phone'=>$store_phone,
'store_address1'=>$store_address1,
);
$return = Merchant_model::merchant_submit1($data1);
Model
return DB::table('le_store')->insert($data1);
I guess you need to get the last inserted id and do something with that
So, i am doing the same what you did
Step 1 : Building the input
1.
$data = array(
'merchant_firstname' => $merchant_firstname,
'merchant_lastname' => $merchant_lastname,
'merchant_password' => $merchant_password,
'merchant_email'=>$merchant_email,
);
Step 2 : Saving the Data
$Merchant = Merchant_model::create($data);
Step 3 : Getting the inserted id
return $Merchant->id;
Now the $Merchant->id will have the last inserted id, You shall return or save this to another model that you wish to do.
Update :
As you want to update the inserted id to another table, Just do this
As usual like previous
$data = array(
'merchant_firstname' => $merchant_firstname,
'merchant_lastname' => $merchant_lastname,
'merchant_password' => $merchant_password,
'merchant_email'=>$merchant_email,
);
$Merchant = Merchant_model::create($data);
Then build $data1
$data1 = array(
'store_merchant_id'=>$Merchant->id,
'store_name'=>$store_name,
'store_phone'=>$store_phone,
'store_address1'=>$store_address1,
);
Note :
store_merchant_id'=>$Merchant->id' should be like this
Then just create it
Merchant_model::create($data1);
Hope this helps you
if($this->input->post('tambah')){
$kode = $this->input->post('kode');
$jumlah = $this->input->post('jumlah');
$hjual = $this->input->post('hjual');
$nama = $this->input->post('nama');
$exp = $this->input->post('tglexp');
$hpp = $this->input->post('hpp');
$temp_stok = $this->input->post('temp_stok');
$diskon = $this->input->post('diskon');
$cart = array(
'id' => $kode,
'qty' => $jumlah,
'price' => $hjual,
'name' => $nama,
'options' => array('exp' => $exp, 'hpp' => $hpp,
'temp_stok' => $temp_stok , 'diskon'=>$diskon ));
$this->cart->insert($cart);
header('location:'.base_url().'penjualan/load_input_barang_eceran');
}
I cant seem to add any more items and the latest one I add replaces the existing one.
I had like this in another controller but strangely can insert and not overwriting
I've had this.
It was non alphanumerics in the product code which caused the whole cart to behave strangely.
Try just having aaa123 etc as codes to test this
In CodeIgniter, I want to insert a row into a db that includes a timestamp for "now".
$message_row = array(
"sender_email" => $recruiter_email,
"recipient_email" => $recruiter_email,
"message" => $recruiter_email,
"send_date" => "NOW()" // hmmm how do I do this?
);
$this->db->insert('messages', $message_row);
If I use "NOW()" it will just enter the string, and not actual have MySQL use its NOW keyword.
In order to use NOW() function in CodeIgniter you need to use "set" function
$table = 'user';
$message_row = array(
"sender_email" => $recruiter_email,
"recipient_email" => $recruiter_email,
"message" => $recruiter_email
);
$this->db->set('send_date', 'NOW()', false);
$this->db->insert($table, $message_row);
if you need to be timezone aware, i recommend you store the datetime in UTC format.
so:
$now = new DateTime ( NULL, new DateTimeZone('UTC'));
$message_row = array(
"sender_email" => $recruiter_email,
"recipient_email" => $recruiter_email,
"message" => $recruiter_email,
"send_date" => $now->format('Y-m-d H:i:s')
);
when you retrieve the information, you have to know the user's timezone, using a $row that contains the send_date:
$then = new DateTime( $row->send_date, new DateTimeZone('UTC'));
$then->setTimeZone(new DateTimeZone($userstimezone));
echo $then->format('Y-M-D H:i:s');
I am trying to add the following 2 additional attributes through API. I am not getting any error, however it is not getting uploaded. It would be great if some one could give me a suggestion.
catalogProductAdditionalAttributesEntity AdAtrributeEntity = new catalogProductAdditionalAttributesEntity();
associativeEntity[] AdditionalAttributes = new associativeEntity[2];
associativeEntity AdditionalAttributeOne = new associativeEntity();
associativeEntity AdditionalAttributeTwo = new associativeEntity();
AdditionalAttributeOne.key = "color";
AdditionalAttributeOne.value = "green";
AdditionalAttributeTwo.key = "size";
AdditionalAttributeTwo.value = "xl";
AdditionalAttributes[0] = AdditionalAttributeOne;
AdditionalAttributes[1] = AdditionalAttributeTwo;
AdAtrributeEntity.single_data = AdditionalAttributes;
ProductEntity.additional_attributes = AdAtrributeEntity;
MyService.catalogProductUpdate(Mylogin, SKU, ProductEntity, null, null)
I know this is older, but I found a solution. 'single_data' and 'multi_data' need to have an array inside it that has the arrays of attributes.
product_data = {
'name' => self.get_attribute_value('name'),
'description' => self.get_attribute_value('description'),
'short_description' => self.get_attribute_value('short_description'),
'weight' => self.get_attribute_value('weight'),
'status' => self.get_attribute_value('status'),
'categories' => compose_categories,
'url_key' => self.get_attribute_value('url_key'),
'price' => self.get_attribute_value('price'),
'additional_attributes' => { 'single_data' => { items: compose_attribute_values }}
}
In the example, I named the additional array 'item', hoever, you can call it whatever you want. I used 'item' because the API returns many values like that. The additional attributes look something like this in PHP:
...
'additional_attributes' = array(
'single_data' => array(
'item' => array(
[0] => array(
'key' => 'some_attribute_code',
'value' => 'some_attribute_value'
)
[1] => array(
'key' => 'some_other_attribute_code',
'value' => 'some_other_attribute_value'
)
)
)
)
...
This work for add additional_attributes:
'additional_attributes' => array(
'single_data' => array(
array(
'key' =>'manufacturer',
'value' => '10'
)
)
)
Example for Java (Apache XML-RPC client + Gson):
I have attribute manufacturer with option: Adidas (ID: 318)
Product entity:
...
#SerializedName("additional_attributes")
private Map<String,Map<String,String>> additionalAttributes;
...
// getters + setters
...
code:
...
Map<String,String> attribute = new HashMap<>();
attribute.put("manufacturer", "318");
Map<String,Map<String,String>> additionalAttributes = new HashMap<>();
additionalAttributes.put("single_data", attribute);
product.setAdditionalAttributes(additionalAttributes);
...
then do product.update api request
p.s: of course it's a little bit weird, but you can wrap that with some facade
I have a basket cookie, before adding a product to the basket the function checks to see if a cookie exists or if a new cookie is required. This works fine when adding one item at a time but there are occasions when more than one item is added at the same time. Again if an old basket cookie exists this works fine. The problem is when no basket cookie exists and the function had to create one.
The first time it goes through, the cookie is created a database record is added ect.
The second time round the function we check for the cookie no cookie is found and another cookie is created etc.
$this->db->select('basket_id');
$this->db->from($this->basket_table);
$this->db->where('basket_id', get_cookie('basket_id'));
$check_basket = $this->db->get();
if($check_basket->num_rows > 0){
$basket_exists = 1;
}else{
$basket_exists = 0;
}
if($basket_exists == 0){
delete_cookie('basket_id');
$basket = array(
'lang_id' => $lang_id,
'currency_id' => $currency_id,
'customer_id' => $customer_id,
);
$this->db->insert($this->basket_table, $basket);
$basket_id = $this->db->insert_id();;
$cookie = array(
'name' => 'basket_id',
'value' => $basket_id,
'expire' => 60*60*24*30,
'domain' => 'REMOVED'
'path' => '/',
'prefix' => '',
);
set_cookie($cookie);
}else{
$basket_id = get_cookie('basket_id');
}
In order to set the cookie, you need to send it to the browser, - but this never happens if your function loops multiple times before you create a view.
So set the cookie prior to them using the basket, OR only check if the cookie needs to be set once, like this:
$this->db->select('basket_id');
$this->db->from($this->basket_table);
$this->db->where('basket_id', get_cookie('basket_id'));
$check_basket = $this->db->get();
if($check_basket->num_rows > 0) {
$basket = array(
'lang_id' => $lang_id,
'currency_id' => $currency_id,
'customer_id' => $customer_id,
);
$this->db->insert($this->basket_table, $basket);
$basket_id = $this->db->insert_id();
$cookie = array(
'name' => 'basket_id',
'value' => $basket_id,
'expire' => 60*60*24*30,
'domain' => 'REMOVED'
'path' => '/',
'prefix' => '',
);
set_cookie($cookie);
}
// Now run your basket logic here - knowing the cookie is setup
}