0

Has anyone got a clue why this code does not update the column order_id in my database? Is it because we are in model-context? Because similar code does work in controller-context.

If I dump the $order variable, I can see that it has updated the order_id value of the object, but this is not saved into the database.

These are the fields in the table planner_orders:

id  int
order_id    bigint
visitor_id  bigint
store_id    int
repair_customers_id int
start_timeslot  timestamp
timeslots   int
location    varchar
vat double
total_vat   double
created timestamp

.

<?php
class Alphabase_Planner_Model_Order extends Mage_Core_Model_Abstract
{
    public function _construct()
    {
        parent::_construct();
        $this->_init('planner/order');
    }

    public function create($visitor, $store, $customer, $start, $timeslots = 0, $location, $vat, $total_vat) {
        $order = Mage::getModel('planner/order')
            ->setData('visitor_id', $visitor)
            ->setData('store_id', $store)
            ->setData('repair_customers_id', $customer)
            ->setData('start_timeslot', $start)
            ->setData('timeslots', $timeslots)
            ->setData('location', $location)
            ->setData('vat', $vat)
            ->setData('total_vat', $total_vat)
            ->setData('created', now())
            ->save();
        $id = $order->id;
        $order_id = $store.sprintf('%08d', $id);
        $order->setOrderId($order_id);
        $order->save();
        return $order;
    }

}
4
  • I tested same code and it works. Nothing wrong with code. Have you checked that cache is not troubling you? If you set order_id in first call(for testing hardcode order_id value) and then save, is it saving data or same issue is coming? Nov 21, 2013 at 18:18
  • What is $store? Why $order->id should work? Please, show var_dump($store) and var_dump(sprintf('%08d', $id)), add it before $order->setOrderId($order_id);
    – freento
    Nov 21, 2013 at 18:42
  • $store is the store_id, which is (int) 8 in the example. Nov 21, 2013 at 21:05
  • Crazy thing, but I let the thing rest for the night and now it works! Thanks anyway for your thoughts. Nov 22, 2013 at 11:19

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.