Sitewards_QuickOrders - Version 0.1.0

Version Notes

First stable release

Download this release

Release Info

Developer Sitewards Magento Team
Extension Sitewards_QuickOrders
Version 0.1.0
Comparing to
See all releases


Version 0.1.0

app/code/community/Sitewards/QuickOrders/Helper/Data.php ADDED
@@ -0,0 +1,55 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * Sitewards_QuickOrders_Helper_Data
5
+ * - Helper containing the checks for
6
+ * - extension is active
7
+ *
8
+ * @category Sitewards
9
+ * @package Sitewards_QuickOrders
10
+ * @copyright Copyright (c) 2014 Sitewards GmbH (http://www.sitewards.com/)
11
+ */
12
+ class Sitewards_QuickOrders_Helper_Data extends Mage_Core_Helper_Abstract
13
+ {
14
+ /**
15
+ * Path for the config for extension active status
16
+ */
17
+ const CONFIG_EXTENSION_ACTIVE = 'quickorders/generalsettings/active';
18
+
19
+ /**
20
+ * Variable for if the extension is active
21
+ *
22
+ * @var bool
23
+ */
24
+ protected $bExtensionActive;
25
+
26
+ /**
27
+ * Check to see if the extension is active
28
+ *
29
+ * @return bool
30
+ */
31
+ public function isExtensionActive()
32
+ {
33
+ if ($this->bExtensionActive === null) {
34
+ $this->bExtensionActive = Mage::getStoreConfigFlag(self::CONFIG_EXTENSION_ACTIVE);
35
+ }
36
+ return $this->bExtensionActive;
37
+ }
38
+
39
+ /**
40
+ * Check to see if the controller can be dispatched
41
+ *
42
+ * @param Mage_Core_Controller_Front_Action $oController
43
+ */
44
+ public function isDispatchAllowed($oController)
45
+ {
46
+ $sLoginUrl = Mage::helper('customer')->getLoginUrl();
47
+
48
+ if (
49
+ !Mage::getSingleton('customer/session')->authenticate($oController, $sLoginUrl)
50
+ || !Mage::helper('sitewards_quickorders')->isExtensionActive()
51
+ ) {
52
+ $oController->setFlag('', $oController::FLAG_NO_DISPATCH, true);
53
+ }
54
+ }
55
+ }
app/code/community/Sitewards/QuickOrders/Test/Helper/Data.php ADDED
@@ -0,0 +1,25 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * Test for class Sitewards_QuickOrders_Helper_Data
5
+ *
6
+ * @category Sitewards
7
+ * @package Sitewards_QuickOrders
8
+ * @copyright Copyright (c) 2014 Sitewards GmbH (http://www.sitewards.com/)
9
+ */
10
+ class Sitewards_QuickOrders_Test_Helper_Data extends EcomDev_PHPUnit_Test_Case
11
+ {
12
+ /**
13
+ * Tests is extension active
14
+ *
15
+ * @test
16
+ * @loadFixture
17
+ */
18
+ public function testIsExtensionActive()
19
+ {
20
+ $this->assertTrue(
21
+ Mage::helper('sitewards_quickorders')->isExtensionActive(),
22
+ 'Extension is not active please check config'
23
+ );
24
+ }
25
+ }
app/code/community/Sitewards/QuickOrders/Test/Helper/Data/fixtures/testIsExtensionActive.yaml ADDED
@@ -0,0 +1,2 @@
 
 
1
+ config:
2
+ default/quickorders/generalsettings/active: 1
app/code/community/Sitewards/QuickOrders/controllers/OrderController.php ADDED
@@ -0,0 +1,124 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * Sitewards_QuickOrders_OrderController
5
+ * - implements actions for quick order form
6
+ *
7
+ * @category Sitewards
8
+ * @package Sitewards_QuickOrders
9
+ * @copyright Copyright (c) 2014 Sitewards GmbH (http://www.sitewards.com/)
10
+ */
11
+ class Sitewards_QuickOrders_OrderController extends Mage_Core_Controller_Front_Action
12
+ {
13
+ /**
14
+ * Check customer authentication and extension flag
15
+ */
16
+ public function preDispatch()
17
+ {
18
+ parent::preDispatch();
19
+ Mage::helper('sitewards_quickorders')->isDispatchAllowed($this);
20
+ }
21
+
22
+ /**
23
+ * Inital form display action
24
+ */
25
+ public function formAction()
26
+ {
27
+ $this->loadLayout();
28
+ $this->_initLayoutMessages('customer/session');
29
+ $this->renderLayout();
30
+ }
31
+
32
+
33
+ /**
34
+ * Submits all the products from the multiple product addition form
35
+ */
36
+ public function submitAction()
37
+ {
38
+ try {
39
+ $oCart = $this->tryAddProducts();
40
+
41
+ if (!$this->getCheckoutSession()->getNoCartRedirect(true)) {
42
+ if (!$oCart->getQuote()->getHasError()) {
43
+ $sSuccessMessage = $this->__('Your product(s) where added to your shopping cart.');
44
+ $this->getCheckoutSession()->addSuccess($sSuccessMessage);
45
+ }
46
+ $this->_redirect('checkout/cart');
47
+ }
48
+ } catch (Mage_Core_Exception $e) {
49
+ $this->getCustomerSession()->addError(
50
+ $this->__('Please enter valid product sku.')
51
+ );
52
+
53
+ $this->_redirect('quickorders/order/form');
54
+ }
55
+ }
56
+
57
+ /**
58
+ * Get checkout session model instance
59
+ *
60
+ * @return Mage_Checkout_Model_Session
61
+ */
62
+ protected function getCheckoutSession()
63
+ {
64
+ return Mage::getSingleton('checkout/session');
65
+ }
66
+
67
+ /**
68
+ * Get the current customer session
69
+ *
70
+ * @return Mage_Customer_Model_Session
71
+ */
72
+ protected function getCustomerSession()
73
+ {
74
+ return Mage::getSingleton('customer/session');
75
+ }
76
+
77
+ /**
78
+ * Retrieve shopping cart model object
79
+ *
80
+ * @return Mage_Checkout_Model_Cart
81
+ */
82
+ protected function getCart()
83
+ {
84
+ return Mage::getSingleton('checkout/cart');
85
+ }
86
+
87
+ /**
88
+ * Try to add products to the cart from the request
89
+ *
90
+ * @return Mage_Checkout_Model_Cart
91
+ */
92
+ protected function tryAddProducts()
93
+ {
94
+ $oRequest = $this->getRequest();
95
+ $aSkus = array_filter($oRequest->getParam('sku'));
96
+ $aQtys = $oRequest->getParam('qty');
97
+
98
+ foreach ($aSkus as $iKey => $sSku) {
99
+ $iQuantity = isset($aQtys[$iKey]) ? $aQtys[$iKey] : 1;
100
+ $this->addSingleProduct($sSku, $iQuantity);
101
+ }
102
+ $oCart = $this->getCart();
103
+ $oCart->save();
104
+
105
+ $this->getCheckoutSession()->setCartWasUpdated(true);
106
+ return $oCart;
107
+ }
108
+
109
+ /**
110
+ * Try to add a given product to the cart via sku
111
+ *
112
+ * @param string $sSku
113
+ * @param int $iQuantity
114
+ */
115
+ protected function addSingleProduct($sSku, $iQuantity)
116
+ {
117
+ /** @var Mage_Catalog_Model_Product $oProduct */
118
+ $oProduct = Mage::getModel('catalog/product');
119
+ $iProductId = $oProduct->getIdBySku($sSku);
120
+ if (isset($iProductId)) {
121
+ $this->getCart()->addProduct($iProductId, $iQuantity);
122
+ }
123
+ }
124
+ }
app/code/community/Sitewards/QuickOrders/controllers/ProductController.php ADDED
@@ -0,0 +1,63 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * Sitewards_QuickOrders_ProductController
5
+ * - implements infoAction to validate a product request by sku
6
+ *
7
+ * @category Sitewards
8
+ * @package Sitewards_QuickOrders
9
+ * @copyright Copyright (c) 2013 Sitewards GmbH (http://www.sitewards.com/)
10
+ */
11
+ class Sitewards_QuickOrders_ProductController extends Mage_Core_Controller_Front_Action
12
+ {
13
+ /**
14
+ * Check customer authentication and extension flag
15
+ */
16
+ public function preDispatch()
17
+ {
18
+ parent::preDispatch();
19
+ Mage::helper('sitewards_quickorders')->isDispatchAllowed($this);
20
+ }
21
+
22
+ /**
23
+ * gets a sku as input parameter
24
+ * sets JSON response with product data if it is allowed to be viewed
25
+ */
26
+ public function infoAction()
27
+ {
28
+ $sSku = $this->getRequest()->getParam('sku');
29
+
30
+ /* @var Mage_Catalog_Model_Product $oProduct */
31
+ $oProduct = Mage::getModel('catalog/product')->loadByAttribute('sku', $sSku);
32
+ if ($this->isProductActive($oProduct)) {
33
+ $sResponse = json_encode(
34
+ array(
35
+ 'result' => 0,
36
+ 'sku' => $oProduct->getSku(),
37
+ 'name' => $oProduct->getName(),
38
+ 'price' => Mage::helper('core')->currency($oProduct->getPrice()),
39
+ 'qty' => $oProduct->getStockItem()->getMinSaleQty(),
40
+ )
41
+ );
42
+ $this->getResponse()->setHeader('Content-type', 'text/json');
43
+ $this->getResponse()->setBody($sResponse);
44
+ } else {
45
+ $this->getResponse()->setHttpResponseCode(404);
46
+ }
47
+ }
48
+
49
+ /**
50
+ * Check to see if the product is active on the current website
51
+ *
52
+ * @param Mage_Catalog_Model_Product $oProduct
53
+ * @return bool
54
+ */
55
+ protected function isProductActive($oProduct)
56
+ {
57
+ $aCurrentWebsiteId = Mage::app()->getStore()->getWebsiteId();
58
+ return $oProduct
59
+ && $oProduct->getId()
60
+ && is_array($oProduct->getWebsiteIds())
61
+ && in_array($aCurrentWebsiteId, $oProduct->getWebsiteIds());
62
+ }
63
+ }
app/code/community/Sitewards/QuickOrders/etc/adminhtml.xml ADDED
@@ -0,0 +1,33 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <!--
3
+ /**
4
+ * adminhtml.xml
5
+ * - create acl for this module
6
+ *
7
+ * @category Sitewards
8
+ * @package Sitewards_QuickOrders
9
+ * @copyright Copyright (c) 2014 Sitewards GmbH (http://www.sitewards.com/)
10
+ */
11
+ -->
12
+ <config>
13
+ <acl>
14
+ <resources>
15
+ <admin>
16
+ <children>
17
+ <system>
18
+ <children>
19
+ <config>
20
+ <children>
21
+ <quickorders translate="title" module="sitewards_quickorders">
22
+ <title>Quick Orders</title>
23
+ <sort_order>50</sort_order>
24
+ </quickorders>
25
+ </children>
26
+ </config>
27
+ </children>
28
+ </system>
29
+ </children>
30
+ </admin>
31
+ </resources>
32
+ </acl>
33
+ </config>
app/code/community/Sitewards/QuickOrders/etc/config.xml ADDED
@@ -0,0 +1,71 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <!--
3
+ /**
4
+ * config.xml
5
+ * - set-up module
6
+ *
7
+ * @category Sitewards
8
+ * @package Sitewards_QuickOrders
9
+ * @copyright Copyright (c) 2014 Sitewards GmbH (http://www.sitewards.com/)
10
+ */
11
+ -->
12
+ <config>
13
+ <modules>
14
+ <Sitewards_QuickOrders>
15
+ <version>0.1.0</version>
16
+ </Sitewards_QuickOrders>
17
+ </modules>
18
+ <global>
19
+ <blocks>
20
+ <sitewards_quickorders>
21
+ <class>Sitewards_QuickOrders_Block</class>
22
+ </sitewards_quickorders>
23
+ </blocks>
24
+ <helpers>
25
+ <sitewards_quickorders>
26
+ <class>Sitewards_QuickOrders_Helper</class>
27
+ </sitewards_quickorders>
28
+ </helpers>
29
+ </global>
30
+ <frontend>
31
+ <routers>
32
+ <Sitewards_QuickOrders>
33
+ <use>standard</use>
34
+ <args>
35
+ <module>Sitewards_QuickOrders</module>
36
+ <frontName>quickorders</frontName>
37
+ </args>
38
+ </Sitewards_QuickOrders>
39
+ </routers>
40
+ <translate>
41
+ <modules>
42
+ <Sitewards_QuickOrders>
43
+ <files>
44
+ <default>Sitewards_QuickOrders.csv</default>
45
+ </files>
46
+ </Sitewards_QuickOrders>
47
+ </modules>
48
+ </translate>
49
+ <layout>
50
+ <updates>
51
+ <sitewards_quickorders>
52
+ <file>sitewards/quickorders.xml</file>
53
+ </sitewards_quickorders>
54
+ </updates>
55
+ </layout>
56
+ </frontend>
57
+ <default>
58
+ <quickorders>
59
+ <generalsettings>
60
+ <active>0</active>
61
+ </generalsettings>
62
+ </quickorders>
63
+ </default>
64
+ <phpunit>
65
+ <suite>
66
+ <modules>
67
+ <Sitewards_QuickOrders/>
68
+ </modules>
69
+ </suite>
70
+ </phpunit>
71
+ </config>
app/code/community/Sitewards/QuickOrders/etc/system.xml ADDED
@@ -0,0 +1,47 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <!--
3
+ /**
4
+ * sytem.xml
5
+ * - create admin config tab,
6
+ * - assign admin config fields to sections
7
+ *
8
+ * @category Sitewards
9
+ * @package Sitewards_QuickOrders
10
+ * @copyright Copyright (c) 2014 Sitewards GmbH (http://www.sitewards.com/)
11
+ */
12
+ -->
13
+ <config>
14
+ <sections>
15
+ <quickorders translate="label" module="sitewards_quickorders">
16
+ <label>Quick Orders</label>
17
+ <tab>customer</tab>
18
+ <frontend_type>text</frontend_type>
19
+ <sort_order>990</sort_order>
20
+ <show_in_default>1</show_in_default>
21
+ <show_in_website>1</show_in_website>
22
+ <show_in_store>1</show_in_store>
23
+ <groups>
24
+ <generalsettings translate="label">
25
+ <label>General settings</label>
26
+ <frontend_type>text</frontend_type>
27
+ <sort_order>1</sort_order>
28
+ <show_in_default>1</show_in_default>
29
+ <show_in_website>1</show_in_website>
30
+ <show_in_store>1</show_in_store>
31
+ <fields>
32
+ <active translate="label,comment">
33
+ <label>Enable Quick Orders Form</label>
34
+ <frontend_type>select</frontend_type>
35
+ <source_model>adminhtml/system_config_source_yesno</source_model>
36
+ <sort_order>1</sort_order>
37
+ <show_in_default>1</show_in_default>
38
+ <show_in_website>1</show_in_website>
39
+ <show_in_store>1</show_in_store>
40
+ <comment><![CDATA[Enable or disable extension.]]></comment>
41
+ </active>
42
+ </fields>
43
+ </generalsettings>
44
+ </groups>
45
+ </quickorders>
46
+ </sections>
47
+ </config>
app/design/frontend/base/default/layout/sitewards/quickorders.xml ADDED
@@ -0,0 +1,40 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0" ?>
2
+ <!--
3
+ /**
4
+ * layout.xml
5
+ * - add the option to the checkout page in the shipping methods additional block,
6
+ * - Add the delivery date to all the order and print pages in the customer section
7
+ *
8
+ * @category Sitewards
9
+ * @package Sitewards_QuickOrders
10
+ * @copyright Copyright (c) 2014 Sitewards GmbH (http://www.sitewards.com/)
11
+ */
12
+ -->
13
+ <layout version="0.1.0">
14
+ <customer_account>
15
+ <reference name="customer_account_navigation">
16
+ <action method="addLink" ifconfig="quickorders/generalsettings/active" translate="label"
17
+ module="sitewards_quickorders">
18
+ <name>order_form</name>
19
+ <path>quickorders/order/form</path>
20
+ <label>Quick Order Form</label>
21
+ </action>
22
+ </reference>
23
+ </customer_account>
24
+ <sitewards_quickorders_order_form translate="label" module="sitewards_quickorders">
25
+ <label>Qucik Order Form</label>
26
+ <update handle="customer_account"/>
27
+ <reference name="my.account.wrapper">
28
+ <block type="core/template" name="order_form"
29
+ template="sitewards/quickorders/order/form.phtml"/>
30
+ </reference>
31
+ <reference name="head">
32
+ <action method="addJs">
33
+ <script>sitewards/quickorders.js</script>
34
+ </action>
35
+ <action method="addCss">
36
+ <name>css/sitewards/quickorders.css</name>
37
+ </action>
38
+ </reference>
39
+ </sitewards_quickorders_order_form>
40
+ </layout>
app/design/frontend/base/default/template/sitewards/quickorders/order/form.phtml ADDED
@@ -0,0 +1,42 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php echo $this->getMessagesBlock()->getGroupedHtml() ?>
2
+ <?php $oHelper = Mage::helper('sitewards_quickorders') ?>
3
+ <ul class="messages" style="display: none;">
4
+ <li class="error-msg">
5
+ <ul>
6
+ <li></li>
7
+ </ul>
8
+ </li>
9
+ </ul>
10
+ <div class="fieldset">
11
+ <form method="POST" id="order_form" action="<?php echo $this->getUrl('quickorders/order/submit'); ?>">
12
+ <input type="hidden" name="form_key" value="<?php echo Mage::getSingleton('core/session')->getFormKey(); ?>"/>
13
+ <table>
14
+ <thead>
15
+ <tr>
16
+ <th><?php echo $oHelper->__('SKU'); ?></th>
17
+ <th><?php echo $oHelper->__('Name'); ?></th>
18
+ <th><?php echo $oHelper->__('Price'); ?></th>
19
+ <th><?php echo $oHelper->__('Quantity'); ?></th>
20
+ <th><?php echo $oHelper->__('Action'); ?></th>
21
+ </tr>
22
+ </thead>
23
+ <tbody>
24
+ <tr class="product">
25
+ <td><input type="text" name="sku[]" class="sku input-text"/></td>
26
+ <td class="name"></td>
27
+ <td class="price"></td>
28
+ <td><input type="text" name="qty[]" class="qty input-text" disabled="disabled"/></td>
29
+ <td><a class="remove"><?php echo $oHelper->__('Remove this entry'); ?></a></td>
30
+ </tr>
31
+ </tbody>
32
+ </table>
33
+ <input type="submit" value="<?php echo $oHelper->__('Submit Data') ?>"
34
+ title="<?php echo $oHelper->__('Submit Data') ?>"/>
35
+ </form>
36
+ <div class="invisible">
37
+ <img class="loading" src="<?php echo $this->getSkinUrl('images/sitewards/quickorders/loading.gif'); ?>"/>
38
+ </div>
39
+ </div>
40
+ <script type="text/javascript">
41
+ Translator.add('The product does not exist.', '<?php echo $oHelper->__('The product does not exist.')?>');
42
+ </script>
app/etc/modules/Sitewards_QuickOrders.xml ADDED
@@ -0,0 +1,25 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <!--
3
+ /**
4
+ * Sitewards_QuickOrders.xml
5
+ * - Activate module,
6
+ * - Specify code pool,
7
+ * - Set-up dependencies
8
+ *
9
+ * @category Sitewards
10
+ * @package Sitewards_QuickOrders
11
+ * @copyright Copyright (c) 2014 Sitewards GmbH (http://www.sitewards.com/)
12
+ */
13
+ -->
14
+ <config>
15
+ <modules>
16
+ <Sitewards_QuickOrders>
17
+ <active>true</active>
18
+ <codePool>community</codePool>
19
+ <depends>
20
+ <Mage_Catalog/>
21
+ <Mage_Checkout/>
22
+ </depends>
23
+ </Sitewards_QuickOrders>
24
+ </modules>
25
+ </config>
app/locale/de_DE/Sitewards_QuickOrders.csv ADDED
@@ -0,0 +1,15 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ "Quick Orders","Quick Orders"
2
+ "General settings","Allgemeine Einstellungen"
3
+ "Enable Quick Orders Form","Enable Quick Orders Form"
4
+ "Enable or disable extension.","Aktivieren oder Deaktivieren der Extension."
5
+ "Your product(s) where added to your shopping cart.","Your product(s) where added to your shopping cart."
6
+ "Please enter valid product sku.","Bitte geben Sie eine gültige SKU an."
7
+ "The product does not exist.","Dieses Produkt ist nicht vorhanden."
8
+ "Remove this entry","Eintrag entfernen"
9
+ "Submit Data","Daten Senden"
10
+ "Quick Order Form","Schnellbestellformular"
11
+ "SKU","Artikelnummer"
12
+ "Name","Name"
13
+ "Price","Preis"
14
+ "Quantity","Anzahl"
15
+ "Action","Aktion"
app/locale/en_US/Sitewards_QuickOrders.csv ADDED
@@ -0,0 +1,10 @@
 
 
 
 
 
 
 
 
 
 
1
+ "Quick Orders","Quick Orders"
2
+ "General settings","General settings"
3
+ "Enable Quick Orders Form","Enable Quick Orders Form"
4
+ "Enable or disable extension.","Enable or disable extension."
5
+ "Your product(s) where added to your shopping cart.","Your product(s) where added to your shopping cart."
6
+ "Please enter valid product sku.","Please enter valid product sku."
7
+ "The product does not exist.","The product does not exist."
8
+ "Quick Order Form","Quick Order Form"
9
+ "Remove this entry","Remove this entry"
10
+ "Submit Data","Submit Data"
js/sitewards/quickorders.js ADDED
@@ -0,0 +1,218 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ document.observe(
2
+ 'dom:loaded',
3
+ /**
4
+ * initializes first product
5
+ */
6
+ function() {
7
+ var oProduct = new OrderProduct($$('form#order_form .product')[0]);
8
+ }
9
+ );
10
+
11
+ /**
12
+ * presentation of a product row
13
+ */
14
+ var OrderProduct = Class.create(
15
+ {
16
+ /**
17
+ * prototype element of the .product element
18
+ */
19
+ _oLine: null,
20
+
21
+ /**
22
+ * URL of loading image
23
+ */
24
+ _sLoadingImage: null,
25
+
26
+ /**
27
+ * initializes observer for sku
28
+ *
29
+ * @param oLine
30
+ */
31
+ initialize: function (oLine) {
32
+ if (typeof oLine == 'undefined') {
33
+ return;
34
+ }
35
+ this._oLine = oLine;
36
+ this.getElement('input.sku').observe(
37
+ 'change',
38
+ this._onChangeSku.bind(this)
39
+ );
40
+ this.getElement('.qty').style.display = 'none';
41
+ this._sLoadingImage = $$('.sitewards-quickorders-order-form .loading').first().src;
42
+
43
+ var that = this;
44
+ this.getElement('.remove')
45
+ .observe('click', function (oEvent) {
46
+ that._onRemove();
47
+ oEvent.preventDefault();
48
+ return false;
49
+ })
50
+ .hide()
51
+ ;
52
+ },
53
+
54
+ /**
55
+ * displays more information about product, if allowed
56
+ *
57
+ * @private
58
+ */
59
+ _onChangeSku: function () {
60
+ new Ajax.Request('/quickorders/product/info', {
61
+ method: 'get',
62
+ parameters: {
63
+ 'sku' : this.getElement('input.sku').value
64
+ },
65
+ requestHeaders: {Accept: 'application/json'},
66
+ onSuccess: this._onSuccess.bind(this),
67
+ onFailure: this._onFailure.bind(this)
68
+ });
69
+ this.getElement('.name').update('<img src="'+this._sLoadingImage+'">');
70
+ this.getElement('.qty').style.display = 'none';
71
+ },
72
+
73
+ /**
74
+ * returns element of this product element
75
+ *
76
+ * @param sSelector
77
+ * @returns {*}
78
+ */
79
+ getElement: function (sSelector) {
80
+ return this._oLine.down(sSelector);
81
+ },
82
+
83
+ /**
84
+ * duplicates current line
85
+ *
86
+ * @private
87
+ */
88
+ _duplicateLine: function () {
89
+ var oParent = this._oLine.up();
90
+ oParent.insert(this._oLine.outerHTML);
91
+ var oProduct = new OrderProduct(oParent.childElements().last());
92
+ oProduct._reset();
93
+ },
94
+
95
+ /**
96
+ * displaysinformation about product
97
+ *
98
+ * @param transport
99
+ * @private
100
+ */
101
+ _onSuccess: function(transport) {
102
+ this._clearMessages();
103
+ var oResponse = transport.responseText.evalJSON(true);
104
+ if (oResponse.result === 0) {
105
+ var oQty = this.getElement('input.qty');
106
+
107
+ oQty.value = Math.max(1, oResponse.qty);
108
+ oQty.disabled = false;
109
+ this.getElement('.name').update(oResponse.name);
110
+ this.getElement('.price').update(oResponse.price);
111
+ if (this._hasEmptyLineInForm() === false) {
112
+ this._duplicateLine();
113
+ }
114
+ this.getElement('.qty').style.display = 'block';
115
+ oQty.focus();
116
+ oQty.select();
117
+
118
+ if (this.getElement('input.sku').value.length > 0) {
119
+ this.getElement('.remove').show();
120
+ }
121
+ } else {
122
+ this._reset();
123
+ this.getElement('input.sku').value = '';
124
+ this._showMessage(oResponse.error);
125
+ this.getElement('input.sku').focus();
126
+ }
127
+ },
128
+
129
+ /**
130
+ * Show standard magento message
131
+ *
132
+ * @param sText
133
+ * @param sType
134
+ * @private
135
+ */
136
+ _showMessage : function (sText) {
137
+ $$('.messages')[0].style.display = 'block';
138
+ $$('.messages>li>ul>li')[0].update(sText);
139
+ },
140
+
141
+ /**
142
+ * Remove all messages
143
+ *
144
+ * @private
145
+ */
146
+ _clearMessages : function () {
147
+ $$('.messages>li>ul>li')[0].update('');
148
+ $$('.messages')[0].style.display = 'none';
149
+ },
150
+
151
+ /**
152
+ * Determines if there is an empty line in the form
153
+ *
154
+ * @return {Boolean} true if there is an empty line
155
+ * @private
156
+ */
157
+ _hasEmptyLineInForm : function () {
158
+ var aLines = this._oLine.up('tbody').select('tr');
159
+ for (var i=0; i < aLines.length; i++) {
160
+ var oInput = $(aLines[i]).select('input').first();
161
+ if (oInput.value === '') {
162
+ return true;
163
+ }
164
+ }
165
+ return false;
166
+ },
167
+
168
+ /**
169
+ * resets information about product
170
+ *
171
+ * @private
172
+ */
173
+ _reset: function () {
174
+ this.getElement('input.qty').update('');
175
+ this.getElement('input.qty').disabled = 'disabled';
176
+ this.getElement('.name').update('');
177
+ this.getElement('.price').update('');
178
+ },
179
+
180
+ /**
181
+ * remove last empty row after a failed ajax request, except current row is last row
182
+ *
183
+ * @private
184
+ */
185
+ _removeEmptyRows: function () {
186
+ var oLastLine = this._oLine.up().childElements().last();
187
+ if (oLastLine != this._oLine) {
188
+ oLastLine.remove();
189
+ }
190
+ },
191
+
192
+ /**
193
+ * removes the line from the form
194
+ *
195
+ * @private
196
+ */
197
+ _onRemove: function () {
198
+ var oLinesContainer = this._oLine.up();
199
+ this._oLine.remove();
200
+ // hide "remove line" if only one line is left
201
+ if (oLinesContainer.childElements().length <= 1) {
202
+ oLinesContainer.down('.remove').hide();
203
+ }
204
+ },
205
+
206
+ /**
207
+ * called on ajax request failure
208
+ *
209
+ * @private
210
+ */
211
+ _onFailure: function () {
212
+ this._reset();
213
+ this._removeEmptyRows();
214
+ this._showMessage(Translator.translate('The product does not exist.'));
215
+ this.getElement('.name').focus();
216
+ }
217
+ }
218
+ );
package.xml ADDED
@@ -0,0 +1,23 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <package>
3
+ <name>Sitewards_QuickOrders</name>
4
+ <version>0.1.0</version>
5
+ <stability>stable</stability>
6
+ <license uri="http://www.opensource.org/licenses/gpl-license.php">GPL</license>
7
+ <channel>community</channel>
8
+ <extends/>
9
+ <summary>The Sitewards QuickOrders extension adds a new form to the customer section that allows a user to add multiple products to the cart via sku.</summary>
10
+ <description>The Sitewards QuickOrders extension adds a new form to the customer section that allows a user to add multiple products to the cart via sku.&#xD;
11
+ &#xD;
12
+ Features&#xD;
13
+ &#xD;
14
+ - Adds new form to the customer account section&#xD;
15
+ - Form allows to add multiple products to the cart via sku</description>
16
+ <notes>First stable release</notes>
17
+ <authors><author><name>Sitewards Magento Team</name><user>sitewards</user><email>magento@sitewards.com</email></author></authors>
18
+ <date>2014-06-23</date>
19
+ <time>10:16:20</time>
20
+ <contents><target name="magecommunity"><dir name="Sitewards"><dir name="QuickOrders"><dir name="Helper"><file name="Data.php" hash="db972aea00ca57e65b84a6cf6dd47d95"/></dir><dir name="Test"><dir name="Helper"><dir name="Data"><dir name="fixtures"><file name="testIsExtensionActive.yaml" hash="4154fdddf3a247afb75a5b6a288da480"/></dir></dir><file name="Data.php" hash="cf0419059980b0131a30d669dd877b17"/></dir></dir><dir name="controllers"><file name="OrderController.php" hash="4cdbeefa41e3cc5673ad6292c1cd3d6e"/><file name="ProductController.php" hash="f5e2a22d0975f5c74fb5dcad9a37a2dc"/></dir><dir name="etc"><file name="adminhtml.xml" hash="c28626e802835131cb9d2ea9bde4c2d6"/><file name="config.xml" hash="a189f1ea9ebdd71016fc58918e51d5b1"/><file name="system.xml" hash="cce3940ac94c8f7099a3565d60ede3b7"/></dir></dir></dir></target><target name="mageetc"><dir name="modules"><file name="Sitewards_QuickOrders.xml" hash="bbd5ff9ca2de18cb1b7b0ef5f7d9cc26"/></dir></target><target name="magelocale"><dir name="de_DE"><file name="Sitewards_QuickOrders.csv" hash="22b165d76d96e661e53b69347740507f"/></dir><dir name="en_US"><file name="Sitewards_QuickOrders.csv" hash="8106f736e238f085feaf0f0caef989b6"/></dir></target><target name="magedesign"><dir name="frontend"><dir name="base"><dir name="default"><dir name="template"><dir name="sitewards"><dir name="quickorders"><dir name="order"><file name="form.phtml" hash="7822738d2b88173b7ffad3e66a1b696e"/></dir></dir></dir></dir><dir name="layout"><dir name="sitewards"><file name="quickorders.xml" hash="777e96fc715ef599148c4c02fbd73c90"/></dir></dir></dir></dir></dir></target><target name="mage"><dir name="js"><dir name="sitewards"><file name="quickorders.js" hash="fb5de43cb4ff4716e6724fdec57a2a81"/></dir></dir></target><target name="mageskin"><dir name="frontend"><dir name="base"><dir name="default"><dir name="images"><dir name="sitewards"><dir name="quickorders"><file name="loading.gif" hash="1836c963dec1eb6dab0e0a41b8121cd3"/></dir></dir></dir><dir name="css"><dir name="sitewards"><file name="quickorders.css" hash="e23e7597f0c20ff39caf48db7d51df90"/></dir></dir></dir></dir></dir></target></contents>
21
+ <compatible/>
22
+ <dependencies><required><php><min>5.3.0</min><max>6.0.0</max></php></required></dependencies>
23
+ </package>
skin/frontend/base/default/css/sitewards/quickorders.css ADDED
@@ -0,0 +1,21 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ .sitewards-quickorders-order-form TABLE TR TD,
2
+ .sitewards-quickorders-order-form THEAD TR TH {
3
+ padding-right: 20px;
4
+ padding-bottom: 10px;
5
+ }
6
+
7
+ .sitewards-quickorders-order-form THEAD TR TH {
8
+ font-weight: bold;
9
+ }
10
+
11
+ .sitewards-quickorders-order-form .price {
12
+ text-align: right;
13
+ }
14
+
15
+ .sitewards-quickorders-order-form .invisible {
16
+ display: none;
17
+ }
18
+
19
+ .sitewards-quickorders-order-form A {
20
+ cursor: pointer;
21
+ }
skin/frontend/base/default/images/sitewards/quickorders/loading.gif ADDED
Binary file