Restructure array and use update_batch function - codeigniter

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
)
)

Related

How to convert from newsoap to xml using simplexelement,simple_to_string

error_reporting(0);
session_start();
$link=$_POST['Host'];
$_SESSION['Host']=$link;
$client = new SoapClient("http://".$link."/api/soap/?wsdl");
/*api credentials*/
$apiuser=$_POST['User'];
$_SESSION['User']=$apiuser;
$apikey =$_POST['Key'];
$_SESSION['Key']=$apikey;
/*Action to be made */
$action =$_POST['Catalog'];
$_SESSION['Catalog']=$action;
/*Error trapping if in case number will be input*/
if(ctype_alpha(!$action))
{
die('Incorrect format');
}
else
{
$sess_id= $client->login($apiuser, $apikey);
/api login/
echo"Total Active list Product:".(count($client->call($sess_id, $action)));
echo"";
print_r($result=$client->call($sess_id,$action));
echo"";
}
?>
Array
(
[0] => Array
(
[product_id] => 1
[sku] => ROx12345
[name] => acer netbook
[set] => 4
[type] => simple
[category_ids] => Array
(
)
[website_ids] => Array
(
[0] => 1
)
)
[1] => Array
(
[product_id] => 2
[sku] => Cats1234
[name] => starbucks mug
[set] => 4
[type] => simple
[category_ids] => Array
(
)
[website_ids] => Array
(
[0] => 1
)
)
[2] => Array
(
[product_id] => 3
[sku] => samsung2141
[name] => samsung 3110
[set] => 4
[type] => grouped
[category_ids] => Array
(
)
[website_ids] => Array
(
[0] => 1
)
)

Codeigniter Active record response differnt from MyPhpAdmin SQL query

I am getting a different result when I execute query in codeigniter active record form MyPhpAdmin
The following query run using MyPhpAdmin
SELECT * FROM (`ingredients`) LEFT JOIN `product_ingredients` ON `ingredients`.`ingredient_id` = `product_ingredients`.`ingredient_id` AND `product_id` = 46
gives the desired result which which includes the ingredient_id for both ingredient records that get returned.
Array ( [0] => stdClass Object ( [ingredient_id] => 1 [display] => Sweet Almond Oil [slug] => sweet-almond-oil [title] => Sweet Almond Oil [description] => Sweet Almond Oil [featured_image_url] => [product_ingredient_id] => 10 [product_id] => 46 [display_position] => 2 [key_ingredient] => 0 ) [1] => stdClass Object ( [ingredient_id] => 2 [display] => Shea Butter [slug] => shea-butter [title] => Shea Butter [description] => Shea Butter [featured_image_url] => [product_ingredient_id] => [product_id] => [display_position] => [key_ingredient] => ) )
But if I execute this query using Codeigniter Active record with the following code:
$this->db->select('*');
$this->db->join('product_ingredients', 'ingredients.ingredient_id = product_ingredients.ingredient_id AND `product_id` = 46', 'left');
$query = $this->db->get('ingredients');
Then the resulting array is missing the ingredient_id for the second ingredient result which is:
Array ( [0] => stdClass Object ( [ingredient_id] => 1 [display] => Sweet Almond Oil [slug] => sweet-almond-oil [title] => Sweet Almond Oil [description] => Sweet Almond Oil [featured_image_url] => [product_ingredient_id] => 10 [product_id] => 46 [display_position] => 2 [key_ingredient] => 0 ) [1] => stdClass Object ( [ingredient_id] => [display] => Shea Butter [slug] => shea-butter [title] => Shea Butter [description] => Shea Butter [featured_image_url] => [product_ingredient_id] => [product_id] => [display_position] => [key_ingredient] => ) )
Any help would be really appreciated...
Check it out
$this->db->select('i.*');
$this->db->from('ingredients i');
$this->db->join('product_ingredients pi', 'i.ingredient_id = pi.ingredient_id', 'left');
$this->db->where('pi.product_id',46);
$query = $this->db->get()->result_array();

Magento displays errors in server after upgrade

I upgraded my magento site .the upgrading completed without errors.
But when i loading site in browser i got duplicate entry errors ,So i clear the database and again take the url in browser.But now i got this error:
Mage_Eav_Exception Object
(
[_messages:protected] => Array
(
)
[message:protected] => Maximum length of attribute code must be less then 30 symbols
[string:Exception:private] =>
[code:protected] => 0
[file:protected] => /var/www/magento_upgrade/app/Mage.php
[line:protected] => 579
[trace:Exception:private] => Array
(
[0] => Array
(
[file] => /var/www/magento_upgrade/app/code/core/Mage/Eav/Model/Entity/Attribute.php
[line] => 158
[function] => exception
[class] => Mage
[type] => ::
[args] => Array
(
[0] => Mage_Eav
[1] => Maximum length of attribute code must be less then 30 symbols
)
)
[1] => Array
(
[file] => /var/www/magento_upgrade/app/code/core/Mage/Core/Model/Abstract.php
[line] => 316
[function] => _beforeSave
[class] => Mage_Eav_Model_Entity_Attribute
[type] => ->
[args] => Array
(
)
)
[2] => Array
(
[file] => /var/www/magento_upgrade/app/code/community/Biebersdorf/CustomerOrderComment/sql/customerordercomment_setup/mysql4-install-0.0.3.php
[line] => 49
[function] => save
[class] => Mage_Core_Model_Abstract
[type] => ->
[args] => Array
(
)
)
[3] => Array
(
[file] => /var/www/magento_upgrade/app/code/core/Mage/Core/Model/Resource/Setup.php
[line] => 624
[args] => Array
(
[0] => /var/www/magento_upgrade/app/code/community/Biebersdorf/CustomerOrderComment/sql/customerordercomment_setup/mysql4-install-0.0.3.php
)
[function] => include
)
[4] => Array
(
[file] => /var/www/magento_upgrade/app/code/core/Mage/Core/Model/Resource/Setup.php
[line] => 421
[function] => _modifyResourceDb
[class] => Mage_Core_Model_Resource_Setup
[type] => ->
[args] => Array
(
[0] => install
[1] =>
[2] => 0.1.3
)
)
[5] => Array
(
[file] => /var/www/magento_upgrade/app/code/core/Mage/Core/Model/Resource/Setup.php
[line] => 327
[function] => _installResourceDb
[class] => Mage_Core_Model_Resource_Setup
[type] => ->
[args] => Array
(
[0] => 0.1.3
)
)
[6] => Array
(
[file] => /var/www/magento_upgrade/app/code/core/Mage/Core/Model/Resource/Setup.php
[line] => 235
[function] => applyUpdates
[class] => Mage_Core_Model_Resource_Setup
[type] => ->
[args] => Array
(
)
)
[7] => Array
(
[file] => /var/www/magento_upgrade/app/code/core/Mage/Core/Model/App.php
[line] => 417
[function] => applyAllUpdates
[class] => Mage_Core_Model_Resource_Setup
[type] => ::
[args] => Array
(
)
)
[8] => Array
(
[file] => /var/www/magento_upgrade/app/code/core/Mage/Core/Model/App.php
[line] => 343
[function] => _initModules
[class] => Mage_Core_Model_App
[type] => ->
[args] => Array
(
)
)
[9] => Array
(
[file] => /var/www/magento_upgrade/app/Mage.php
[line] => 683
[function] => run
[class] => Mage_Core_Model_App
[type] => ->
[args] => Array
(
[0] => Array
(
[scope_code] =>
[scope_type] => store
[options] => Array
(
)
)
)
)
[10] => Array
(
[file] => /var/www/magento_upgrade/index.php
[line] => 87
[function] => run
[class] => Mage
[type] => ::
[args] => Array
(
[0] =>
[1] => store
)
)
)
[previous:Exception:private] =>
)
How can i solve this?
Or what i do here?
somewhere between the actual version of your Magento install and the one you're trying to upgrade to, Magento put a limit to the characters of the sku of the EAV attributes.
The error you have is because one of your attribute have more then 30 characters in his SKU.
One thing you can do is to override Mage_Eav_Model_Entity_Attribute::ATTRIBUTE_CODE_MAX_LENGTH and make it big enough so that the upgrade go on.
HTH
And for clarity, the full path to the file you want to edit is...
your-project/app/code/core/Mage/Eav/Model/Entity/Attribute.php CONST
ATTRIBUTE_CODE_MAX_LENGTH = 30;
put the CONST ATTRIBUTE_CODE_MAX_LENGTH = 30; to 60
Stolen from: Bijal Bhavsar

Magento solr search - how to add custom field to product search index

I have enterprise magento 1.10 and I need to add custom field to solr index in order to to have better search results. This custom field should contain category names for indexed product.
I need to know which part of magento I need to amend. I modified method Enterprise_Search_Model_Resource_Index::_getCatalogCategoryData which actualy produces some category related data but my new field doesnt appear in message to sorl.
Have I miss something?
Also I have some notes here, maybe it would someone help http://docs.nostresscommerce.com:8090/pages/viewpage.action?pageId=2490371
My output of rewrited Enterprise_Search_Model_Resource_Index::_getCatalogCategoryData, and I need category_name_level_* in solr.
[result] => Array
(
[12227] => Array
(
[#categories] => Array
(
[0] => 2
[3] => 3235
[7] => 2765
[10] => 6672
)
[#show_in_categories] => Array
(
[1] => 6671
[2] => 6670
[4] => 3224
[5] => 3199
[6] => 3191
[8] => 2761
[9] => 2760
)
[#position_category_2] => 1
[#position_category_6671] => 120000
[#position_category_6670] => 120000
[#position_category_3235] => 0
[#position_category_3224] => 150000
[#position_category_3199] => 150000
[#position_category_3191] => 120000
[#position_category_2765] => 1
[#position_category_2761] => 250001
[#position_category_2760] => 250001
[#position_category_6672] => 0
[#visibility] => 4
[#category_name_level_1] => Array
(
[0] => BCC Root Category
)
[#category_name_level_4] => Array
(
[0] => Huishouden
[1] => Top wasmachines
[2] => Accessoires wasmachine
)
[#category_name_level_3] => Array
(
[0] => Beste Koop Shop
[1] => Top
[2] => Wasmachine
)
[#category_name_level_2] => Array
(
[0] => Acties
[1] => Speciale informatie pagina's
[2] => Huishouden
)
[#category_name_level_5] => Array
(
[0] => Wasmachines
)
)
)
Thanks a lot,
Jaro.
I found a solution
class Xyz_Solrsearch_Model_Resource_Engine extends Enterprise_Search_Model_Resource_Engine {
public function __construct()
{
$this->_advancedDynamicIndexFields[] = '#category_name_level_';
parent::__construct();
}
}

Shopping Cart not working properly in 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.

Resources