last day (15 days later) » 

8:02 PM
0
A: After refresh the page select dropdown is cleared

Praveen Kumar PurushothamanI feel there's something wrong with: <?php if (in_array($prim->name_id, array_column($this->cart->contents(), 'id'))) { foreach($this->cart->contents() as $product) { if ($product['options']['durationActivity'] == '12m') { $yearSelected12 = 'selected="selected"'; } if ($produ...

 
Thanks for the answer. Give me some time to check this.
 
@user9437856 Sure, added some more details.
 
why I am using for each because to find the id and get the value from the cart. Is there any other option without foreach?
I treid your select code but I am getting the error "Undefined index: duration". $product["duration"] is the correct way to display ?
 
@user9437856 Did you define $product as I have said you?
 
Where should I define? I tried $product['options']['duration'] and it's working but the issue is, if I refresh the page then it is working. before adding to the cart I am getting the error Undefined variable: product
 
8:02 PM
@user9437856 Oh wow... You are close.
 
Yes, but getting the error Undefined variable: product. Where should I declare that?
 
@user9437856 Show me the definition for $product
 
foreach($this->cart->contents() as $product) { this is only
 
No... That would be very much local to the loop.
 
I can't get you properly
Let me tell you my scenario.
I am displaying the records from the database and displaying in the table list and columns are Name, selectDrodpwn ,price , Addtocart.
records are displaying proper even add to cart is also working but the issue is if user refreshes the page after adding the product to the cart then my select dropdown is showing empty or asking for choose again.
So after some experiments, I found some solution
<?php if (in_array($prim->name_id, array_column($this->cart->contents(), 'id'))){
foreach ($this->cart->contents() as $product) {
//break;

}

<select name="memberDuration" class="form-control dropdownDuration">
<option selected disabled >Select duration</option>
<option value="12m" <?php if($product['options']['duration] == "12m"){ echo 'selected="selected"';} ?> >1 Year</option>
<option value="6m" <?php if($product['options']['duration'] == "6m"){ echo 'selected="selected"';} ?>>6 months</option>
 
8:21 PM
Hey... Sorry...
Looking at it.
 
cool. Thanks
 
That break is what screwing things up.
Okay, I am gonna wait for more answers then..
That's what I would do.
 
Yes, after your suggestion, I removed it.
 
It's beyond my knowledge.
The OOP here is confusing - without getting my hands dirty into the code, I won't be able to get a solution.
Would you like to put on your findings and update the question? :)
 
yes sure I will do.
 
8:23 PM
:)
Good luck.
 
I updated the code.
 
9:09 PM
I asked one more question on SO stackoverflow.com/questions/54280987/…
Hope, this will help you to understand my issue.
 

last day (15 days later) »