Ejemplo n.º 1
0
 public function update(array $data, $isAtomic = true)
 {
     parent::update($data, $isAtomic);
     // Set the groups.
     if (!empty($data['groups'])) {
         $this->groups = array();
         foreach ($data['groups'] as $key => $group) {
             if (!$group instanceof ProductGroup) {
                 $productGroup = ProductGroups::getInstance()->getEntity($group['id']);
                 if (!$productGroup) {
                     $productGroup = new ProductGroup(array('id' => $group['id'], 'name' => $group['name']));
                 }
                 $group = $productGroup;
             }
             // Keep the new entity.
             $this->groups[$group->id] = $group;
         }
     }
     // Invalidate calculated fields.
     $this->pricePerKg = null;
 }
Ejemplo n.º 2
0
 public function update(array $data, $isAtomic = true)
 {
     // Create a security code if none is present.
     if (empty($data['securityCode']) && empty($this->securityCode)) {
         $data['securityCode'] = sprintf('%06d', mt_rand(00, 999999));
     }
     // Record a status
     $newStatus = @$data['status'];
     if ($newStatus) {
         // Update status, but only notify if genuinely changing it. If the
         // current status is null, a new order object is just being
         // populated.
         $this->setStatus($newStatus, !is_null($this->status));
     }
     // Ensure the customer is the correct type.
     if (empty($data['customer'])) {
         if (empty($this->customer)) {
             throw new \InvalidArgumentException('No customer data found, the order will not be created.');
         }
     } else {
         $customerData = @$data['customer'] ?: array();
         if (!$customerData instanceof Customer) {
             // An entity is not retrieved from the registry here as it is
             // quite possible that the current user's data is no longer
             // the same as the one in the order.
             $data['customer'] = new Customer($customerData);
         }
     }
     parent::update($data, $isAtomic);
 }