Auto fill value multidimensional array in php - php

Question might be difficult to answer but here it goes:-
See I have an market order book in array like this:-
$str = array(
array(
'amount' => 1.5,
'price' => 10,
'user' => 'test',
'filled' => 0,
'status' => 'active',
),
array(
'amount' => 2.5,
'price' => 10,
'user' => 'test1',
'filled' => 0,
'status' => 'active',
),
array(
'amount' => 5,
'price' =>10,
'user' => 'test2',
'filled' => 0,
'status' => 'active',
),
array(
'amount' => 10,
'price' => 10,
'user' => 'test3',
'filled' => 0,
'status' => 'active',
)
);
Here the above arrays shows the name of user selling the amount of a thing and the price per thing. Status is active as nothing is still sold to anyone(filled is 0). Let's say a user named test4 comes into the picture and wants to buy 6 things at price'10'. How do I make so that the first three orders get dynamically filled and also from 'active' status to 'done' or 'partially filled'.
Please help :)

Related

How do I set a max quantity in darryldecode shopping cart in laravel?

\Cart::add(array(
'id' => $request->test,
'name' => $price->tests->item_name,
'quantity' => 1,
'price' => $price->price,
'attributes' => array(
'lab_logo' => $price->labs->logo,
'lab_name' => $price->labs->name,
'item_number' => $price->tests->item_number
),
));
When i add the same product it increments the item quantity but i want the quantity of the item to be 1 at max.
According to the documentation:
// NOTE: as you can see by default, the quantity update is relative to its current value
// if you want to just totally replace the quantity instead of incrementing or decrementing its current quantity value
// you can pass an array in quantity value like so:
Cart::update(456, array(
'quantity' => array(
'relative' => false,
'value' => 5
),
));
So, if you pass an array on add and override it to not be relative, it should work as expected:
Cart::add(array(
'id' => $request->test,
'name' => $price->tests->item_name,
'quantity' => array(
'relative' => false,
'value' => 1,
),
'price' => $price->price,
'attributes' => array(
'lab_logo' => $price->labs->logo,
'lab_name' => $price->labs->name,
'item_number' => $price->tests->item_number
),
));

How to insert value cart codeigniter into database if has options

$data = array(
'id' => $id_product,
'qty' => 1,
'price' => '',
'name' => $name_group->name_product_groups.' '.$name_product->name_products,
'options' => array('player'=>$this->input->post('name'),'number'=>$this->input->post('number'),'size'=>$name_size->name_group.' '.$name_size->name_size,'comment'=>$this->input->post('comment')),
'id_groups' => $id_groups,
'fabric' => $name_fabric->name_fabrics,
'option' => $name_option,
'order_type' => 'Order Uniform');
$this->orders->insert_order_product_ready($data2);
can i ask, how to insert data on cart into database? because data has options

JSON Array Construction PHP

I have part of a JSON feed that I need to segment based on variable existance, but its a nested array and I am not quite sure how to write it down.
Here is the code
$postData += array(
'LineItems' => array(
array(
'ItemName' => $_POST['milestone_1_detail'],
'Description' => 'Minimum Guarantee - Installment 1',
'Quantity' => 1,
'Price' => $_POST['milestone_1_amount'],
'SellComm' => 0,
'BuyComm' => 0,
'Accept' => true
),
array(
'ItemName' => $_POST['milestone_2_detail'],
'Description' => 'Minimum Guarantee - Installment 2',
'Quantity' => 1,
'Price' => $_POST['milestone_2_amount'],
'SellComm' => 0,
'BuyComm' => 0,
'Accept' => true
),
array(
'ItemName' => $_POST['milestone_3_detail'],
'Description' => 'Minimum Guarantee - Installment 3',
'Quantity' => 1,
'Price' => $_POST['milestone_3_amount'],
'SellComm' => 0,
'BuyComm' => 0,
'Accept' => true
)
)
);
As you can see, its three (potentially) items all listed in a parent array
I need to do a basic
if ($_POST['milestone_1_amount']) { LineItem1 }
if ($_POST['milestone_2_amount']) { LineItem2 }
if ($_POST['milestone_3_amount']) { LineItem3 }
type condition for all three items,that will still keep those child arrays in the parent array but ONLY show the lineItems that have a value set, but not quite sure how to correctly write the code and retain the array format
Thank you in advance for helping me to stop tearing my hair out

iOS "corrupting" PHP Session

I have been working on a bug now that has been plaguing me for ages and it is really obscure and difficult to get to the bottom of.
The bug only affects iOS devices (iPhone/iPad)
It won't always affect a device, it seems to be random
Customers who have placed several orders fine may suddenly experience it, then when placing another order minutes later not experience it
We have seen it happen in both very old devices and newer versions of iOS
It only affects users using Safari that we have seen
Theories we have tested:
Something to do with mobile data/switching between cell towers when roaming causes the session to become corrupt. We were unable to reproduce this and customers experiencing it say it has happened while at home on WiFi
When switching between HTTP/HTTPS the session is becoming void, we made the entire site secure and it still happened
Poor code in our cart somewhere, we operate multiple brands and some are using different carts. A similar thing happens in all of them
Server misconfiguration, tried multiple servers with 4 different hosts. They configured the server in 2 instances with the same result.
The payment gateway isn't working correctly (we used to use a HPP & PayPal solution), we switched to an API solution with the same result
Somehow misconfigured product, can't be the case as the same product works fine in almost all cases, except the odd iOS ones
Below I have included a sample of what the array should look like storing the cart, and what it looks like on a corrupt iOS cart
Correct Cart
$_SESSION['cart'] = array(
'items' = array (0 => array(
'product_name' => 'Shirt',
'product_price' => '20.00',
'product_sku' => '801245',
'vat_rate' => '20.0000',
'attributes' => array(
'size' => array('value' => 'large', 'cost' => '+5'),
'qty' => array('value' => 1, 'cost' => '+0'),
'colour' => array('value' => 'blue', 'cost' => '+0'),
),
'delivery_info' => array(
'name' => 'Mr A. Tester',
'line1' => 'Street',
'line2' => 'Off another street',
'company' => 'ACME Ent.',
'postcode' => 'AA1 0AA',
'county' => 'London',
'country' => 'United Kingdom',
'date' => '2015-12-01',
),
)
),
'totals' = array (
'item' => '20.00',
'extras' => '5.00',
'delivery' => '3.00',
'blended_vat' => '20.0000',
'to_pay' => '28.00',
),
'cart_id' = 'fc5e038d38a57032085441e7fe7010b0',
'customer_id' = '102145',
'order_status' = 'Pending',
'paid' = false,
)
Corrupt iOS Cart
$_SESSION['cart'] = array(
'items' = array (
'attributes' => array(
'size' => array('value' => 'large', 'cost' => '+5'),
'qty' => array('value' => 1, 'cost' => '+0'),
'colour' => array('value' => 'blue', 'cost' => '+0'),
),
'delivery_info' => array(
'name' => 'Mr A. Tester',
'line1' => 'Street',
'line2' => 'Off another street',
'company' => 'ACME Ent.',
'postcode' => 'AA1 0AA',
'county' => 'London',
'country' => 'United Kingdom',
'date' => '2015-12-01',
),
)
),
0 => array(
'product_name' => 'Shirt',
'product_price' => '20.00',
'product_sku' => '801245',
'vat_rate' => '20.0000',
'totals' = array (
'item' => '20.00',
'extras' => '5.00',
'delivery' => '3.00',
'blended_vat' => '20.0000',
'to_pay' => '28.00',
),
'cart_id' = 'fc5e038d38a57032085441e7fe7010b0',
'customer_id' = '102145',
'order_status' = 'Pending',
'paid' = false,
)
I would love to hear anyone's thoughts on this and any possible suggestions. As I say the cart works fine with every OS/Browser combination. It only randomly seems to affect iPhones/iPads, and could work fine on the same device several times, then not work, then work again.
It seems random as to when it won't work.

how to pre-fill select box in typo3 backend

First of all excuse my bad english.
I got a problem with my select-field in the BE. I would like to prefill (preselect) all of the available items.
Code in ext_tables.php:
'teilnehmer' => array(
'exclude' => 0,
'label' => 'LLL:EXT:kiwanisext/Resources/Private/Language/locallang_db.xlf:tx_kiwanisext_domain_model_veranstaltung.teilnehmer',
'config' => array(
'type' => 'select',
'foreign_table' => 'fe_users',
'MM' => 'tx_kiwanisext_veranstaltung_user_mm',
'size' => 10,
'autoSizeMax' => 30,
'maxitems' => 9999,
'multiple' => 0,
'wizards' => array(
'_PADDING' => 1,
'_VERTICAL' => 1,
'edit' => array(
'type' => 'popup',
'title' => 'Edit',
'script' => 'wizard_edit.php',
'icon' => 'edit2.gif',
'popup_onlyOpenIfSelected' => 1,
'JSopenParams' => 'height=350,width=580,status=0,menubar=0,scrollbars=1',
),
'add' => Array(
'type' => 'script',
'title' => 'Create new',
'icon' => 'add.gif',
'params' => array(
'table' => 'fe_users',
'pid' => '###CURRENT_PID###',
'setValue' => 'prepend'
),
'script' => 'wizard_add.php',
),
),
),
),
I found nothing helpful in the documentation.
Any hint, tip or help will be much appreciated!
Its not possible to do that with plain TCA config, afaik. You can however define a default value wich will be selected (if none is defines, 1st item will be selected).
'default' => 'myValue'
But to preselect multiple values at once, you have to use JavaScript I guess.
This code worked for me in typo3 6.2. I have a selectbox filled with database records.
I want the records with ID's 1 ans 2 to be preselected in the selectbox:
'thematique' => array(
'exclude' => 0,
'label' => 'LLL:EXT:dk_actus/locallang_db.xml:tx_dkactus_thematique',
'config' => array(
'type' => 'select',
'foreign_table' => 'tx_dkactus_thematique',
'foreign_table_where' => 'ORDER BY tx_dkactus_thematique.uid',
'size' => 10,
'minitems' => 0,
'maxitems' => 99,
'default' => '1,2',
),
),

Categories