Example #1
0
 /**
  * Checks the legal age
  *
  * @param   array $data
  * @param   int $customerAddressId
  * @return  Mage_Checkout_Model_Type_Onepage
  */
 public function saveBilling($data, $customerAddressId)
 {
     $result = parent::saveBilling($data, $customerAddressId);
     if (isset($result['error'])) {
         return $result;
     }
     $dobIso = $this->getQuote()->getCustomerDob();
     $dob = new Zend_Date($dobIso, Zend_Date::ISO_8601);
     $legalBirthDay = $dob->add(self::LIMITED_AGE, Zend_Date::YEAR);
     $legal1 = Zend_Date::now()->isLater($legalBirthDay);
     if (!$legal1) {
         // not even limited legal
         $result['error'] = 1;
         $result['message'] = Mage::helper('n98legalage')->__('You are not yet limited contractually capable. You can ask your legal guardian to purchase.');
         return $result;
     }
     $dob = new Zend_Date($dobIso, Zend_Date::ISO_8601);
     $legalBirthDay = $dob->add(self::LEGAL_AGE, Zend_Date::YEAR);
     $legal2 = Zend_Date::now()->isLater($legalBirthDay);
     if (!$legal2) {
         $result['error'] = 1;
         $result['message'] = Mage::helper('n98legalage')->__('You are not yet contractually capable. You can ask your legal guardian to purchase on your behalf.');
         return $result;
     }
     return $result;
 }
 public function __construct()
 {
     //instead of
     //$this->_helper = Mage::helper('checkout');
     parent::__construct();
     $this->_helper = Mage::helper('a2m_customcheckout');
 }
Example #3
0
 public function __construct()
 {
     $this->helper = Mage::helper('gomage_checkout');
     if ($this->helper->getIsAnymoreVersion(1, 4)) {
         return parent::__construct();
     }
 }
Example #4
0
 /**
  * Specify quote payment method
  *
  * @param   array $data
  * @return  array
  */
 public function savePayment($data)
 {
     $return = parent::savePayment($data);
     /** @var TIG_MyParcel2014_Helper_Data $helper */
     $helper = Mage::helper('tig_myparcel');
     $price = $helper->calculatePrice();
     $this->getQuote()->getShippingAddress()->setShippingAmount($price);
     return $return;
 }
 /**
  * @param array $data
  * @param int $customerAddressId
  * @return Mage_Checkout_Model_Type_Onepage
  */
 public function saveBilling($data, $customerAddressId)
 {
     if (isset($data['is_subscribed']) && !empty($data['is_subscribed'])) {
         $this->getCheckout()->setCustomerIsSubscribed(1);
     } else {
         $this->getCheckout()->setCustomerIsSubscribed(0);
     }
     return parent::saveBilling($data, $customerAddressId);
 }
Example #6
0
 public function saveBilling($data, $customerAddressId)
 {
     if (isset($data['is_subscribed']) && !empty($data['is_subscribed'])) {
         Mage::getSingleton('customer/session')->setCustomerIsSubscribed(1);
     } else {
         Mage::getSingleton('customer/session')->setCustomerIsSubscribed(0);
     }
     return parent::saveBilling($data, $customerAddressId);
 }
 public function saveOrder()
 {
     if (Mage::helper('adjdeliverydate')->isOPCEnabled()) {
         $errors = Mage::getModel('adjdeliverydate/step')->process();
         if ($errors) {
             return $errors;
         }
     }
     return parent::saveOrder();
 }
Example #8
0
 public function getQuote()
 {
     $quote = parent::getQuote();
     $action = Mage::app()->getRequest()->getActionName();
     if ('saveOrder' == $action) {
         if (!$quote->validateMinimumAmount()) {
             $quote->setHasError(true);
         }
     }
     return $quote;
 }
 public function saveShippingMethod($shippingMethod)
 {
     $result = parent::saveShippingMethod($shippingMethod);
     if (Mage::helper('smdropship')->dropShipIsActive()) {
         $rate = $this->getQuote()->getShippingAddress()->getShippingRateByCode($shippingMethod);
         if ($rate->getCarrier() == 'dropshipping') {
             $methodDetail = $rate->getMethodDetail();
             $this->getQuote()->getShippingAddress()->setShippingMethodDetail($methodDetail);
         }
     }
     return $result;
 }
Example #10
0
 public function saveBilling($data, $customerAddressId)
 {
     if (empty($data)) {
         return array('error' => -1, 'message' => $this->_helper->__('Invalid data.'));
     }
     if (!$this->getQuote()->getCustomerId() && self::METHOD_REGISTER == $this->getQuote()->getCheckoutMethod()) {
         if ($this->_customerMobileExists($data['telephone'], Mage::app()->getWebsite()->getId())) {
             return array('error' => 1, 'message' => $this->_customerMobileExistsMessage);
         }
     }
     return parent::saveBilling($data, $customerAddressId);
 }
Example #11
0
 /**
  * Create order based on checkout type. Create customer if necessary.
  *
  * @see http://magento.stackexchange.com/questions/4682/magento-multiple-order-on-one-checkout-or-order-splitting
  *
  * @return Mage_Checkout_Model_Type_Onepage
  */
 public function saveOrder()
 {
     $quote = $this->getQuote();
     //TODO: Set config option
     $splitOnMuliWarehouse = true;
     // First build an array with the items split by vendor
     $sortedItems = array();
     foreach ($quote->getAllItems() as $item) {
         $buyRequest = $item->getBuyRequest()->getOptions();
         if (isset($buyRequest['warehouses'])) {
             $warehouses = $buyRequest['warehouses'];
         } else {
             $warehouses = array(Mage_CatalogInventory_Model_Stock::DEFAULT_STOCK_ID => $item->getQty());
         }
         foreach ($warehouses as $stockId => $stockQty) {
             $sortedItems[$stockId][] = array('item' => $item, 'qty' => $stockQty);
         }
     }
     $quote->setWarehouseIds(implode(',', array_keys($sortedItems)));
     if (count($sortedItems) > 1 and $splitOnMuliWarehouse) {
         $orders = array();
         foreach ($sortedItems as $stockId => $stockItems) {
             $itemCollection = $quote->getItemsCollection();
             // Empty quote
             foreach ($quote->getAllItems() as $item) {
                 $itemCollection->removeItemByKey($item->getId());
             }
             foreach ($stockItems as $stockItem) {
                 $item = $stockItem['item'];
                 //Unset id to add item on quote with addItem
                 //$item->setId(null);
                 if ($item->getProductType() == 'simple') {
                     $item->setQty($stockItem['qty']);
                     $item->setWarehouseId($stockId);
                 }
                 //Unset id to add item on quote with addItem
                 //$quote->addItem($item);
                 $itemCollection->addItem($item);
             }
             // Update totals for vendor
             $quote->setTotalsCollectedFlag(false)->collectTotals();
             // Delegate to parent method to place an order for each vendor
             parent::saveOrder();
             $checkoutSession = $this->_checkoutSession;
             $orders[$checkoutSession->getLastOrderId()] = array('url' => $checkoutSession->getRedirectUrl(), 'incrementid' => $checkoutSession->getLastRealOrderId(), 'profileids' => $checkoutSession->setLastRecurringProfileIds());
         }
         return $this;
     } else {
         $quote->setTotalsCollectedFlag(false)->collectTotals();
         return parent::saveOrder();
     }
 }
Example #12
0
 public function saveShippingMethod($shippingMethod)
 {
     if (empty($shippingMethod)) {
         return array('error' => -1, 'message' => Mage::helper('sheepla')->__('Invalid shipping method.'));
     }
     $so = null;
     $sTemp = explode('_', $shippingMethod);
     //is it sheepla's method
     if ($sTemp[0] == 'sheepla') {
         //if so get check if $method is available with current shipping method
         $cString = "sheepla/{$sTemp[1]}_{$sTemp[2]}";
         $conf = Mage::getStoreConfig($cString);
         $_request = Mage::app()->getRequest();
         //read delivery option
         $ire = strip_tags($_request->getParam('sheepla-widget-plinpost-email'));
         $irm = strip_tags($_request->getParam('sheepla-widget-plinpost-paczkomat'));
         $irp = strip_tags($_request->getParam('sheepla-widget-plinpost-phone-number'));
         $ira = strip_tags($_request->getParam('sheepla-widget-plinpost-form-agree-checkbox'));
         $slMetro = strip_tags($_request->getParam('sheepla-widget-rushoplogistics-metro-station'));
         $imPoint = strip_tags($_request->getParam('sheepla-widget-ruimlogistics-paczkomat'));
         $ppPoint = strip_tags($_request->getParam('sheepla-widget-rupickpoint-paczkomat'));
         //$qwPoint =  strip_tags($_request->getParam('sheepla-widget-rupickpoint-metro-station-id'));
         //save sheepla order data
         $so = Mage::getModel('sheepla/order')->load($this->getQuote()->getId(), 'quote_id');
         $so->setQuoteId($this->getQuote()->getId());
         $so->setRequiresSync(1);
         $so->setIsValid(null);
         $so->setLastError(null);
         //save delivery options
         $so->setDoRuShoplogisticsMetro($slMetro);
         $so->setDoRuImPoint($imPoint);
         $so->setDoRuPickPointPoint($ppPoint);
         $so->setDoPlInpostMachineId($irm);
         $so->setDoPlInpostMobile($irp);
         $so->setDoPlInpostEmail($ire);
         $so->setDoPlInpostEmail($ire);
         $so->setDoPlInpostEmail($ire);
         $so->setDoPlInpostEmail($ire);
         $so->save();
         //if this is an inpost shipping add a note
         if (!empty($irm)) {
             $note = Mage::helper('sheepla')->__('Delivery to Inpost pick-up machine:') . $irm;
             $this->getQuote()->setCustomerNote($note);
         }
         //eveything seems to ok, update sheepla order data
         if ($so != null) {
             $so->setIsValid(1);
             $so->save();
         }
     }
     return parent::saveShippingMethod($shippingMethod);
 }
 /**
  * Save billing address information to quote
  * This method is called by One Page Checkout JS (AJAX) while saving the billing information.
  *
  * @param   array $data
  * @param   int $customerAddressId
  * @return  Mage_Checkout_Model_Type_Onepage
  */
 public function saveBilling($data, $customerAddressId)
 {
     //$session = $this->getCustomerSession();
     //$customer = $session->getCustomer();
     $quote = $this->getQuote();
     $email = !empty($data['email']) ? $data['email'] : null;
     try {
         //Mage::getModel('icc_purchases/link_purchases')->canBuy($quote, $email);
     } catch (Exception $e) {
         return array('error' => -1, 'message' => $e->getMessage());
     }
     return parent::saveBilling($data, $customerAddressId);
 }
Example #14
0
 public function saveBilling($data, $customerAddressId)
 {
     $active = Mage::getStoreConfig('j2tonecheckout/default/active', Mage::app()->getStore()->getStoreId());
     if ($active) {
         if (isset($data['is_subscribed']) && !empty($data['is_subscribed'])) {
             //$this->getCheckout()->setCustomerIsSubscribed(1);
             //j2tonecheckout
             Mage::getSingleton('j2tonecheckout/session')->setCustomerIsSubscribed(1);
         } else {
             //$this->getCheckout()->setCustomerIsSubscribed(0);
             Mage::getSingleton('j2tonecheckout/session')->setCustomerIsSubscribed(0);
         }
     }
     return parent::saveBilling($data, $customerAddressId);
 }
Example #15
0
 public function saveBilling($data, $customerAddressId)
 {
     if (isset($data['amcustomerattr'])) {
         // checking unique attributes
         $checkUnique = array();
         $collection = Mage::getModel('eav/entity_attribute')->getCollection();
         $collection->addFieldToFilter('is_user_defined', 1);
         $collection->addFieldToFilter('entity_type_id', Mage::getModel('eav/entity')->setType('customer')->getTypeId());
         foreach ($collection as $attribute) {
             if ($attribute->getIsUnique()) {
                 $translations = $attribute->getStoreLabels();
                 if (isset($translations[Mage::app()->getStore()->getId()])) {
                     $attributeLabel = $translations[Mage::app()->getStore()->getId()];
                 } else {
                     $attributeLabel = $attribute->getFrontend()->getLabel();
                 }
                 $checkUnique[$attribute->getAttributeCode()] = $attributeLabel;
             }
         }
         if ($checkUnique) {
             foreach ($checkUnique as $attributeCode => $attributeLabel) {
                 $customerCollection = Mage::getResourceModel('customer/customer_collection');
                 $customerCollection->addAttributeToSelect($attributeCode);
                 if ($customerCollection->getSize() > 0) {
                     foreach ($customerCollection as $customerWithAttribute) {
                         if ($data['amcustomerattr'][$attributeCode] == $customerWithAttribute->getData($attributeCode)) {
                             $result = array('error' => 1, 'message' => Mage::helper('amcustomerattr')->__('Please specify different value for "%s" attribute. Customer with such value already exists.', $attributeLabel));
                             return $result;
                         }
                     }
                 }
             }
         }
         Mage::getSingleton('checkout/session')->setAmcustomerattr($data['amcustomerattr']);
     }
     return parent::saveBilling($data, $customerAddressId);
 }
Example #16
0
 protected function _prepareGuestQuote()
 {
     parent::_prepareGuestQuote();
     $isSubscribed = Mage::app()->getRequest()->getParam('is_subscribed', false) || Mage::getSingleton('checkout/session')->getAmscheckoutIsSubscribed();
     if ($isSubscribed) {
         $quote = $this->getQuote();
         Mage::getModel('newsletter/subscriber')->subscribe($quote->getBillingAddress()->getEmail());
         Mage::getSingleton('checkout/session')->setAmscheckoutIsSubscribed(true);
     }
 }
Example #17
0
 /**
  * FALLS DIESE KLASSE AUFGRUND EINES KONFLIKTS (VERURSACHT Z.B. DURCH EIN ANDERES ADDON) NICHT AKTIV IST,
  * MUSS DIE KOMPLETTE METHODE IN DIE AKTIVE KLASSE KOPIERT WERDEN. SOLLTE DIE METHODE IN DER AKTIVEN KLASSE
  * BEREITS VORHANDEN SEIN, MUSS DIE 'Mage::dispatchEvent'-ANWEISUNG ANS ENDE DER BEREITS VORHANDENEN METHODE 
  * KOPIERT WERDEN. OB DIESE KLASSE AKTIV IST, KANN NACH INSTALLATION DES BILLPAY-ADDONS MIT HILFE DES 
  * DIAGNOSESKRIPTS, WELCHES UNTER DER FOLGENDEN URL VERFUEGBAR IST, UEBERPRUEFT WERDEN.
  * 
  * http://<Ihr-Magento-Shop>/billpay/diagnostics/checkRewrites
  */
 public function savePayment($data)
 {
     $result = parent::savePayment($data);
     Mage::dispatchEvent('billpay_after_save_payment', array('data' => $data, 'useHTMLFormat' => false, 'expectedDaysTillShipping' => 0));
     return $result;
 }
Example #18
0
 /**
  * Constructor. Fix Onepage model bug with error message private property
  */
 public function __construct()
 {
     parent::__construct();
     $this->_customerEmailExistsMessage = $this->_helper->__('There is already a customer registered using this email address. Please login using this email address or enter a different email address to register your account.');
 }
Example #19
0
 public function saveBilling($data, $customerAddressId)
 {
     if (!isset($data['amcustomerattr'])) {
         return parent::saveBilling($data, $customerAddressId);
     }
     // checking unique attributes
     $checkUnique = array();
     $nameGroupAttribute = '';
     $idGroupSelect = '';
     $collection = Mage::getModel('eav/entity_attribute')->getCollection();
     $filters = array("is_user_defined = 1", "entity_type_id  = " . Mage::getModel('eav/entity')->setType('customer')->getTypeId());
     $collection = Mage::helper('amcustomerattr')->addFilters($collection, 'eav_attribute', $filters);
     /* @
      * setup $checkUnique array('attribute_code','attribute_label')
      */
     foreach ($collection as $attribute) {
         if ($attribute->getIsUnique()) {
             $translations = $attribute->getStoreLabels();
             $storeId = Mage::app()->getStore()->getId();
             $checkUnique[$attribute->getAttributeCode()] = isset($translations[$storeId]) ? $translations[$storeId] : $attribute->getFrontend()->getLabel();
         }
     }
     /* @
      * get attribute code for last attribute with type_internal == 'selectgroup'
      */
     $collection = Mage::getModel('customer/attribute')->getCollection();
     $filters = array("is_user_defined = 1", "entity_type_id  = " . Mage::getModel('eav/entity')->setType('customer')->getTypeId());
     $collection = Mage::helper('amcustomerattr')->addFilters($collection, 'eav_attribute', $filters);
     foreach ($collection as $attribute) {
         if ('selectgroup' == $attribute->getTypeInternal()) {
             $nameGroupAttribute = $attribute->getAttributeCode();
         }
     }
     foreach ($data['amcustomerattr'] as $attributeCode => $attributeValue) {
         if ($attributeCode == $nameGroupAttribute) {
             $idGroupSelect = $attributeValue;
         }
     }
     if ($idGroupSelect) {
         $option = Mage::getModel('eav/entity_attribute_option')->load($idGroupSelect);
         if ($option && $option->getGroupId()) {
             $customer = Mage::getModel('customer/customer');
             $customer->setGroupId($option->getGroupId());
         }
     }
     if (!empty($checkUnique)) {
         foreach ($checkUnique as $attributeCode => $attributeLabel) {
             //skip empty values
             if (!array_key_exists($attributeCode, $data['amcustomerattr']) || !$data['amcustomerattr'][$attributeCode]) {
                 continue;
             }
             $customerCollection = Mage::getResourceModel('customer/customer_collection');
             $customerCollection->addAttributeToFilter($attributeCode, array('eq' => $data['amcustomerattr'][$attributeCode]));
             if ($customerId = Mage::getSingleton('customer/session')->getCustomer()->getId()) {
                 $mainAlias = false !== strpos($customerCollection->getSelect()->__toString(), 'AS `e') ? 'e' : 'main_table';
                 $customerCollection->getSelect()->where($mainAlias . '.entity_id != ?', $customerId);
             }
             if ($customerCollection->getSize() > 0) {
                 $result = array('error' => 1, 'message' => Mage::helper('amcustomerattr')->__('Please specify different value for "%s" attribute. Customer with such value already exists.', $attributeLabel));
                 return $result;
             }
         }
     }
     Mage::getSingleton('checkout/session')->setAmcustomerattr($data['amcustomerattr']);
     return parent::saveBilling($data, $customerAddressId);
 }
Example #20
0
 /**
  * Overiding save order function as we don't want to save order at this stage
  *
  * @return array
  */
 public function saveOrder()
 {
     $paymentType = $this->getQuote()->getPayment()->getMethod();
     if ($paymentType != 'cybersource_soap') {
         return parent::saveOrder();
     }
     $this->validateOrder();
     $billing = $this->getQuote()->getBillingAddress();
     if (!$this->getQuote()->isVirtual()) {
         $shipping = $this->getQuote()->getShippingAddress();
     }
     switch ($this->getQuote()->getCheckoutMethod()) {
         case 'guest':
             if (!$this->getQuote()->isAllowedGuestCheckout()) {
                 Mage::throwException(Mage::helper('checkout')->__('Sorry, guest checkout is not enabled. Please try again or contact store owner.'));
             }
             $this->getQuote()->setCustomerEmail($billing->getEmail())->setCustomerIsGuest(true)->setCustomerGroupId(Mage_Customer_Model_Group::NOT_LOGGED_IN_ID);
             break;
         case 'register':
             $customer = Mage::getModel('customer/customer');
             /* @var $customer Mage_Customer_Model_Customer */
             $customerBilling = $billing->exportCustomerAddress();
             $customer->addAddress($customerBilling);
             if (!$this->getQuote()->isVirtual() && !$shipping->getSameAsBilling()) {
                 $customerShipping = $shipping->exportCustomerAddress();
                 $customer->addAddress($customerShipping);
             }
             if ($this->getQuote()->getCustomerDob() && !$billing->getCustomerDob()) {
                 $billing->setCustomerDob($this->getQuote()->getCustomerDob());
             }
             if ($this->getQuote()->getCustomerTaxvat() && !$billing->getCustomerTaxvat()) {
                 $billing->setCustomerTaxvat($this->getQuote()->getCustomerTaxvat());
             }
             Mage::helper('core')->copyFieldset('checkout_onepage_billing', 'to_customer', $billing, $customer);
             $customer->setPassword($customer->decryptPassword($this->getQuote()->getPasswordHash()));
             $customer->setPasswordHash($customer->hashPassword($customer->getPassword()));
             $this->getQuote()->setCustomer($customer);
             break;
         default:
             $customer = Mage::getSingleton('customer/session')->getCustomer();
             if (!$billing->getCustomerId() || $billing->getSaveInAddressBook()) {
                 $customerBilling = $billing->exportCustomerAddress();
                 $customer->addAddress($customerBilling);
             }
             if (!$this->getQuote()->isVirtual() && (!$shipping->getCustomerId() && !$shipping->getSameAsBilling() || !$shipping->getSameAsBilling() && $shipping->getSaveInAddressBook())) {
                 $customerShipping = $shipping->exportCustomerAddress();
                 $customer->addAddress($customerShipping);
             }
             $customer->setSavedFromQuote(true);
             $customer->save();
             $changed = false;
             if (isset($customerBilling) && !$customer->getDefaultBilling()) {
                 $customer->setDefaultBilling($customerBilling->getId());
                 $changed = true;
             }
             if (!$this->getQuote()->isVirtual() && isset($customerBilling) && !$customer->getDefaultShipping() && $shipping->getSameAsBilling()) {
                 $customer->setDefaultShipping($customerBilling->getId());
                 $changed = true;
             } elseif (!$this->getQuote()->isVirtual() && isset($customerShipping) && !$customer->getDefaultShipping()) {
                 $customer->setDefaultShipping($customerShipping->getId());
                 $changed = true;
             }
             if ($changed) {
                 $customer->save();
             }
     }
     $this->getQuote()->reserveOrderId();
     $convertQuote = Mage::getModel('sales/convert_quote');
     /* @var $convertQuote Mage_Sales_Model_Convert_Quote */
     //$order = Mage::getModel('sales/order');
     if ($this->getQuote()->isVirtual()) {
         $order = $convertQuote->addressToOrder($billing);
     } else {
         $order = $convertQuote->addressToOrder($shipping);
     }
     /* @var $order Mage_Sales_Model_Order */
     $order->setBillingAddress($convertQuote->addressToOrderAddress($billing));
     if (!$this->getQuote()->isVirtual()) {
         $order->setShippingAddress($convertQuote->addressToOrderAddress($shipping));
     }
     $order->setPayment($convertQuote->paymentToOrderPayment($this->getQuote()->getPayment()));
     foreach ($this->getQuote()->getAllItems() as $item) {
         $orderItem = $convertQuote->itemToOrderItem($item);
         if ($item->getParentItem()) {
             $orderItem->setParentItem($order->getItemByQuoteItemId($item->getParentItem()->getId()));
         }
         $order->addItem($orderItem);
     }
     /**
      * We can use configuration data for declare new order status
      */
     Mage::dispatchEvent('checkout_type_onepage_save_order', array('order' => $order, 'quote' => $this->getQuote()));
     // check again, if customer exists
     if ($this->getQuote()->getCheckoutMethod() == 'register') {
         if ($this->_customerEmailExists($customer->getEmail(), Mage::app()->getWebsite()->getId())) {
             Mage::throwException(Mage::helper('checkout')->__('There is already a customer registered using this email address'));
         }
     }
     Mage::getSingleton('checkout/session')->setSecure3d(false);
     $order->place();
     if ($this->getQuote()->getCheckoutMethod() == 'register') {
         $customer->save();
         $customerBillingId = $customerBilling->getId();
         if (!$this->getQuote()->isVirtual()) {
             $customerShippingId = isset($customerShipping) ? $customerShipping->getId() : $customerBillingId;
             $customer->setDefaultShipping($customerShippingId);
         }
         $customer->setDefaultBilling($customerBillingId);
         $customer->save();
         $this->getQuote()->setCustomerId($customer->getId());
         $order->setCustomerId($customer->getId());
         Mage::helper('core')->copyFieldset('customer_account', 'to_order', $customer, $order);
         $billing->setCustomerId($customer->getId())->setCustomerAddressId($customerBillingId);
         if (!$this->getQuote()->isVirtual()) {
             $shipping->setCustomerId($customer->getId())->setCustomerAddressId($customerShippingId);
         }
         if ($customer->isConfirmationRequired()) {
             $customer->sendNewAccountEmail('confirmation');
         } else {
             $customer->sendNewAccountEmail();
         }
     }
     /**
      * a flag to set that there will be redirect to third party after confirmation
      * eg: paypal standard ipn
      */
     $redirectUrl = $this->getQuote()->getPayment()->getOrderPlaceRedirectUrl();
     if (!$redirectUrl) {
         $order->setEmailSent(true);
     }
     if (!$redirectUrl) {
         $order->setState(Mage::getStoreConfig('payment/cybersource_soap/order_status'), true, Mage::helper('cybersource')->__('Payment Successful'), true);
         $order->save();
         //Saving Additional Data
         $payment = $order->getPayment();
         $payment->setAdditionalData(Mage::getSingleton('checkout/session')->getAdditionalData())->save();
         Mage::dispatchEvent('checkout_type_onepage_save_order_after', array('order' => $order, 'quote' => $this->getQuote()));
     }
     /**
      * need to have somelogic to set order as new status to make sure order is not finished yet
      * quote will be still active when we send the customer to paypal
      */
     $this->getCheckout()->setLastQuoteId($this->getQuote()->getId());
     $this->getCheckout()->setLastOrderId($order->getId());
     $this->getCheckout()->setLastRealOrderId($order->getIncrementId());
     $this->getCheckout()->setRedirectUrl($redirectUrl);
     /**
      * we only want to send to customer about new order when there is no redirect to third party
      */
     /*        if(!$redirectUrl){
             	try
             	{
                 	//$order->sendNewOrderEmail();
             	}
                	catch(Exception $e)
                	{
                		Mage::logexception($e);
                	}
             }
     */
     if ($this->getQuote()->getCheckoutMethod() == 'register') {
         /**
          * we need to save quote here to have it saved with Customer Id.
          * so when loginById() executes checkout/session method loadCustomerQuote
          * it would not create new quotes and merge it with old one.
          */
         $this->getQuote()->save();
         if ($customer->isConfirmationRequired()) {
             Mage::getSingleton('checkout/session')->addSuccess(Mage::helper('customer')->__('Account confirmation is required. Please, check your e-mail for confirmation link. To resend confirmation email please <a href="%s">click here</a>.', Mage::helper('customer')->getEmailConfirmationUrl($customer->getEmail())));
         } else {
             Mage::getSingleton('customer/session')->loginById($customer->getId());
         }
     }
     //Setting this one more time like control flag that we haves saved order
     //Must be checkout on success page to show it or not.
     $this->getCheckout()->setLastSuccessQuoteId($this->getQuote()->getId());
     $this->getQuote()->save();
     //echo $this;
     return $this;
 }
Example #21
0
 public function saveBilling($data, $customerAddressId)
 {
     if (isset($data['amcustomerattr'])) {
         // checking unique attributes
         $checkUnique = array();
         $nameGroupAttribute = '';
         $idGroupSelect = '';
         $collection = Mage::getModel('eav/entity_attribute')->getCollection();
         $alias = Mage::helper('amcustomerattr')->getProperAlias($collection->getSelect()->getPart('from'), 'eav_attribute');
         $collection->addFieldToFilter($alias . 'is_user_defined', 1);
         $collection->addFieldToFilter($alias . 'entity_type_id', Mage::getModel('eav/entity')->setType('customer')->getTypeId());
         foreach ($collection as $attribute) {
             if ($attribute->getIsUnique()) {
                 $translations = $attribute->getStoreLabels();
                 if (isset($translations[Mage::app()->getStore()->getId()])) {
                     $attributeLabel = $translations[Mage::app()->getStore()->getId()];
                 } else {
                     $attributeLabel = $attribute->getFrontend()->getLabel();
                 }
                 $checkUnique[$attribute->getAttributeCode()] = $attributeLabel;
             }
         }
         $collection = Mage::getModel('customer/attribute')->getCollection();
         $alias = Mage::helper('amcustomerattr')->getProperAlias($collection->getSelect()->getPart('from'), 'eav_attribute');
         $collection->addFieldToFilter($alias . 'is_user_defined', 1);
         $collection->addFieldToFilter($alias . 'entity_type_id', Mage::getModel('eav/entity')->setType('customer')->getTypeId());
         foreach ($collection as $attribute) {
             if ('selectgroup' == $attribute->getTypeInternal()) {
                 $nameGroupAttribute = $attribute->getAttributeCode();
             }
         }
         foreach ($data['amcustomerattr'] as $attributeCode => $attributeValue) {
             if ($attributeCode == $nameGroupAttribute) {
                 $idGroupSelect = $attributeValue;
             }
         }
         if ($idGroupSelect) {
             $option = Mage::getModel('eav/entity_attribute_option')->load($idGroupSelect);
             if ($option && $option->getGroupId()) {
                 $customer = Mage::getModel('customer/customer');
                 $customer->setGroupId($option->getGroupId());
             }
         }
         if ($checkUnique) {
             foreach ($checkUnique as $attributeCode => $attributeLabel) {
                 //skip empty values
                 if (!$data['amcustomerattr'][$attributeCode]) {
                     continue;
                 }
                 $customerCollection = Mage::getResourceModel('customer/customer_collection');
                 $customerCollection->addAttributeToFilter($attributeCode, array('eq' => $data['amcustomerattr'][$attributeCode]));
                 if ($customerId = Mage::getSingleton('customer/session')->getCustomer()->getId()) {
                     $mainAlias = false !== strpos($customerCollection->getSelect()->__toString(), 'AS `e') ? 'e' : 'main_table';
                     $customerCollection->getSelect()->where($mainAlias . '.entity_id != ?', $customerId);
                 }
                 if ($customerCollection->getSize() > 0) {
                     $result = array('error' => 1, 'message' => Mage::helper('amcustomerattr')->__('Please specify different value for "%s" attribute. Customer with such value already exists.', $attributeLabel));
                     return $result;
                 }
             }
         }
         Mage::getSingleton('checkout/session')->setAmcustomerattr($data['amcustomerattr']);
     }
     return parent::saveBilling($data, $customerAddressId);
 }
Example #22
0
 public function saveOrder()
 {
     if (isset($_POST['fm_fields'])) {
         foreach ($_POST['fm_fields'] as $key => $value) {
             if (substr($key, 0, 3) == 'fm_') {
                 Mage::getModel('fieldsmanager/fieldsmanager')->SaveFieldsdata(substr($key, 3), $value);
             }
         }
     }
     // Mage::getModel('fieldsmanager/fieldsmanager')->SaveToFM();
     return parent::saveOrder();
 }