how to update Cart Options in Codeigniter? - codeigniter

Through Documents provided by Codeigniter Its Cart Library doesnt Update its options We can add the Options like that
$data = array(
array(
'id' => 'sku_123ABC',
'qty' => 1,
'price' => 39.95,
'name' => 'T-Shirt',
'options' => array('Size' => 'L', 'Color' => 'Red')
)
);
$this->cart->insert($data);
Is there any other way or any tutorial to learn how we can update options of Cart just like
$qid = $this->input->post("qid");
$pairs = $this->input->post("pairs");
$males = $this->input->post("males");
$females = $this->input->post("females");
$data = array(
array(
'rowid' => $qid,
'qty' => 1,
'options' => array('pairs' => $pairs, 'males' => $males, 'females' => $females))
);
$this->cart->update($data);
I have searched it but seems no one has made any fix for it?

Though I have not found any solution therefore I am using simple solution and that is just rest the item in cart and adding new item with same id and updated option values. Its not great trick though but it is just working for me.

I am fallen yesterday like this kind of problem then i create Extending / Override update function. Here how to Extending Native library Link : Create CI Library
Here is my modified code in Github Link
I hope it will help someone and also can modify as their need.

No it did not work for me.. but there is no any errors, I check the array within the _update function as well,
Array
(
[id] => 177
[rowid] => 66bd8895e10f189f62bf3a65ada83630
[qty] => 1
[options] => Array
(
[vat] => 0
[discount] => 0
)
)

I know i'ts just too late but I want to share my solution:
I just got the the options in an array and updated it as I wanted and then update the entire options field in the cart with the array content.
Hope this help somebody.
Sorry for the english.

The way I tried was a bit difficult but it works. You can’t just update a single option value. To update you have to pass all the existing values to all the option values with the value you want to update as well.
If you want to update your Size option
$data = array(
‘rowid’ => $yourRowIdHere,
‘options’ => array ( ‘color’ => $yourExistingValue, ‘length’ => $yourExistingValue, ‘size’ => $newUpdatedValue)
));
$this->cart->update($data);
Give it a try :)

Related

How with laravel/pint to make keys and values are aligned with spaces on the same level?

In Laravel 9 app using laravel/pint (1.4) with "psr12" preset I prefer to see not code :
\DB::table('quizzes')->insert([
'id' => 2,
'question' => 'What does ORM stand for?',
'quiz_category_id' => 1,
'points' => 4,
'active' => true,
]);
But:
\DB::table('quizzes')->insert([
'id' => 2,
'question' => 'What does ORM stand for?',
'quiz_category_id' => 1,
'points' => 4,
'active' => true,
]);
where keys and values are aligned with spaces on the same level.
I tried to fix it and found property “binary_operator_spaces”
But looking at docs :
https://github.com/laravel/pint/blob/main/resources/presets/laravel.php
I see only 1 rule :
'binary_operator_spaces' => [
'default' => 'single_space',
],
Not sure, but how can I set this rule? Seems it does not hae any other rules...
Thanks!
Check the documentation for binary_operator_spaces
You want to use that rule with the align_single_space_minimal option:
'binary_operator_spaces' => [
'default' => 'align_single_space_minimal',
],
That is if you have the same setup as shown in the link you provided
If you were using PHPCodeSniffer (which is what laravel is using behind the scenes) you would simply use it this way:
$config->setRuleset([
'Squiz.WhiteSpace.OperatorSpacing' => [
'align_single_space_minimal' => true
]
]);
Just remember that each space is 1 byte, and those add up... a pedantic-thought but one to keep in your head none-the-less (imho no one should use this rule or add pointless whitespace to array)

Order by title without taking into account 'the' in Wordpress (wp_query)

I currently have episodes from a TV Show that feature bands playing, so for example I have:
Moby
The Dandy Warhols
The Kooks
My wp_query looks like this:
$loop = new WP_Query(array('post_type' => 'episodio', 'cat' => '9', 'posts_per_page' => 90, 'orderby' => 'title','order' => 'ASC' ));
But I want to order them like this, alphabetically, without taking into account 'the':
The Dandy Warhols
The Kooks
Moby
There are a lot of records in the database, so it's not very practical and/or efficient to get everything into an array, remove 'the', order again and then going through the array to display the data.
Is this possible in WP? Maybe through a filter?
Thanks a lot in advance! :)
$loop = new WP_Query(array('post_type' => 'episodio', 'cat' => '9', 'posts_per_page' => 90, 'orderby' => 'title','order' => 'DESC' ));
you will get result post title descending of category 9.

getting the value of array key in codeigniter

I have the following line in my controller:
$data['faq'] = $this->faqModel->get();
This data print the following using the print_r
Array
(
[faq] => Array
(
[0] => Array
(
[faqid] => 12
[catid] => 122
[question] => How this CMS works
[question_en] => How this CMS works
[answer] => How this CMS works?
[answer_en] => How this CMS works?
[sorder] => 2
[visible] => 1
)
[1] => Array
(
[faqid] => 8
[catid] => 121
[question] => How does the design cost?
[question_en] => How does the design cost?
[answer] => How does the design cost?
[answer_en] => How does the design cost?
[sorder] => 1
[visible] => 1
)
)
)
I want to use the value stored in the [catid] key, and I am trying to do something like:
$data['faq']['catid'] to get that value in the controller (I want to make another select with that value) But I am getting with this error message: Undefined index: catid
Anyone can help me to get the value of ['catid']???
Regards, Zoran
Its 3 dimensional array u look closely there is two elements in faq array. You must wrote something like this: $data['faq'][0]['catid'] or $data['faq'][1]['catid']
The way you are accessing the array is incorrect, you are missing the item index on the second level. The correct way to use it as you are doing would be to do
echo $data['faq'][0]['faqid']; //faqid of the first item
However, this will only show one faqid at a time, and it not so useful when you are iterating. So, a good way would be this way.
foreach($data['faq'] as $value) {
echo $value['faqid'];
}

Names of the associated products of a configurable product are not visible in admin?

In a vanilla install of Magento 1.5.1.0 I have created simple products COLOR-RED, COLOR-BLUE and created a configurable product COLOR that has these products associated with it. This works all fine, except for the fact that the names of the associated products are not shown in the backend in the Configurable product's 'Super product attributes configuration' table.
I have added a simple debug statement to htdocs/app/design/adminhtml/default/default/template/widget/grid.phtml to display the item's data before display. See below, the name attribute is not there.
Does anybody have an idea why? Is it a bug in Magento, or is something else wrong?
Array
(
[entity_id] => 1
[entity_type_id] => 4
[attribute_set_id] => 9
[type_id] => simple
[sku] => COLOR-RED
[has_options] => 0
[required_options] => 0
[created_at] => 2011-12-13 15:08:36
[updated_at] => 2011-12-13 15:08:36
[is_saleable] => 0
[inventory_in_stock] => 0
[color] => 3
[price] => 12.0000
[stock_item] => Varien_Object Object
(
[_data:protected] => Array
(
[is_in_stock] =>
)
[_hasDataChanges:protected] =>
[_origData:protected] =>
[_idFieldName:protected] =>
[_isDeleted:protected] =>
)
)
You're probably using the Simple Configurable Products module. In the file app/code/community/OrganicInternet/SimpleConfigurableProducts/Adminhtml/Block/Catalog/Product/Edit/Tab/Super/Config/Grid.php the developers of Organic Internet left a nice little hint;
#Copied from Magento v1.3.1 code.
#Only need to comment out addFilterByRequiredOptions but there's no
#nice way of doing that without cutting and pasting the method into my own
#derived class. Boo.
#This change stops the filtering-out of any configurable product's 'associated products' that have compulsory custom options
#Have also replaced parent::_prepareCollection with Mage_Adminhtml_Block_Widget_Grid::_prepareCollection();
I figured the code that was used in 1.3.1 was outdated so this file would be outdated if you're using >1.3.1. So I just looked at the contents of the core file app/code/core/Mage/Adminhtml/Block/Catalog/Product/Edit/Tab/Super/Config/Grid.php and looked for differences, and found the culprit.
All you have to do is add this line;
->joinAttribute('name', 'catalog_product/name', 'entity_id', null, 'inner')
between these two lines;
->addFieldToFilter('attribute_set_id',$product->getAttributeSetId())
->addFieldToFilter('type_id', $allowProductTypes);
And you're all set!

Multiple level ordering in Yii

This is my CActiveDataProvider
$dataProvider = new CActiveDataProvider ('MyTable', array (
'pagination' => array (
'PageSize' => 4,
),
'criteria' => array (
'condition' => 'from_user_id='.$user->id,
'order' => 'date DESC',
),
));
My question is: I would like to have this CActiveDataProvider ordered first by date (as the posted code does), and in a second level, within those with the same date, order by a second criteria. Is this possible?
Maybe I'm not understanding you correctly, but won't the following work? :
'order' => 'date DESC, name DESC',

Resources