public function createAction() { if (!$this->request->isPost()) { return $this->forward("/order/index"); } $form = new OrderForm(); $order = new TradeOrder(); $data = $this->request->getPost(); $data = array_filter($data, function ($v) { return '' !== $v; }); if (!$form->isValid($data, $order)) { foreach ($form->getMessages() as $message) { $this->flash->error($message); } return $this->forward('/order/new'); } if ($order->save() == false) { foreach ($order->getMessages() as $message) { $this->flash->error($message); } return $this->forward('/order/new'); } $form->clear(); $this->flash->success("order was created successfully"); return $this->forward("/order/new"); }
public function executeFormWidget(dmWebRequest $request) { $form = new OrderForm(); if ($request->hasParameter($form->getName()) && $form->bindAndValid($request)) { $order = $form->save(); $order->setUid(md5(rand(1111, 9999) . time())); $order->save(); // link order details $this->shopping_cart = $shopping_cart = $this->getUser()->getShoppingCart(); $this->items = $shopping_cart->getItems(); foreach ($shopping_cart->getItems() as $i => $item) { $od = new OrderDetail(); $od->fromArray(array('product_id' => $item->getId(), 'order_id' => $order->id, 'quantity' => $item->getQuantity(), 'price' => $item->getPrice())); $od->save(); } if (sfConfig::get('app_send_order', false)) { dm::enableMailer(); //send mail $message = $this->getMailer()->compose($_from = dmConfig::get('orderEmail'), $_to = array($order->email, dmConfig::get('orderEmail')), $_subj = '[' . dmConfig::get('siteName') . '] thanks for order'); $message->setBody($this->getPartial('order/mailOrder', array('order' => $order, 'companyName' => dmConfig::get('companyName'), 'companyPhone' => dmConfig::get('companyPhone'), 'siteUrl' => dmConfig::get('siteUrl'), 'siteName' => dmConfig::get('siteName')))); $message->setContentType('text/html'); $this->getMailer()->send($message); } // if send order // clear cart now $shopping_cart->clear(); //redirect to order info $this->redirect($this->getHelper()->link('main/ordershow?uid=' . $order->uid)->getHref()); //$this->redirectBack(); } $this->forms['Order'] = $form; }
public function actionIndex() { $cart = Yii::app()->shoppingCart; $model = new OrderForm(); if (Yii::app()->user->isGuest) { $model->scenario = 'guest_order'; } else { $user = User::model()->findByPk(Yii::app()->user->name); $model->client = Yii::app()->user->name; if (!empty($user->client)) { $model->name = $user->client->name; $model->phone = $user->client->phone; $model->email = $user->client->email; $model->city = $user->client->city; $model->address = $user->client->address; } } if (isset($_POST['OrderForm'])) { $model->attributes = $_POST['OrderForm']; if ($model->validate()) { $order = new Order(); $order->attributes = $model->attributes; $order->created = date('Y-m-d H:i:s'); $tmp = array(); $positions = $cart->getPositions(); foreach ($positions as $k => $position) { $tmp[] = array('item' => preg_split('/_/', $k), 'price' => $position->getPrice(), 'quantity' => $position->getQuantity()); } $order->order = CJSON::encode($tmp); $order->status = L::r_item('orderStatus', 'new'); $order->data = CJSON::encode($order->attributes); if ($order->save()) { Yii::app()->getSession()->add('order', $order); $cart->clear(); $this->redirect(array('basket/done')); } else { $model->addError('error', 'Мы не можем обработать Ваш заказ.'); } } } $this->render('index', array('model' => $model, 'cart' => $cart)); }
$this->apt = new Phorm_Field_Text("Apt #", 5, 10); $this->city = new Phorm_Field_Text("City", 14, 255, array('required')); $this->state = new Phorm_Field_Text("State/province", 3, 4, array('required')); $this->postal = new Phorm_Field_Text("ZIP or postal code", 10, 10, array('required')); $this->country = new Phorm_Field_Text("Country", 24, 40); $this->phone = new Phorm_Field_Text("Phone number", 22, 24); $this->fax = new Phorm_Field_Text("Fax number", 22, 24); $this->email = new Phorm_Field_Email("Email address", 24, 255, array('required')); $this->url = new Phorm_Field_URL("Web page URL", 40, 255); $this->bookname = new Phorm_Field_DropDown("Selected Item", array('item1' => 'Book', 'item2' => 'Chair', 'item3' => 'Table', 'item4' => 'Lamp'), array('required')); $this->quantity = new Phorm_Field_Integer("Quantity", 5, 5, array('required')); $this->message = new Phorm_Field_Textarea("Message", 8, 40); } } //Form validation/processing: $form = new OrderForm(); if ($form->is_valid()) { $email_body = ''; foreach ($form->fields() as $field) { $email_body .= $field->label(false) . ': ' . $field->get_value() . "\n"; } if (CONFIRMATION_EMAIL_TO) { mail(CONFIRMATION_EMAIL_TO, 'New Order has been received!', $email_body); echo 'Thank you for your order!'; } else { echo nl2br($email_body); } exit; } /////////////////////////////////////////////////////////////////////////////// //Display page and form:
/** * returns true if all the data is correct. * * @param array $data The form request data - see OrderForm * @param OrderForm $form The form object submitted on * @return Boolean */ function validatePayment($data, $form) { $this->getDataFromForm($data); $errors = false; if (!$this->validCreditCard($this->CreditCard)) { $form->addErrorMessage('DPSPXPost_CreditCard', _t('DPSPXPost.INVALID_CREDIT_CARD', 'Invalid credit card number.'), 'bad'); $errors = true; } if (strlen($this->NameOnCard) < 3) { $form->addErrorMessage('DPSPXPost_NameOnCard', _t('DPSPXPost.INVALID_NAME_ON_CARD', 'No card name provided.'), 'bad'); $errors = true; } if (!$this->validExpiryDate($this->ExpiryDate)) { $form->addErrorMessage('DPSPXPost_ExpiryDate', _t('DPSPXPost.INVALID_EXPIRY_DATE', 'Expiry date not valid.'), 'bad'); $errors = true; } if (!$this->validCVV($this->CreditCard, $this->CVVNumber)) { $form->addErrorMessage('DPSPXPost_CVVNumber', _t('DPSPXPost.INVALID_CVV_NUMBER', 'Invalid security number.'), 'bad'); $errors = true; } if ($errors) { $form->sessionMessage(_t('DPSPXPost.PLEASE_REVIEW_CARD_DETAILS', 'Please review your card details.'), 'bad'); return false; } return true; }
function processOrder($data, $form, $request) { return parent::processOrder($data, $form, $request); }
EcommerceCurrency::setDecimalDelimiter('.'); EcommerceCurrency::setThousandDelimiter(''); Object::useCustomClass('SS_Datetime', 'I18nDatetime', true); // * * * SHOPPING CART, ORDER, MODIFIERS Order::set_email(null); Order::set_receipt_subject("Shop Sale Information #%d"); Order::set_modifiers(array(), true); Order::set_table_overview_fields(array('ID' => 'Order No', 'Created' => 'Created', 'FirstName' => 'First Name', 'Surname' => 'Surname', 'Total' => 'Total', 'Status' => 'Status')); Order::set_maximum_ignorable_sales_payments_difference(0.01); Order::set_order_id_start_number(0); Order::set_cancel_before_payment(true); Order::set_cancel_before_processing(false); Order::set_cancel_before_sending(false); Order::set_cancel_after_sending(false); OrderForm::set_user_membership_optional(false); OrderForm::set_force_membership(true); OrderManipulation::set_allow_cancelling(false); OrderManipulation::set_allow_paying(false); // * * * PRODUCTS ProductsAndGroupsModelAdmin::set_managed_models(array("Product", "ProductGroup", "ProductVariation", "ProductAttributeType")); Product_Image::set_thumbnail_size(140, 100); Product_Image::set_content_image_width(200); Product_Image::set_large_image_width(200); ProductGroup::set_include_child_groups(true); ProductGroup::set_must_have_price(true); ProductGroup::set_sort_options(array('Title' => 'Alphabetical', 'Price' => 'Lowest Price')); // * * * CHECKOUT ExpiryDateField::set_short_months(true); OrderFormWithoutShippingAddress::set_fixed_country_code(null); OrderFormWithoutShippingAddress::set_postal_code_url("http://www.nzpost.co.nz/Cultures/en-NZ/OnlineTools/PostCodeFinder"); OrderFormWithoutShippingAddress::set_postal_code_label("find postcode");
function testNoMemberOrder() { //TODO: test configuration that deines non-member orders //adjust configuration to allow non member orders OrderForm::set_user_membership_optional(true); OrderForm::set_force_membership(false); $socks = $this->objFromFixture('Product', 'socks'); $this->get(ShoppingCart::add_item_link($socks->ID)); //add a different product $cart = ShoppingCart::current_order(); $this->placeOrder('Donald', 'Duck', '*****@*****.**', '4 The Strand', null, 'Melbourne', null, 'AU'); $order = DataObject::get_by_id('Order', $cart->ID); $this->assertNotNull($order, 'Order exists'); if ($order) { $this->assertEquals($order->Status, 'Unpaid', 'status is now "unpaid"'); $this->assertEquals($order->MemberID, 0, 'No associated member'); $this->assertEquals($order->Total(), 8, 'grand total'); $this->assertEquals($order->TotalOutstanding(), 8, 'total outstanding'); $this->assertEquals($order->TotalPaid(), 0, 'total outstanding'); $this->assertEquals($order->FirstName, 'Donald', 'order first name'); $this->assertEquals($order->Surname, 'Duck', 'order surname'); $this->assertEquals($order->Email, '*****@*****.**', 'order email'); $this->assertEquals($order->Address, '4 The Strand'); $this->assertNull($order->AddressLine2, 'order address2'); $this->assertEquals($order->City, 'Melbourne', 'order city'); $this->assertNull($order->PostalCode, 'order postcode'); $this->assertEquals($order->Country, 'AU', 'order country'); } ShoppingCart::clear(); //cleanup }
Order::set_email("*****@*****.**"); Order::set_receipt_subject("Thank you for your order at www.myshop.com - Order #%d"); Order::set_modifiers(array("FlatTaxModifier", "SimpleShippingModifier")); Order::set_table_overview_fields(array('Total' => 'Total', 'Status' => 'Status')); // Order::set_maximum_ignorable_sales_payments_difference(0.001); //sometimes there are small discrepancies in total (for various reasons)- here you can set the max allowed differences Order::set_order_id_start_number(1234567); //sets a start number for order ID, so that they do not start at one. Order::set_cancel_before_payment(false); Order::set_cancel_before_processing(false); Order::set_cancel_before_sending(false); Order::set_cancel_after_sending(false); OrderForm::set_user_membership_optional(); //optional for user to become a member OrderForm::set_force_membership(); //all users must become members if true, or won't become members if false OrderManipulation::set_allow_cancelling(); //shows a cancel button on the order page OrderManipulation::set_allow_paying(); //shows a payment form // * * * PRODUCTS ProductsAndGroupsModelAdmin::set_managed_models(array("Product", "ProductGroup", "ProductVariation")); Product_Image::set_thumbnail_size(140, 100); Product_Image::set_content_image_width(200); Product_Image::set_large_image_width(200); ProductGroup::set_include_child_groups(true); ProductGroup::set_must_have_price(true); ProductGroup::set_sort_options(array('Title' => 'Alphabetical', 'Price' => 'Lowest Price')); // * * * CHECKOUT ExpiryDateField::set_short_months(true);
function OrderForm() { $order = Cart::get_current_order(); $member = Customer::currentUser() ? Customer::currentUser() : singleton('Customer'); $form = OrderForm::create($this, 'OrderForm')->disableSecurityToken(); //Populate fields the first time form is loaded $form->populateFields(); return $form; }
/** * Returns a form allowing a user to enter their * details to checkout their order. * * @return OrderForm object */ function OrderForm() { $form = OrderForm::create($this, 'OrderForm'); $this->data()->extend('updateOrderForm', $form); //load session data if ($data = Session::get("FormInfo.{$form->FormName()}.data")) { $form->loadDataFrom($data); } return $form; }
static function set_force_membership($force = false) { self::$force_membership = $force; }
public function update(SS_HTTPRequest $request) { if ($request->isPOST()) { $member = Customer::currentUser() ? Customer::currentUser() : singleton('Customer'); $order = Cart::get_current_order(); //Update the Order $order->update($request->postVars()); $order->updateModifications($request->postVars())->write(); $form = OrderForm::create($this->controller, 'OrderForm')->disableSecurityToken(); // $form->validate(); return $form->renderWith('OrderFormCart'); } }