Beispiel #1
0
 private function save(User $user = null)
 {
     $validator = self::createUserFormValidator($this, $user);
     if ($validator->isValid()) {
         $email = $this->request->get('email');
         $password = $this->request->get('password');
         if ($user && $email != $user->email->get() && User::getInstanceByEmail($email) || !$user && User::getInstanceByEmail($email)) {
             return new JSONResponse(false, 'failure', $this->translate('_err_this_email_is_already_being_used_by_other_user'));
         }
         if ($groupID = (int) $this->request->get('UserGroup')) {
             $group = UserGroup::getInstanceByID((int) $groupID);
         } else {
             $group = null;
         }
         if (!$user) {
             $user = User::getNewInstance($email, $password, $group);
         }
         $user->loadRequestData($this->request);
         $user->userGroup->set($group);
         if (!empty($password)) {
             $user->setPassword($password);
         }
         $user->save();
         $this->saveAddresses($user);
         BackendToolbarItem::registerLastViewedUser($user);
         return new JSONResponse(array('user' => $user->toFlatArray()), 'success', $this->translate('_user_details_were_successfully_saved'));
     } else {
         return new JSONResponse(array('errors' => $validator->getErrorList()), 'failure', $this->translate('_could_not_save_user_details'));
     }
 }
Beispiel #2
0
 public function toolbarBlock()
 {
     $response = new BlockResponse();
     $response->set('dropButtons', BackendToolbarItem::sanitizeItemArray(BackendToolbarItem::getUserToolbarItems(BackendToolbarItem::TYPE_MENU)));
     return $response;
 }
 private function save(CustomerOrder $order)
 {
     $validator = self::createOrderFormValidator();
     if ($validator->isValid()) {
         $existingRecord = $order->isExistingRecord();
         $order->save(true);
         BackendToolbarItem::registerLastViewedOrder($order);
         return new JSONResponse(array('order' => array('ID' => $order->getID())), 'success', $this->translate($existingRecord ? '_order_status_has_been_successfully_changed' : '_new_order_has_been_successfully_created'));
     } else {
         return new JSONResponse(array('errors' => $validator->getErrorList()), 'failure', $this->translate('_error_updating_order_status'));
     }
 }
Beispiel #4
0
 private function save(Product $product)
 {
     ClassLoader::import('application.model.presentation.CategoryPresentation');
     $validator = $this->buildValidator($product);
     if ($validator->isValid()) {
         $product->loadRequestData($this->request);
         foreach (array('ShippingClass' => 'shippingClassID', 'TaxClass' => 'taxClassID') as $class => $field) {
             $value = $this->request->get($field, null);
             $instance = $value ? ActiveRecordModel::getInstanceByID($class, $value) : null;
             $product->setFieldValue($field, $instance);
         }
         $product->save();
         // presentation
         $instance = CategoryPresentation::getInstance($product);
         $instance->loadRequestData($this->request);
         $instance->save();
         // save pricing
         $product->loadSpecification();
         $product->loadPricing();
         if ($quantities = $this->request->get('quantityPricing')) {
             foreach ($product->getRelatedRecordSet('ProductPrice', new ARSelectFilter()) as $price) {
                 $id = $price->currency->get()->getID();
                 $prices = array();
                 if (!empty($quantities[$id])) {
                     $values = json_decode($quantities[$id], true);
                     $prices = array();
                     // no group selected - set all customers
                     if ('' == $values['group'][0]) {
                         $values['group'][0] = 0;
                     }
                     $quantCount = count($values['quant']);
                     foreach ($values['group'] as $groupIndex => $group) {
                         foreach ($values['quant'] as $quantIndex => $quant) {
                             $pr = $values['price'][$groupIndex * $quantCount + $quantIndex];
                             if (strlen($pr) != 0) {
                                 $prices[$quant][$group] = (double) $pr;
                             }
                         }
                     }
                 }
                 ksort($prices);
                 $price->serializedRules->set(serialize($prices));
                 $price->save();
             }
         }
         // $product->loadRequestData($this->request);
         // $product->save();
         if ($this->isQuickEdit == false) {
             BackendToolbarItem::registerLastViewedProduct($product);
         }
         $response = $this->productForm($product);
         $response->setHeader('Cache-Control', 'no-cache, must-revalidate');
         $response->setHeader('Expires', 'Mon, 26 Jul 1997 05:00:00 GMT');
         $response->setHeader('Content-type', 'text/javascript');
         return $response;
     } else {
         // reset validator data (as we won't need to restore the form)
         $validator->restore();
         return new JSONResponse(array('errors' => $validator->getErrorList(), 'failure', $this->translate('_could_not_save_product_information')));
     }
 }
 private function fixSortOrder()
 {
     BackendToolbarItem::saveItemArray(BackendToolbarItem::getUserToolbarItems(BackendToolbarItem::TYPE_MENU));
 }