Note that there are some explanatory texts on larger screens.

plurals
  1. POCakePHP: value not being saved to Db
    primarykey
    data
    text
    <p>I am trying to use Andras Kende's <a href="https://github.com/andraskende/cakephp-shopping-cart" rel="nofollow noreferrer">CakePHP Shopping Cart</a> in my own application, and I cant figure why the following changes will not work.</p> <p>At the end of the order process, after paypal and everything, when the user is about to finalize the transaction, I would like to, if the user is a member/logged in, use <code>$this-&gt;Auth-&gt;user('id')</code> to get their authenticated ID and attach it to the order that is about to be finalized. For the life that is left in me, I can't get it to work. This is what I am doing:</p> <p>I have the following class:</p> <pre><code> public function review() { $shop = $this-&gt;Session-&gt;read('Shop'); if(empty($shop)) { $this-&gt;redirect('/shop/cart'); } if ($this-&gt;request-&gt;is('post')) { $this-&gt;loadModel('Order'); $this-&gt;Order-&gt;set($this-&gt;request-&gt;data); if($this-&gt;Order-&gt;validates()) { $order = $shop; $order['Order']['user_id'] = (int)$this-&gt;Auth-&gt;user('id'); $order['Order']['status'] = 1; var_dump($order); if($shop['Order']['order_type'] == 'paypal') { $paypal = $this-&gt;Paypal-&gt;ConfirmPayment($order['Order']['total']); $ack = strtoupper($paypal['ACK']); if($ack == 'SUCCESS' || $ack == 'SUCCESSWITHWARNING') { $order['Order']['status'] = 2; } $order['Order']['authorization'] = $paypal['ACK']; } $save = $this-&gt;Order-&gt;saveAll($order, array('validate' =&gt; 'first')); if($save) { $this-&gt;set(compact('shop')); App::uses('CakeEmail', 'Network/Email'); $email = new CakeEmail(); $email-&gt;from($this-&gt;requestAction('/settings/getSettingValue/ADMIN_EMAIL')) -&gt;cc($this-&gt;requestAction('/settings/getSettingValue/ADMIN_EMAIL')) -&gt;to($shop['Order']['email']) -&gt;subject('Shop Order') -&gt;emailFormat('text') -&gt;viewVars(array('shop' =&gt; $shop)) -&gt;send(); $this-&gt;redirect(array('action' =&gt; 'success')); } else { $errors = $this-&gt;Order-&gt;invalidFields(); $this-&gt;set(compact('errors')); } } } if(($shop['Order']['order_type'] == 'paypal') &amp;&amp; !empty($shop['Paypal']['Details'])) { $shop['Order']['first_name'] = $shop['Paypal']['Details']['FIRSTNAME']; $shop['Order']['last_name'] = $shop['Paypal']['Details']['LASTNAME']; $shop['Order']['email'] = $shop['Paypal']['Details']['EMAIL']; $shop['Order']['phone'] = '888-888-8888'; $shop['Order']['billing_address'] = $shop['Paypal']['Details']['SHIPTOSTREET']; $shop['Order']['billing_address2'] = ''; $shop['Order']['billing_city'] = $shop['Paypal']['Details']['SHIPTOCITY']; $shop['Order']['billing_zip'] = $shop['Paypal']['Details']['SHIPTOZIP']; $shop['Order']['billing_state'] = $shop['Paypal']['Details']['SHIPTOSTATE']; $shop['Order']['billing_country'] = $shop['Paypal']['Details']['SHIPTOCOUNTRYNAME']; $shop['Order']['shipping_address'] = $shop['Paypal']['Details']['SHIPTOSTREET']; $shop['Order']['shipping_address2'] = ''; $shop['Order']['shipping_city'] = $shop['Paypal']['Details']['SHIPTOCITY']; $shop['Order']['shipping_zip'] = $shop['Paypal']['Details']['SHIPTOZIP']; $shop['Order']['shipping_state'] = $shop['Paypal']['Details']['SHIPTOSTATE']; $shop['Order']['shipping_country'] = $shop['Paypal']['Details']['SHIPTOCOUNTRYNAME']; $shop['Order']['order_type'] = 'paypal'; $this-&gt;Session-&gt;write('Shop.Order', $shop['Order']); } $this-&gt;set(compact('shop')); } </code></pre> <p>At line 11, I add the logged in user ID to the <code>$order</code> array by doing the following:</p> <pre><code>$order['Order']['user_id'] = (int)$this-&gt;Auth-&gt;user('id'); </code></pre> <p>At this point if I do a <code>var_dump($order)</code>, I will see whatever user id is for the currently logged in user, in this case <code>18</code>. So I know for a fact that I am assigning it correctly.</p> <pre><code> ["user_id"]=&gt; int(18) </code></pre> <p>Everything is fine up to here. However, when I check my DB the <code>user_id</code> field is NULL. <code>18</code> is not being saved as added to the array. I have done multiple things and I cant see what am I doing wrong. Please help!</p> <p>My <code>orders</code> table structure look like this:</p> <p><img src="https://i.stack.imgur.com/QpxRm.jpg" alt="enter image description here"></p> <p>And one of the order entry look like this:</p> <p><img src="https://i.stack.imgur.com/Xrxol.jpg" alt="enter image description here"></p> <p>I run out of ideas and I dont know what to do.....</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload