1: <?php
2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25:
26:
27: 28: 29: 30: 31:
32: class Mage_Sales_Helper_Guest extends Mage_Core_Helper_Data
33: {
34: 35: 36:
37: protected $_cookieName = 'guest-view';
38: protected $_lifeTime = 600;
39:
40: 41: 42: 43: 44:
45: public function loadValidOrder()
46: {
47: if (Mage::getSingleton('customer/session')->isLoggedIn()) {
48: Mage::app()->getResponse()->setRedirect(Mage::getUrl('sales/order/history'));
49: return false;
50: }
51:
52: $post = Mage::app()->getRequest()->getPost();
53:
54: $type = '';
55: $incrementId = '';
56: $lastName = '';
57: $email = '';
58: $zip = '';
59: $protectCode = '';
60: $errors = false;
61:
62:
63: $order = Mage::getModel('sales/order');
64:
65: if (empty($post) && !Mage::getSingleton('core/cookie')->get($this->_cookieName)) {
66: Mage::app()->getResponse()->setRedirect(Mage::getUrl('sales/guest/form'));
67: return false;
68: } elseif (!empty($post) && isset($post['oar_order_id']) && isset($post['oar_type'])) {
69: $type = $post['oar_type'];
70: $incrementId = $post['oar_order_id'];
71: $lastName = $post['oar_billing_lastname'];
72: $email = $post['oar_email'];
73: $zip = $post['oar_zip'];
74:
75: if (empty($incrementId) || empty($lastName) || empty($type) || (!in_array($type, array('email', 'zip')))
76: || ($type == 'email' && empty($email)) || ($type == 'zip' && empty($zip))) {
77: $errors = true;
78: }
79:
80: if (!$errors) {
81: $order->loadByIncrementId($incrementId);
82: }
83:
84: if ($order->getId()) {
85: $billingAddress = $order->getBillingAddress();
86: if ((strtolower($lastName) != strtolower($billingAddress->getLastname()))
87: || ($type == 'email'
88: && strtolower($email) != strtolower($billingAddress->getEmail()))
89: || ($type == 'zip'
90: && (strtolower($zip) != strtolower($billingAddress->getPostcode())))
91: ) {
92: $errors = true;
93: }
94: } else {
95: $errors = true;
96: }
97:
98: if (!$errors) {
99: $toCookie = base64_encode($order->getProtectCode());
100: Mage::getSingleton('core/cookie')->set($this->_cookieName, $toCookie, $this->_lifeTime, '/');
101: }
102: } elseif (Mage::getSingleton('core/cookie')->get($this->_cookieName)) {
103: $fromCookie = Mage::getSingleton('core/cookie')->get($this->_cookieName);
104: $protectCode = base64_decode($fromCookie);
105:
106: if (!empty($protectCode)) {
107: $order->loadByAttribute('protect_code', $protectCode);
108:
109: Mage::getSingleton('core/cookie')->renew($this->_cookieName, $this->_lifeTime, '/');
110: } else {
111: $errors = true;
112: }
113: }
114:
115: if (!$errors && $order->getId()) {
116: Mage::register('current_order', $order);
117: return true;
118: }
119:
120: Mage::getSingleton('core/session')->addError(
121: $this->__('Entered data is incorrect. Please try again.')
122: );
123: Mage::app()->getResponse()->setRedirect(Mage::getUrl('sales/guest/form'));
124: return false;
125: }
126:
127: 128: 129: 130: 131:
132: public function getBreadcrumbs($controller)
133: {
134: $breadcrumbs = $controller->getLayout()->getBlock('breadcrumbs');
135: $breadcrumbs->addCrumb(
136: 'home',
137: array(
138: 'label' => Mage::helper('cms')->__('Home'),
139: 'title' => Mage::helper('cms')->__('Go to Home Page'),
140: 'link' => Mage::getBaseUrl()
141: )
142: );
143: $breadcrumbs->addCrumb(
144: 'cms_page',
145: array(
146: 'label' => 'Order Information',
147: 'title' => 'Order Information'
148: )
149: );
150: }
151:
152: }
153: