Shopping Cart not working properly in codeigniter - codeigniter

I’m trying to add items to the shopping cart but it will only add the first 6 items to the cart. The rest don’t seem to get added.
I’ve checked the arrays and they have the required id, qty, price, and name. What am I doing wrong?
Here is the code:
function add_cart_item() {
$id = $this->input->post('product_id'); // Assign posted product_id to $id
$cty = $this->input->post('quantity'); // Assign posted quantity to $cty
$colors = $this->input->post('color_id'); // Assign posted color to $colors
$sizes = $this->input->post('size_id'); // Assign posted size to $sizes
$warna = "warna";
$ukuran = "ukuran";
//Ini untuk warna
$sqlNameColor = 'SELECT NAME FROM ref_colors WHERE ID = "'.$colors.'"';
$queryNameColor = $this->db->query($sqlNameColor);
$color_id = $queryNameColor->row()->NAME;
//Ini untuk ukuran
$sqlNameSize = 'SELECT NAME FROM ref_sizes WHERE ID = "'.$sizes.'"';
$queryNameSize = $this->db->query($sqlNameSize);
$size_id = $queryNameSize->row()->NAME;
//Ini untuk weight
$sqlWeight = 'SELECT WEIGHT FROM v_weight WHERE PRODUCT_ID = "'.$id.'"';
$queryWeight = $this->db->query($sqlWeight);
$weight = $queryWeight->row()->WEIGHT;
$product = $this->model_product->get($id);
$data = array(
'id' => $id,
'qty' => $cty,
'price' => $product->PRICE,
'name' => $product->NAME,
'colors' => $color_id,
'sizes' => $size_id,
'colors_id' => $colors,
'weight' => $weight,
'size_id' => $this->input->post('size_id'),
'image' => $product->IMAGE,
'options'=>array('Size' => $this->input->post('size_id'), 'Color' => $this->input->post('color_id'))
);
$this->cart->insert($data);
$data['cart_list'] = $this->cart->contents();
show_shoppingcart('shoppingcart_view', $data);
}
The problem is when i add option value in my cart.
Here is the arrays result:
Array (
[698d51a19d8a121ce581499d7b701668] => Array
(
[rowid] => 698d51a19d8a121ce581499d7b701668
[id] => 1
[qty] => 1
[price] => 10000
[name] => Nike superfly Merah
[colors] => MERAH
[sizes] => 34
[colors_id] => 1
[weight] =>
[size_id] => 1
[image] => assets/images/product/SB 02 - 03 Nike superfly3 merah.jpg
[options] => Array
(
[Size] => 1
[Color] => 1
)
[subtotal] => 10000
)
[caf1a3dfb505ffed0d024130f58c5cfa] => Array
(
[rowid] => caf1a3dfb505ffed0d024130f58c5cfa
[id] => 3
[qty] => 1
[price] => 30000
[name] => Nike Superfly ungu
[colors] => MERAH
[sizes] => 35
[colors_id] => 1
[weight] =>
[size_id] => 2
[image] => assets/images/product/thumbs/T SB 02 - 02 nike superfly3 ijo Stabilo 3.jpg
[options] => Array
(
[Size] => 2
[Color] => 1
)
[subtotal] => 30000
)
[f85454e8279be180185cac7d243c5eb3] => Array
(
[rowid] => f85454e8279be180185cac7d243c5eb3
[id] => 4
[qty] => 1
[price] => 20000
[name] => Nike Superfly Ijo stabilo
[colors] => PUTIH
[sizes] => 35
[colors_id] => 2
[weight] =>
[size_id] => 2
[image] => assets/images/product/thumbs/t SBI 001 03 - Nike CTR putih lis Merah 2.jpg
[options] => Array
(
[Size] => 2
[Color] => 2
)
[subtotal] => 20000
)
[c8ed21db4f678f3b13b9d5ee16489088] => Array
(
[rowid] => c8ed21db4f678f3b13b9d5ee16489088
[id] => 7
[qty] => 1
[price] => 12000
[name] => NIKE CTR Fabregas Kw Super PUTIH KOM
[colors] => PUTIH
[sizes] => 35
[colors_id] => 2
[weight] =>
[size_id] => 2
[image] => assets/images/product/thumbs/T SB 02 04 - Nike superfly3 ungu3 - Copy.jpg
[options] => Array
(
[Size] => 2
[Color] => 2
)
[subtotal] => 12000
)
[ccc0aa1b81bf81e16c676ddb977c5881] => Array
(
[rowid] => ccc0aa1b81bf81e16c676ddb977c5881
[id] => 9
[qty] => 1
[price] => 12000
[name] => ADIDAS CTR Fabregas Kw Super PUTIH KOM BIRU
[colors] => PUTIH
[sizes] => 35
[colors_id] => 2
[weight] =>
[size_id] => 2
[image] => assets/images/product/thumbs/T SBI 001 01 - Nike CTR putih lis Biru 2.jpg
[options] => Array
(
[Size] => 2
[Color] => 2
)
[subtotal] => 12000
)
)

Ryan is correct.
Here is the SQL that worked for me.
CREATE TABLE `ci_sessions` (
`session_id` varchar(40) NOT NULL DEFAULT '0',
`ip_address` varchar(16) NOT NULL DEFAULT '0',
`user_agent` varchar(50) NOT NULL,
`last_activity` int(10) unsigned NOT NULL DEFAULT '0',
`user_data` text NOT NULL,
PRIMARY KEY (`session_id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8;

Enable session database would solve the problem, your session can't hold your cart data, that's why you only can add 6 items.

Related

How to sum of all values using hasManyRelation in laravel

I am using laravel query builder. i got stuck somewhere. My query is like below :-
$details = File::query();
if($ftskey=="partially"){
$details = $details->with(['partialfiles'=>function($query) use($startdate,$enddate){
$query->whereDate('partial_date', '>=', $startdate)
->whereDate('partial_date', '<=', $enddate);
}]);
}
$details = $details->get();
$response = json_decode(json_encode($details),true);
//Relationship below
public function partialfiles(){
return $this->hasMany('App\PartialFile','file_id');
}
Output is coming below:-
Array
(
[0] => Array
(
[id] => 238
[file_no] => FSC334
[partialfiles] => Array
(
[0] => Array
(
[id] => 3
[file_id] => 238
[partial_date] => 2019-09-23
[partial_amount] => 50
)
[1] => Array
(
[id] => 4
[file_id] => 238
[partial_date] => 2019-09-23
[partial_amount] => 50
)
)
)
[0] => Array
(
[id] => 239
[file_no] => FSC335
[partialfiles] => Array
(
[0] => Array
(
[id] => 3
[file_id] => 238
[partial_date] => 2019-09-23
[partial_amount] => 100
)
[1] => Array
(
[id] => 4
[file_id] => 238
[partial_date] => 2019-09-23
[partial_amount] => 100
)
)
)
)
Now i want to add sum of all partial_amount key that i used in hasMany relationship i.e is 50+50+100+100 =300 my expected output is like below:-
Array
(
[0] => Array
(
[id] => 238
[file_no] => FSC334
[total_amount] => 300
[partialfiles] => Array
(
[0] => Array
(
[id] => 3
[file_id] => 238
[partial_date] => 2019-09-23
[partial_amount] => 50
)
[1] => Array
(
[id] => 4
[file_id] => 238
[partial_date] => 2019-09-23
[partial_amount] => 50
)
)
)
[0] => Array
(
[id] => 239
[file_no] => FSC335
[total_amount] => 300
[partialfiles] => Array
(
[0] => Array
(
[id] => 3
[file_id] => 238
[partial_date] => 2019-09-23
[partial_amount] => 100
)
[1] => Array
(
[id] => 4
[file_id] => 238
[partial_date] => 2019-09-23
[partial_amount] => 100
)
)
)
)
Now see i have added the key total_amount in array. Kindly help me how can i get the sum of all amount.
note :- Please don't suggest me foreach loop to do. As i want to do at query level only.
You can use sum() from Collection
$details->partialfiles()->sum('partial_amount');
also read this documentation from laravel: https://laravel.com/docs/5.8/collections

How do I remove indexes in findall of cakephp

I have the following code:
$s= $this->ShowFare->find('all');
Array
(
[0] => Array
(
[ShowFare] => Array
(
[id] => 21
[press_release_id] => 14
[category] => 0
[title] => pr
[image_name] => 1486719733.jpg
[crop_image] => 1486719729.jpg
[is_default] => 0
[is_active] => 0
[created] => 2017-02-10 09:42:13
[created_by] => 0
[modified] => 2017-02-10 09:42:13
[modified_by] => 0
[deleted] => 0000-00-00 00:00:00
[deleted_by] => 0
)
[PressRelease] => Array
(
[id] =>
[title] =>
)
)
[1] => Array
(
[ShowFare] => Array
(
[id] => 22
[press_release_id] => 7
[category] => 0
[title] => abcd
[image_name] => 1486721484.jpg
[crop_image] => 1486721481.jpg
[is_default] => 0
[is_active] => 0
[created] => 2017-02-10 10:11:24
[created_by] => 0
[modified] => 2017-02-10 10:11:24
[modified_by] => 0
[deleted] => 0000-00-00 00:00:00
[deleted_by] => 0
)
[PressRelease] => Array
(
[id] => 7
[title] => ht48 hours, 04 March 2016
)
)
)
I want the above results in following format:
Array
(
Array
(
[ShowFare] => Array
(
[id] => 21
[press_release_id] => 14
[category] => 0
[title] => pr
[image_name] => 1486719733.jpg
[crop_image] => 1486719729.jpg
[is_default] => 0
[is_active] => 0
[created] => 2017-02-10 09:42:13
[created_by] => 0
[modified] => 2017-02-10 09:42:13
[modified_by] => 0
[deleted] => 0000-00-00 00:00:00
[deleted_by] => 0
)
[PressRelease] => Array
(
[id] =>
[title] =>
)
)
Array
(
[ShowFare] => Array
(
[id] => 22
[press_release_id] => 7
[category] => 0
[title] => abcd
[image_name] => 1486721484.jpg
[crop_image] => 1486721481.jpg
[is_default] => 0
[is_active] => 0
[created] => 2017-02-10 10:11:24
[created_by] => 0
[modified] => 2017-02-10 10:11:24
[modified_by] => 0
[deleted] => 0000-00-00 00:00:00
[deleted_by] => 0
)
[PressRelease] => Array
(
[id] => 7
[title] => ht48 hours, 04 March 2016
)
)
)
Is this possible?
Thanks in advance...

Restructure array and use update_batch function

Having problem with restructuring array.
I'm working with bulk upload data(Update) to database. So i have a 3 Array like this.
Array ( [0] => aaa [1] => ccc [2] => eee [3] => ggg )
Array ( [0] => bbb [1] => ddd [2] => fff [3] => hhh )
Array ( [0] => 1662 [1] => 1663 [2] => 1664 [3] => 1665 )
So What i want is, I need to restructure array to given order below. And then upload(update) to database.
$data = array(
array(
'title' => 'aaa' ,
'Info' => 'bbb' ,
'id' => '1662'
),
array(
'title' => 'ccc' ,
'Info' => 'ddd' ,
'id' => '1663'
),
array(
'title' => 'eee' ,
'Info' => 'fff' ,
'id' => '1664'
),
array(
'title' => 'ggg' ,
'Info' => 'hhh' ,
'id' => '1665'
)
);
$this->db->update_batch('mytable', $data,'id');
How I can restructure the array??
Note : array content will be keep change when various type is selected.
ex:
array(
'title' => 'Any value' ,
'Info' => 'Any value' ,
'id' => 'Any Id'
This may help you
[akshay#localhost tmp]$ cat test.php
<?php
$a1 = array('aaa','ccc','eee','ggg');
$a2 = array('bbb','ddd','fff','hhh');
$a3 = array(1662,1663,1664,1665);
// Output
$output = array_map(function($a,$b,$c){ return array('title'=>$a,'Info'=>$b,'id'=>$c);},$a1,$a2,$a3)
print_r ( $output );
// Here add your update statement
// $this->db->update_batch('mytable', $output,'id');
?>
Output
[akshay#localhost tmp]$ php test.php
Array
(
[0] => Array
(
[title] => aaa
[Info] => bbb
[id] => 1662
)
[1] => Array
(
[title] => ccc
[Info] => ddd
[id] => 1663
)
[2] => Array
(
[title] => eee
[Info] => fff
[id] => 1664
)
[3] => Array
(
[title] => ggg
[Info] => hhh
[id] => 1665
)
)

Iterating an array via Smarty in SugarCRM

When iterating an array in Smarty I am getting results conflicting with a print_r() of the same array.
When doing a print_r() on the array I can see that there are 2 objects in the array and each object is unique. However, when I run a print_r() on each item of the array (via foreach loop) I seem to get the same results for each item.
Can anyone identify what I'm doing wrong?
See the below code examples and results.
Code:
{$fields.rgggo_spreadsheetcellmap_documents.value->beans|#print_r}
Ouput:
Array
(
[a852b076-a5cb-dda9-3868-52010d6957ab] => RGGGO_SpreadsheetCellMap Object
(
[new_schema] => 1
[module_dir] => RGGGO_SpreadsheetCellMap
[object_name] => RGGGO_SpreadsheetCellMap
[table_name] => rgggo_spreadsheetcellmap
[importable] =>
[id] => a852b076-a5cb-dda9-3868-52010d6957ab
[name] =>
[date_entered] => 08/06/2013 09:52am
[date_modified] => 08/06/2013 02:16pm
[modified_user_id] => 1
[modified_by_name] => Sean
[created_by] => 1
[created_by_name] => Sean
[description] => Test 2
[deleted] => 0
[created_by_link] =>
[modified_user_link] =>
[team_id] => 2e201ae4-fac9-8426-44c5-4f54f5830831
[team_set_id] => 65bd59b2-b3ed-fb2b-6a85-4f8888229942
[team_count] =>
[team_name] => Development
[team_link] =>
[team_count_link] =>
[teams] =>
[assigned_user_id] =>
[assigned_user_name] =>
[assigned_user_link] =>
[field] => document_type_text_c
[row] => 3
[col] => 1
.... a bunch more stuff here
)
[f038918d-a13d-69f0-3541-51fff82f0497] => RGGGO_SpreadsheetCellMap Object
(
[new_schema] => 1
[module_dir] => RGGGO_SpreadsheetCellMap
[object_name] => RGGGO_SpreadsheetCellMap
[table_name] => rgggo_spreadsheetcellmap
[importable] =>
[id] => f038918d-a13d-69f0-3541-51fff82f0497
[name] =>
[date_entered] => 08/05/2013 02:10pm
[date_modified] => 08/06/2013 02:17pm
[modified_user_id] => 1
[modified_by_name] => Sean
[created_by] => 1
[created_by_name] => Sean
[description] =>
[deleted] => 0
[created_by_link] =>
[modified_user_link] =>
[team_id] => 2e201ae4-fac9-8426-44c5-4f54f5830831
[team_set_id] => 65bd59b2-b3ed-fb2b-6a85-4f8888229942
[team_count] =>
[team_name] => Development
[team_link] =>
[team_count_link] =>
[teams] =>
[assigned_user_id] =>
[assigned_user_name] =>
[assigned_user_link] =>
[field] => description
[row] => 2
[col] => 1
.... a bunch more stuff here
)
)
When I iterate the array...
{{foreach from=$fields.rgggo_spreadsheetcellmap_documents.value->beans key=k item=v}}
<pre>
{$v|#print_r}
</pre>
{{/foreach}}
I get these results:
RGGGO_SpreadsheetCellMap Object
(
[new_schema] => 1
[module_dir] => RGGGO_SpreadsheetCellMap
[object_name] => RGGGO_SpreadsheetCellMap
[table_name] => rgggo_spreadsheetcellmap
[importable] =>
[id] => f038918d-a13d-69f0-3541-51fff82f0497
[name] =>
[date_entered] => 08/05/2013 02:10pm
[date_modified] => 08/06/2013 02:17pm
[modified_user_id] => 1
[modified_by_name] => Sean
[created_by] => 1
[created_by_name] => Sean
[description] =>
[deleted] => 0
[created_by_link] =>
[modified_user_link] =>
[team_id] => 2e201ae4-fac9-8426-44c5-4f54f5830831
[team_set_id] => 65bd59b2-b3ed-fb2b-6a85-4f8888229942
[team_count] =>
[team_name] => Development
[team_link] =>
[team_count_link] =>
[teams] =>
[assigned_user_id] =>
[assigned_user_name] =>
[assigned_user_link] =>
[field] => description
[row] => 2
[col] => 1
.... a bunch more stuff here
)
RGGGO_SpreadsheetCellMap Object
(
[new_schema] => 1
[module_dir] => RGGGO_SpreadsheetCellMap
[object_name] => RGGGO_SpreadsheetCellMap
[table_name] => rgggo_spreadsheetcellmap
[importable] =>
[id] => f038918d-a13d-69f0-3541-51fff82f0497
[name] =>
[date_entered] => 08/05/2013 02:10pm
[date_modified] => 08/06/2013 02:17pm
[modified_user_id] => 1
[modified_by_name] => Sean
[created_by] => 1
[created_by_name] => Sean
[description] =>
[deleted] => 0
[created_by_link] =>
[modified_user_link] =>
[team_id] => 2e201ae4-fac9-8426-44c5-4f54f5830831
[team_set_id] => 65bd59b2-b3ed-fb2b-6a85-4f8888229942
[team_count] =>
[team_name] => Development
[team_link] =>
[team_count_link] =>
[teams] =>
[assigned_user_id] =>
[assigned_user_name] =>
[assigned_user_link] =>
[field] => description
[row] => 2
[col] => 1
.... a bunch more stuff here
)
I found the answer in another stackoverflow question. The issue is double vs single curly brackets and their use in SugarCRM.
Is there a difference between using a single vs. double brace (delimiters) in SugarCRM Smarty tpls command construct?

smarty arrays multidimensional

I want to access the value of thumbnail using Smarty but I need some help to loop through this array
Array (
[photo] => Array (
[ID] => 10
[Listing_ID] => 10
[Position] => 1
[Photo] => listing_photo10_1710730681321487877.jpg
[Thumbnail] => listing_thumbnail10_11485755481321487877.jpg
[Original] => listing_orig10_19751362711321487877.jpg
[Description] =>
[Type] => sale
[Status] => active
[Kind_ID] => 1
[Account_ID] => 9
[Plan_ID] => 1
[Pay_date] => 2011-11-17 04:57:45
[Featured_ID] => 0
[Featured_date] => 0000-00-00 00:00:00
[Last_show] => 0000-00-00 00:00:00
[Crossed] =>
[Shows] => 0
[Date] => 2011-11-17 04:57:45
[Rating] => 0
[Rating_votes] => 0
[Cron] => 0
[Cron_notified] => 0
[Cron_featured] => 0
[categories] =>
[headline] => test
[price] => 1|euro
[description] => asdas
[condition] => 1
[title] =>
[lf_site_url] =>
[description_add] =>
[contact_number] =>
)
)
<div id="display_image">
{foreach from=$products_images item=photo name=photo}
{foreach from=$photo item=thumbnail name=thumbnail}
{$thumbnail|print_r}
<a href="{$smarty.const.RL_URL_HOME}files/{$thumbnail.Photo}">
<img src="{$smarty.const.RL_URL_HOME}files/{$thumbnail.Thumbnail}" width="87" height="65" style="margin:3px;" /> </a>
{/foreach}
{/foreach}
try this

Resources