sitewards_giveaway - Version 1.0.2

Version Notes

Fixed problems with adding products to shopping cart.
Now extension requires php 5.3 and later.

Download this release

Release Info

Developer Sitewards Magento Team
Extension sitewards_giveaway
Version 1.0.2
Comparing to
See all releases


Code changes from version 1.0.1 to 1.0.2

app/code/community/Sitewards/Giveaway/Block/Checkout/Cart/Sidebar.php CHANGED
@@ -8,22 +8,23 @@
8
  * @package Sitewards_Giveaway
9
  * @copyright Copyright (c) 2012 Sitewards GmbH (http://www.sitewards.com/de/)
10
  */
11
- class Sitewards_Giveaway_Block_Checkout_Cart_Sidebar extends Mage_Checkout_Block_Cart_Sidebar {
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
12
 
13
- /**
14
- * Checks if customer can check out
15
- * with his cart
16
- *
17
- * @return bool
18
- */
19
- public function isPossibleOnepageCheckout(){
20
- $oGiveawayHelper = Mage::helper('sitewards_giveaway');
21
- $bValidCart = $oGiveawayHelper->isCartValidForCheckout();
22
- if ($bValidCart) {
23
- return parent::isPossibleOnepageCheckout();
24
- } else {
25
- return false;
26
- }
27
-
28
- }
29
- }
8
  * @package Sitewards_Giveaway
9
  * @copyright Copyright (c) 2012 Sitewards GmbH (http://www.sitewards.com/de/)
10
  */
11
+ class Sitewards_Giveaway_Block_Checkout_Cart_Sidebar extends Mage_Checkout_Block_Cart_Sidebar
12
+ {
13
+ /**
14
+ * Checks if customer can check out
15
+ * with his cart
16
+ *
17
+ * @return bool
18
+ */
19
+ public function isPossibleOnepageCheckout()
20
+ {
21
+ $oGiveawayHelper = Mage::helper('sitewards_giveaway');
22
+ $bValidCart = $oGiveawayHelper->isCartValidForCheckout();
23
+ if ($bValidCart) {
24
+ return parent::isPossibleOnepageCheckout();
25
+ } else {
26
+ return false;
27
+ }
28
 
29
+ }
30
+ }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
app/code/community/Sitewards/Giveaway/Block/Checkout/Links.php CHANGED
@@ -8,21 +8,22 @@
8
  * @package Sitewards_Giveaway
9
  * @copyright Copyright (c) 2012 Sitewards GmbH (http://www.sitewards.com/de/)
10
  */
11
- class Sitewards_Giveaway_Block_Checkout_Links extends Mage_Checkout_Block_Links {
12
-
13
- /**
14
- * Checks if customer can proceed to checkout and
15
- * if so, adds checkout link to the top nav
16
- *
17
- * @return Sitewards_Giveaway_Block_Checkout_Links
18
- */
19
- public function addCheckoutLink(){
20
- $oGiveawayHelper = Mage::helper('sitewards_giveaway');
21
- $bValidCart = $oGiveawayHelper->isCartValidForCheckout();
22
- if ($bValidCart) {
23
- return parent::addCheckoutLink();
24
- } else {
25
- return $this;
26
- }
27
- }
28
- }
 
8
  * @package Sitewards_Giveaway
9
  * @copyright Copyright (c) 2012 Sitewards GmbH (http://www.sitewards.com/de/)
10
  */
11
+ class Sitewards_Giveaway_Block_Checkout_Links extends Mage_Checkout_Block_Links
12
+ {
13
+ /**
14
+ * Checks if customer can proceed to checkout and
15
+ * if so, adds checkout link to the top nav
16
+ *
17
+ * @return Sitewards_Giveaway_Block_Checkout_Links
18
+ */
19
+ public function addCheckoutLink()
20
+ {
21
+ $oGiveawayHelper = Mage::helper('sitewards_giveaway');
22
+ $bValidCart = $oGiveawayHelper->isCartValidForCheckout();
23
+ if ($bValidCart) {
24
+ return parent::addCheckoutLink();
25
+ } else {
26
+ return $this;
27
+ }
28
+ }
29
+ }
app/code/community/Sitewards/Giveaway/Block/Checkout/Multishipping/Link.php CHANGED
@@ -8,21 +8,22 @@
8
  * @package Sitewards_Giveaway
9
  * @copyright Copyright (c) 2012 Sitewards GmbH (http://www.sitewards.com/de/)
10
  */
11
- class Sitewards_Giveaway_Block_Checkout_Multishipping_Link extends Mage_Checkout_Block_Multishipping_Link {
12
-
13
- /**
14
- * Checks if customer can check out with his
15
- * cart and if so, displays the checkout link
16
- *
17
- * @return string
18
- */
19
- public function _toHtml(){
20
- $oGiveawayHelper = Mage::helper('sitewards_giveaway');
21
- $bValidCart = $oGiveawayHelper->isCartValidForCheckout();
22
- if ($bValidCart) {
23
- return parent::_toHtml();
24
- } else {
25
- return '';
26
- }
27
- }
28
- }
 
8
  * @package Sitewards_Giveaway
9
  * @copyright Copyright (c) 2012 Sitewards GmbH (http://www.sitewards.com/de/)
10
  */
11
+ class Sitewards_Giveaway_Block_Checkout_Multishipping_Link extends Mage_Checkout_Block_Multishipping_Link
12
+ {
13
+ /**
14
+ * Checks if customer can check out with his
15
+ * cart and if so, displays the checkout link
16
+ *
17
+ * @return string
18
+ */
19
+ public function _toHtml()
20
+ {
21
+ $oGiveawayHelper = Mage::helper('sitewards_giveaway');
22
+ $bValidCart = $oGiveawayHelper->isCartValidForCheckout();
23
+ if ($bValidCart) {
24
+ return parent::_toHtml();
25
+ } else {
26
+ return '';
27
+ }
28
+ }
29
+ }
app/code/community/Sitewards/Giveaway/Block/Checkout/Onepage/Link.php CHANGED
@@ -8,24 +8,25 @@
8
  * @package Sitewards_Giveaway
9
  * @copyright Copyright (c) 2012 Sitewards GmbH (http://www.sitewards.com/de/)
10
  */
11
- class Sitewards_Giveaway_Block_Checkout_Onepage_Link extends Mage_Checkout_Block_Onepage_Link {
 
 
 
 
 
 
 
 
 
 
 
 
 
12
 
13
- /**
14
- * Returns if the one page checkout is available
15
- *
16
- * returns false if the cart is empty, contains only giveaway
17
- * products or for other reasons checked in the checkout helper
18
- *
19
- * @return boolean
20
- */
21
- public function isPossibleOnepageCheckout() {
22
- $oGiveawayHelper = Mage::helper('sitewards_giveaway');
23
- $bValidCart = $oGiveawayHelper->isCartValidForCheckout();
24
-
25
- if ( $bValidCart === false ) {
26
- return false;
27
- } else {
28
- return $this->helper('checkout')->canOnepageCheckout();
29
- }
30
- }
31
- }
8
  * @package Sitewards_Giveaway
9
  * @copyright Copyright (c) 2012 Sitewards GmbH (http://www.sitewards.com/de/)
10
  */
11
+ class Sitewards_Giveaway_Block_Checkout_Onepage_Link extends Mage_Checkout_Block_Onepage_Link
12
+ {
13
+ /**
14
+ * Returns if the one page checkout is available
15
+ *
16
+ * returns false if the cart is empty, contains only giveaway
17
+ * products or for other reasons checked in the checkout helper
18
+ *
19
+ * @return boolean
20
+ */
21
+ public function isPossibleOnepageCheckout()
22
+ {
23
+ $oGiveawayHelper = Mage::helper('sitewards_giveaway');
24
+ $bValidCart = $oGiveawayHelper->isCartValidForCheckout();
25
 
26
+ if ($bValidCart === false) {
27
+ return false;
28
+ } else {
29
+ return $this->helper('checkout')->canOnepageCheckout();
30
+ }
31
+ }
32
+ }
 
 
 
 
 
 
 
 
 
 
 
 
app/code/community/Sitewards/Giveaway/Block/Product/List/Giveaway.php CHANGED
@@ -1,7 +1,7 @@
1
  <?php
2
  /**
3
  * Sitewards_Giveaway_Block_Product_List_Giveaway
4
- *
5
  * Builds a block to display all giveaway products
6
  * Sets up a collection and checks for true against the giveaway identifier
7
  *
@@ -9,94 +9,103 @@
9
  * @package Sitewards_Giveaway
10
  * @copyright Copyright (c) 2012 Sitewards GmbH (http://www.sitewards.com/de/)
11
  */
12
- class Sitewards_Giveaway_Block_Product_List_Giveaway extends Mage_Catalog_Block_Product_List {
13
- /**
14
- * Giveaway Product Collection
15
- *
16
- * @var Mage_Eav_Model_Entity_Collection_Abstract
17
- */
18
- protected $_productCollection;
19
-
20
- /**
21
- * Set the Giveaway Product Collection then call the parent function
22
- *
23
- * (non-PHPdoc)
24
- * @see Mage_Core_Block_Abstract::_prepareLayout()
25
- */
26
- public function _prepareLayout() {
27
- $this->_getGiveawayCollection();
28
 
29
- // add Home breadcrumb
30
- $oBreadcrumbs = $this->getLayout()->getBlock('breadcrumbs');
 
 
 
 
 
 
 
31
 
32
- // if we don't have breadcrumbs in layout, just continue
33
- if (!$oBreadcrumbs){
34
- return parent::_prepareLayout();
35
- }
36
 
37
- $sTitle = $this->__('Free Allowances');
38
- if ($oBreadcrumbs) {
39
- $oBreadcrumbs->addCrumb('home', array(
40
- 'label' => $this->__('Home'),
41
- 'title' => $this->__('Go to Home Page'),
42
- 'link' => Mage::getBaseUrl()
43
- ))->addCrumb('search', array(
44
- 'label' => $sTitle,
45
- 'title' => $sTitle
46
- ));
47
- }
48
 
49
- // modify page title
50
- $oHeadBlock = $this->getLayout()->getBlock('head');
51
- if ($oHeadBlock){
52
- $oHeadBlock->setTitle($sTitle);
53
- }
 
 
 
 
 
 
 
 
 
 
 
 
54
 
55
- // add page title
56
- $oTitleBlock = $this->getLayout()->createBlock('sitewards_giveaway/product_listTitle')
57
- ->setTemplate('sitewards/giveaway/catalog/product/list_title.phtml')
58
- ->setPageTitle($sTitle);
59
- $this->getLayout()->getBlock('content')->insert($oTitleBlock);
60
 
61
- return parent::_prepareLayout();
62
- }
 
63
 
64
- /**
65
- * Retrieve loaded Giveaway Product Collection
66
- *
67
- * @return Mage_Eav_Model_Entity_Collection_Abstract
68
- */
69
- protected function _getGiveawayCollection() {
70
- if (is_null($this->_productCollection)) {
71
- $oProduct = Mage::getModel('catalog/product');
72
- /* @var $oCollection Mage_Catalog_Model_Resource_Product_Collection */
73
- $this->_productCollection = $oProduct->getResourceCollection();
74
 
75
- $oSitewardsGiveawayHelper = Mage::helper('sitewards_giveaway');
76
- $sGiveawayAttributeCode = $oSitewardsGiveawayHelper->getGiveawayIdentifierName();
77
- $this->_productCollection->addAttributeToFilter($sGiveawayAttributeCode, true);
78
- $this->_productCollection->addAttributeToSelect('*');
79
- }
 
 
 
 
 
 
80
 
81
- return $this->_productCollection;
82
- }
 
 
 
 
 
83
 
84
- /**
85
- * Retrieve loaded Giveaway Product Collection
86
- *
87
- * @return Mage_Eav_Model_Entity_Collection_Abstract
88
- */
89
- public function getLoadedProductCollection() {
90
- return $this->_getGiveawayCollection();
91
- }
 
92
 
93
- /**
94
- * Set the Giveaway Product Collection
95
- *
96
- * @param Mage_Eav_Model_Entity_Collection_Abstract $oCollection
97
- */
98
- public function setCollection($oCollection) {
99
- $this->_productCollection = $oCollection;
100
- return $this;
101
- }
102
- }
 
 
1
  <?php
2
  /**
3
  * Sitewards_Giveaway_Block_Product_List_Giveaway
4
+ *
5
  * Builds a block to display all giveaway products
6
  * Sets up a collection and checks for true against the giveaway identifier
7
  *
9
  * @package Sitewards_Giveaway
10
  * @copyright Copyright (c) 2012 Sitewards GmbH (http://www.sitewards.com/de/)
11
  */
12
+ class Sitewards_Giveaway_Block_Product_List_Giveaway extends Mage_Catalog_Block_Product_List
13
+ {
14
+ /**
15
+ * Giveaway Product Collection
16
+ *
17
+ * @var Mage_Eav_Model_Entity_Collection_Abstract
18
+ */
19
+ protected $_productCollection;
 
 
 
 
 
 
 
 
20
 
21
+ /**
22
+ * Set the Giveaway Product Collection then call the parent function
23
+ *
24
+ * (non-PHPdoc)
25
+ * @see Mage_Core_Block_Abstract::_prepareLayout()
26
+ */
27
+ public function _prepareLayout()
28
+ {
29
+ $this->_getGiveawayCollection();
30
 
31
+ // add Home breadcrumb
32
+ $oBreadcrumbs = $this->getLayout()->getBlock('breadcrumbs');
 
 
33
 
34
+ // if we don't have breadcrumbs in layout, just continue
35
+ if (!$oBreadcrumbs) {
36
+ return parent::_prepareLayout();
37
+ }
 
 
 
 
 
 
 
38
 
39
+ $sTitle = $this->__('Free Allowances');
40
+ if ($oBreadcrumbs) {
41
+ $oBreadcrumbs->addCrumb(
42
+ 'home',
43
+ array(
44
+ 'label' => $this->__('Home'),
45
+ 'title' => $this->__('Go to Home Page'),
46
+ 'link' => Mage::getBaseUrl()
47
+ )
48
+ )->addCrumb(
49
+ 'giveaway',
50
+ array(
51
+ 'label' => $sTitle,
52
+ 'title' => $sTitle
53
+ )
54
+ );
55
+ }
56
 
57
+ // modify page title
58
+ $oHeadBlock = $this->getLayout()->getBlock('head');
59
+ if ($oHeadBlock) {
60
+ $oHeadBlock->setTitle($sTitle);
61
+ }
62
 
63
+ $oTitleBlock = $this->getLayout()->createBlock('sitewards_giveaway/product_listTitle')
64
+ ->setTemplate('sitewards/giveaway/catalog/product/list_title.phtml');
65
+ $this->getLayout()->getBlock('content')->insert($oTitleBlock);
66
 
67
+ return parent::_prepareLayout();
68
+ }
 
 
 
 
 
 
 
 
69
 
70
+ /**
71
+ * Retrieve loaded Giveaway Product Collection
72
+ *
73
+ * @return Mage_Eav_Model_Entity_Collection_Abstract
74
+ */
75
+ protected function _getGiveawayCollection()
76
+ {
77
+ if (is_null($this->_productCollection)) {
78
+ $oProduct = Mage::getModel('catalog/product');
79
+ /* @var $oCollection Mage_Catalog_Model_Resource_Product_Collection */
80
+ $this->_productCollection = $oProduct->getResourceCollection();
81
 
82
+ $oSitewardsGiveawayHelper = Mage::helper('sitewards_giveaway');
83
+ $sGiveawayAttributeCode = $oSitewardsGiveawayHelper->getGiveawayIdentifierName();
84
+ $this->_productCollection->addAttributeToFilter($sGiveawayAttributeCode, true);
85
+ $this->_productCollection->addAttributeToSelect('*');
86
+ }
87
+ return $this->_productCollection;
88
+ }
89
 
90
+ /**
91
+ * Retrieve loaded Giveaway Product Collection
92
+ *
93
+ * @return Mage_Eav_Model_Entity_Collection_Abstract
94
+ */
95
+ public function getLoadedProductCollection()
96
+ {
97
+ return $this->_getGiveawayCollection();
98
+ }
99
 
100
+ /**
101
+ * Set the Giveaway Product Collection
102
+ *
103
+ * @param Mage_Eav_Model_Entity_Collection_Abstract $oCollection
104
+ * @return Sitewards_Giveaway_Block_Product_List_Giveaway
105
+ */
106
+ public function setCollection($oCollection)
107
+ {
108
+ $this->_productCollection = $oCollection;
109
+ return $this;
110
+ }
111
+ }
app/code/community/Sitewards/Giveaway/Block/Product/ListTitle.php CHANGED
@@ -8,9 +8,11 @@
8
  * @package Sitewards_Giveaway
9
  * @copyright Copyright (c) 2012 Sitewards GmbH (http://www.sitewards.com/de/)
10
  */
11
- class Sitewards_Giveaway_Block_Product_ListTitle extends Mage_Core_Block_Template{
12
-
13
- public function _toHtml(){
14
- return parent::_toHtml();
15
- }
16
- }
 
 
8
  * @package Sitewards_Giveaway
9
  * @copyright Copyright (c) 2012 Sitewards GmbH (http://www.sitewards.com/de/)
10
  */
11
+ class Sitewards_Giveaway_Block_Product_ListTitle extends Mage_Core_Block_Template
12
+ {
13
+ public function _toHtml()
14
+ {
15
+ $this->setPageTitle(Mage::helper('sitewards_giveaway')->__('Free Allowances'));
16
+ return parent::_toHtml();
17
+ }
18
+ }
app/code/community/Sitewards/Giveaway/Helper/Data.php CHANGED
@@ -9,152 +9,407 @@
9
  * @copyright Copyright (c) 2012 Sitewards GmbH (http://www.sitewards.com/de/)
10
  * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
11
  */
12
- class Sitewards_Giveaway_Helper_Data extends Mage_Core_Helper_Abstract {
13
- /**
14
- * Returns an attribute code to identify a give away product by
15
- *
16
- * @return string
17
- */
18
- public function getGiveawayIdentifierName() {
19
- if ( $this->isExtensionEnabled() == true ) {
20
- return Mage::getStoreConfig('sitewards_giveaway_config/sitewards_giveaway_general/giveaway_identifier_name');
21
- }
22
- }
23
-
24
- /**
25
- * Returns the number of giveaway items allowed per cart instance
26
- *
27
- * @return integer
28
- */
29
- public function getGiveawaysPerCart() {
30
- if ( $this->isExtensionEnabled() == true ) {
31
- return Mage::getStoreConfig('sitewards_giveaway_config/sitewards_giveaway_general/giveaways_per_cart');
32
- }
33
- }
34
-
35
- /**
36
- * Returns true is extension is active
37
- *
38
- * @return boolean
39
- */
40
- public function isExtensionEnabled() {
41
- return Mage::getStoreConfig('sitewards_giveaway_config/sitewards_giveaway_general/enable_ext');
42
- }
43
-
44
- /**
45
- * @return boolean
46
- */
47
- public function isForwardToGiveawaysPageEnabled(){
48
- return Mage::getStoreConfig('sitewards_giveaway_config/sitewards_giveaway_general/giveaways_forward_to_list');
49
- }
50
-
51
- /**
52
- * Returns the page for giveaway products
53
- *
54
- * @return string
55
- */
56
- public function getGiveawaysPage(){
57
- return 'giveaway';
58
- }
59
-
60
- /**
61
- * Returns if the product is a giveaway
62
- *
63
- * @param Mage_Catalog_Model_Product $oProduct
64
- *
65
- * @return boolean
66
- */
67
- public function isProductGiveaway(Mage_Catalog_Model_Product $oProduct){
68
- return (boolean)$oProduct->getData($this->getGiveawayIdentifierName());
69
- }
70
-
71
- /**
72
- * Returns an array of giveaway product ids and their amount in the cart
73
- *
74
- * @return array
75
- */
76
- public function getCartGiveawayProductsAmounts(){
77
- $oCart = Mage::getSingleton('checkout/cart');
78
- $oProduct = Mage::getModel('catalog/product');
79
- $oItems = $oCart->getItems();
80
-
81
- $aGiveawayProductsInCart = array();
82
- foreach($oItems as $oItem) {
83
- $oCollection = $oProduct->getResourceCollection()
84
- ->addAttributeToFilter('entity_id', $oItem->getData('product_id'))
85
- ->addAttributeToFilter($this->getGiveawayIdentifierName(), true);
86
- $aProductId = $oCollection->getAllIds();
87
- // if the $aProductId is not empty, then we have a giveaway product
88
- if (!empty($aProductId)){
89
- $aGiveawayProductsInCart[$oItem->getData('product_id')] = $oItem->getData('qty');
90
- }
91
- }
92
-
93
- return $aGiveawayProductsInCart;
94
- }
95
-
96
- /**
97
- * Returns if user can add giveaway products to his cart
98
- *
99
- * @return boolean|integer
100
- */
101
- public function canAddGiveawaysToCart(){
102
- $aGiveawayProductsInCart = $this->getCartGiveawayProductsAmounts();
103
- return array_sum($aGiveawayProductsInCart) < $this->getGiveawaysPerCart();
104
- }
105
-
106
- /**
107
- * Returns the default order qty for a product by provided product id
108
- *
109
- * @param integer|boolean $iProductId
110
- * @return integer|float
111
- * @throws Exception
112
- * if the product id is not an integer greater than zero
113
- */
114
- public function getDefaultOrderQtyForProductId($iProductId = false){
115
-
116
- if (intval($iProductId) != $iProductId || intval($iProductId) <= 0){
117
- throw new Exception("ProductId must be an integer greater than 0.");
118
- }
119
-
120
- $oProductViewBlock = Mage::app()->getLayout()->createBlock('catalog/product_view');
121
- $oProduct = Mage::getModel('catalog/product')->load($iProductId);
122
- $mDefaultQty = $oProductViewBlock->getProductDefaultQty($oProduct);
123
-
124
- return $mDefaultQty;
125
- }
126
-
127
- /**
128
- * Checks if customer can proceed to checkout.
129
- * If his cart contains only giveaway products, there is no checkout possible
130
- *
131
- * @return bool
132
- */
133
- public function isCartValidForCheckout(){
134
- /* @var $oCartHelper Mage_Checkout_Helper_Cart */
135
- $oCartHelper = Mage::helper('checkout/cart');
136
- $oCart = $oCartHelper->getCart();
137
- $oCartItems = $oCart->getItems();
138
- $bValidCart = false;
139
- $oProduct = Mage::getModel('catalog/product');
140
-
141
- // loop through all products in the cart and set $bValidCart
142
- // to true if we have at least one non-giveaway product
143
- foreach ($oCartItems as $oItem) {
144
- $iProductId = $oItem->getProductId();
145
- $oProduct->load($iProductId);
146
- if ( $oProduct->getData($this->getGiveawayIdentifierName()) != true ) {
147
- $bValidCart = true;
148
- }
149
- $oProduct->clearInstance();
150
- }
151
-
152
- // if the cart is empty, it's valid too
153
- if (count($oCartItems) == 0) {
154
- $bValidCart = true;
155
- }
156
-
157
- return $bValidCart;
158
- }
159
-
160
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
9
  * @copyright Copyright (c) 2012 Sitewards GmbH (http://www.sitewards.com/de/)
10
  * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
11
  */
12
+ class Sitewards_Giveaway_Helper_Data extends Mage_Core_Helper_Abstract
13
+ {
14
+ /**
15
+ * Add cart action
16
+ *
17
+ * @type integer
18
+ */
19
+ const I_CART_ACTION_ADD = 0;
20
+
21
+ /**
22
+ * Update cart action
23
+ *
24
+ * @type integer
25
+ */
26
+ const I_CART_ACTION_UPDATE = 1;
27
+
28
+ /**
29
+ * Returns an attribute code to identify a give away product by
30
+ *
31
+ * @return string
32
+ */
33
+ public function getGiveawayIdentifierName()
34
+ {
35
+ if ($this->isExtensionEnabled() == true) {
36
+ return Mage::getStoreConfig('sitewards_giveaway_config/sitewards_giveaway_general/giveaway_identifier_name');
37
+ }
38
+ }
39
+
40
+ /**
41
+ * Returns the number of giveaway items allowed per cart instance
42
+ *
43
+ * @return integer
44
+ */
45
+ public function getGiveawaysPerCart()
46
+ {
47
+ if ($this->isExtensionEnabled() == true) {
48
+ return Mage::getStoreConfig('sitewards_giveaway_config/sitewards_giveaway_general/giveaways_per_cart');
49
+ }
50
+ }
51
+
52
+ /**
53
+ * Returns min total to add giveaways
54
+ *
55
+ * @return integer
56
+ */
57
+ protected function getMinTotal()
58
+ {
59
+ if ($this->isExtensionEnabled() == true) {
60
+ return Mage::getStoreConfig('sitewards_giveaway_config/sitewards_giveaway_general/min_total');
61
+ }
62
+ }
63
+
64
+ /**
65
+ * Returns the number of product in cart needed to add giveaways
66
+ *
67
+ * @return integer
68
+ */
69
+ protected function getNonGiveawaysPerCart()
70
+ {
71
+ if ($this->isExtensionEnabled() == true) {
72
+ return Mage::getStoreConfig('sitewards_giveaway_config/sitewards_giveaway_general/min_products');
73
+ }
74
+ }
75
+
76
+ /**
77
+ * Returns true is extension is active
78
+ *
79
+ * @return boolean
80
+ */
81
+ public function isExtensionEnabled()
82
+ {
83
+ return Mage::getStoreConfig('sitewards_giveaway_config/sitewards_giveaway_general/enable_ext');
84
+ }
85
+
86
+ /**
87
+ * @return boolean
88
+ */
89
+ public function isForwardToGiveawaysPageEnabled()
90
+ {
91
+ return Mage::getStoreConfig('sitewards_giveaway_config/sitewards_giveaway_general/giveaways_forward_to_list');
92
+ }
93
+
94
+ /**
95
+ * Returns the page for giveaway products
96
+ *
97
+ * @return string
98
+ */
99
+ public function getGiveawaysPage()
100
+ {
101
+ return 'giveaway';
102
+ }
103
+
104
+ /**
105
+ * Return giveaway identifier value by product id
106
+ *
107
+ * @param integer $iProductId
108
+ *
109
+ * @return boolean
110
+ */
111
+ public function getGiveawayIdentifierValue($iProductId)
112
+ {
113
+ $bIsGiveaway = (boolean) Mage::getModel('catalog/product')
114
+ ->getResource()
115
+ ->getAttributeRawValue(
116
+ $iProductId,
117
+ $this->getGiveawayIdentifierName(),
118
+ Mage::app()->getStore()
119
+ );
120
+ return $bIsGiveaway;
121
+ }
122
+
123
+ /**
124
+ * Return the number of giveaway products in the cart
125
+ *
126
+ * @return float
127
+ */
128
+ public function getCartGiveawayProductsAmounts()
129
+ {
130
+ return array_sum($this->getCartProductsAmounts(true));
131
+ }
132
+
133
+ /**
134
+ * Return the number of non giveaway products in the cart
135
+ *
136
+ * @return float
137
+ */
138
+ public function getCartNonGiveawayProductsAmounts()
139
+ {
140
+ return array_sum($this->getCartProductsAmounts(false));
141
+ }
142
+
143
+ /**
144
+ * Returns if user can add giveaway products to his cart
145
+ *
146
+ * @return boolean|integer
147
+ */
148
+ public function canAddGiveawaysToCart()
149
+ {
150
+ return ($this->canHaveMoreGiveaways()
151
+ && $this->hasEnoughNonGiveaways()
152
+ && $this->hasEnoughTotal()
153
+ && $this->hasSiteGiveaways()
154
+ );
155
+ }
156
+
157
+ /**
158
+ * returns if sessions grand total is at least the defined min_total
159
+ *
160
+ * @return bool
161
+ */
162
+ private function hasEnoughTotal()
163
+ {
164
+ $oCheckoutSession = Mage::getSingleton('checkout/session');
165
+ if ($oCheckoutSession->getQuote()->getBaseGrandTotal() < $this->getMinTotal()) {
166
+ return false;
167
+ }
168
+ return true;
169
+ }
170
+
171
+ /**
172
+ * returns if user has enough non giveaways in cart
173
+ */
174
+ private function hasEnoughNonGiveaways()
175
+ {
176
+ return $this->getCartNonGiveawayProductsAmounts() >= $this->getNonGiveawaysPerCart();
177
+ }
178
+
179
+ /**
180
+ * returns if user has not already all possible giveaways in cart
181
+ *
182
+ * @return bool
183
+ */
184
+ private function canHaveMoreGiveaways()
185
+ {
186
+ return $this->getCartGiveawayProductsAmounts() < $this->getGiveawaysPerCart();
187
+ }
188
+
189
+ /**
190
+ * Returns the default order qty for a product by provided product id
191
+ *
192
+ * @param integer|boolean $iProductId
193
+ * @return integer|float
194
+ * @throws Exception
195
+ * if the product id is not an integer greater than zero
196
+ */
197
+ public function getDefaultOrderQtyForProductId($iProductId = false)
198
+ {
199
+
200
+ if (intval($iProductId) != $iProductId || intval($iProductId) <= 0) {
201
+ throw new Exception("ProductId must be an integer greater than 0.");
202
+ }
203
+
204
+ $oProductViewBlock = Mage::app()->getLayout()->createBlock('catalog/product_view');
205
+ $oProduct = Mage::getModel('catalog/product')->load($iProductId);
206
+ $mDefaultQty = $oProductViewBlock->getProductDefaultQty($oProduct);
207
+
208
+ return $mDefaultQty;
209
+ }
210
+
211
+ /**
212
+ * Checks if customer can proceed to checkout.
213
+ * If his cart contains only giveaway products,
214
+ * or giveaway products are more than allowed,
215
+ * there is no checkout possible
216
+ *
217
+ * @return bool
218
+ */
219
+ public function isCartValidForCheckout()
220
+ {
221
+ /* @var $oCartHelper Mage_Checkout_Helper_Cart */
222
+ $oCartHelper = Mage::helper('checkout/cart');
223
+ $oCart = $oCartHelper->getCart();
224
+ $oCartItems = $oCart->getItems();
225
+ $bValidCart = false;
226
+
227
+ // loop through all products in the cart and set $bValidCart
228
+ // to true if we have at least one non-giveaway product
229
+ foreach ($oCartItems as $oItem) {
230
+ $iProductId = $oItem->getProductId();
231
+ if ($this->getGiveawayIdentifierValue($iProductId) != true) {
232
+ $bValidCart = true;
233
+ }
234
+ }
235
+
236
+ $bHasDeprecatedGiveawayAmount = ($this->getCartGiveawayProductsAmounts() > $this->getGiveawaysPerCart());
237
+ $bHasSomeGiveaway = ($this->getCartGiveawayProductsAmounts() > 0);
238
+ $bHasEnoughNonGiveaways = ($bHasSomeGiveaway && !$this->hasEnoughNonGiveaways());
239
+ if ($bHasDeprecatedGiveawayAmount || $bHasEnoughNonGiveaways || !$this->hasEnoughTotal()) {
240
+ $bValidCart = false;
241
+ }
242
+
243
+ // if the cart is empty, it's valid too
244
+ if (count($oCartItems) == 0) {
245
+ $bValidCart = true;
246
+ }
247
+
248
+ return $bValidCart;
249
+ }
250
+
251
+ /**
252
+ * Returns an array of non giveaway product ids and their amount in the cart
253
+ *
254
+ * @param bool $bIsGiveaway
255
+ * @return array
256
+ */
257
+ private function getCartProductsAmounts($bIsGiveaway = false)
258
+ {
259
+ $oCart = Mage::getSingleton('checkout/cart');
260
+ $aProductsInCart = array();
261
+ foreach ($oCart->getItems() as $oItem) {
262
+ $iProductId = $oItem->getProductId();
263
+ if ($this->getGiveawayIdentifierValue($iProductId) == $bIsGiveaway) {
264
+ $aProductsInCart[$iProductId] = $oItem->getQty();
265
+ }
266
+ }
267
+ return $aProductsInCart;
268
+ }
269
+
270
+ /**
271
+ * Check to see if there are giveaway products available on the site
272
+ *
273
+ * @return bool
274
+ */
275
+ public function hasSiteGiveaways()
276
+ {
277
+ /* @var $oProduct Mage_Catalog_Model_Product */
278
+ $oProduct = Mage::getModel('catalog/product');
279
+ /* @var $oCollection Mage_Catalog_Model_Resource_Product_Collection */
280
+ $oCollection = $oProduct->getResourceCollection()
281
+ ->addStoreFilter()
282
+ ->addAttributeToFilter($this->getGiveawayIdentifierName(), true);
283
+
284
+ Mage::getSingleton('catalog/product_visibility')->addVisibleInCatalogFilterToCollection($oCollection);
285
+ Mage::getSingleton('catalog/product_status')->addSaleableFilterToCollection($oCollection);
286
+
287
+ if ($oCollection->getSize() > 0) {
288
+ return true;
289
+ }
290
+ return false;
291
+ }
292
+
293
+ /**
294
+ * Get all items in the cart
295
+ * Get all items adding to the cart
296
+ * Calculate cart params
297
+ * Compare cart params with config limits and add notices
298
+ *
299
+ * @param Sitewards_Giveaway_Model_Product_Quantity_Collection $oProductQuantityCollection
300
+ * @param int $iCartAction - cart action
301
+ * @return boolean
302
+ */
303
+ public function canAddProducts(
304
+ Sitewards_Giveaway_Model_Product_Quantity_Collection $oProductQuantityCollection,
305
+ $iCartAction = self::I_CART_ACTION_UPDATE
306
+ ) {
307
+ if ($iCartAction == self::I_CART_ACTION_ADD
308
+ && $this->getGiveawayIdentifierValue($oProductQuantityCollection->getFirstItem()->getId()) == false
309
+ ) {
310
+ return true;
311
+ }
312
+ /** @var $oCheckoutSession Mage_Checkout_Model_Session */
313
+ $oCheckoutSession = Mage::getSingleton('checkout/session');
314
+ $sGiveawayAttributeCode = $this->getGiveawayIdentifierName();
315
+
316
+ /*
317
+ * Config limits
318
+ */
319
+ $iGiveawayMaxCount = (int)$this->getGiveawaysPerCart();
320
+ $iNonGiveawayMinCount = (int)$this->getNonGiveawaysPerCart();
321
+ $fMinTotal = (float)$this->getMinTotal();
322
+
323
+ /*
324
+ * Calculate cart params according to the cart action
325
+ */
326
+ $fTotalGiveawayQty = 0;
327
+ $fTotalNonGiveawayQty = 0;
328
+ $fBaseGrandTotal = 0;
329
+ if ($iCartAction == self::I_CART_ACTION_ADD) {
330
+ $fTotalGiveawayQty = $this->getCartGiveawayProductsAmounts();
331
+ $fTotalNonGiveawayQty = $this->getCartNonGiveawayProductsAmounts();
332
+ $fBaseGrandTotal = (float)$oCheckoutSession->getQuote()->getBaseGrandTotal();
333
+ }
334
+ $bUpdateIsGiveaway = false;
335
+ foreach ($oProductQuantityCollection as $oProductQuantity) {
336
+ $oProduct = Mage::getModel('catalog/product');
337
+ $oProduct->load($oProductQuantity->getId());
338
+ if ($oProduct->getData($sGiveawayAttributeCode) == true) {
339
+ $bUpdateIsGiveaway = true;
340
+ $fTotalGiveawayQty += $oProductQuantity->getQty();
341
+ } else {
342
+ $fTotalNonGiveawayQty += $oProductQuantity->getQty();
343
+ }
344
+ $fBaseGrandTotal += $oProductQuantity->getQty() * $oProduct->getPrice();
345
+ }
346
+
347
+ /*
348
+ * Compare cart params with config limits
349
+ */
350
+ if ($bUpdateIsGiveaway == true) {
351
+ $sMessage = $this->__('Cannot add item(s) to your shopping cart.');
352
+ if ($fTotalGiveawayQty > $iGiveawayMaxCount) {
353
+ $sMessage .= ' ' . $this->__('You can have only %s giveaway item(s) per cart.', $iGiveawayMaxCount);
354
+ $oCheckoutSession->addNotice($sMessage);
355
+ return false;
356
+ } elseif ($fTotalNonGiveawayQty < $iNonGiveawayMinCount) {
357
+ $sMessage .= ' ' . $this->__(
358
+ 'The total number of items in your cart must be at least %s.',
359
+ $iNonGiveawayMinCount
360
+ );
361
+ $oCheckoutSession->addNotice($sMessage);
362
+ return false;
363
+ } elseif ($fBaseGrandTotal < $fMinTotal) {
364
+ $fFormattedMinTotal = Mage::helper('core')->currency($fMinTotal);
365
+ $sMessage .= ' ' . $this->__('The total of the cart must be at least %s.', $fFormattedMinTotal);
366
+ $oCheckoutSession->addNotice($sMessage);
367
+ return false;
368
+ }
369
+ }
370
+ return true;
371
+ }
372
+
373
+ /**
374
+ * Return update cart product data
375
+ *
376
+ * @param Mage_Core_Controller_Request_Http $oRequest
377
+ * @return Sitewards_Giveaway_Model_Product_Quantity_Collection
378
+ */
379
+ public function getUpdateCartProductInfo(Mage_Core_Controller_Request_Http $oRequest)
380
+ {
381
+ $aParams = $oRequest->getParams();
382
+ $oProductQuantityCollection = Mage::getModel('sitewards_giveaway/product_quantity_collection');
383
+ foreach (Mage::getSingleton('checkout/cart')->getItems() as $iItemIndex => $oItem) {
384
+ if (isset($aParams['cart'][$iItemIndex])) {
385
+ $oProductQuantity = Mage::getModel('sitewards_giveaway/product_quantity');
386
+ $oProductQuantity->setId($oItem->getProductId());
387
+ $oProductQuantity->setQty($aParams['cart'][$iItemIndex]['qty']);
388
+ $oProductQuantityCollection->addItem($oProductQuantity);
389
+ }
390
+ }
391
+ return $oProductQuantityCollection;
392
+ }
393
+
394
+ /**
395
+ * Return add cart product data
396
+ *
397
+ * @param Mage_Core_Controller_Request_Http $oRequest
398
+ * @return Sitewards_Giveaway_Model_Product_Quantity_Collection
399
+ */
400
+ public function getAddCartProductInfo(Mage_Core_Controller_Request_Http $oRequest)
401
+ {
402
+ $aParams = $oRequest->getParams();
403
+ if (isset($aParams['qty'])) {
404
+ $iQty = (int)$aParams['qty'];
405
+ } else {
406
+ $iQty = $this->getDefaultOrderQtyForProductId($aParams['product']);
407
+ }
408
+ $oProductQuantityCollection = Mage::getModel('sitewards_giveaway/product_quantity_collection');
409
+ $oProductQuantity = Mage::getModel('sitewards_giveaway/product_quantity');
410
+ $oProductQuantity->setId($aParams['product']);
411
+ $oProductQuantity->setQty($iQty);
412
+ $oProductQuantityCollection->addItem($oProductQuantity);
413
+ return $oProductQuantityCollection;
414
+ }
415
+ }
app/code/community/Sitewards/Giveaway/Model/Observer.php CHANGED
@@ -9,27 +9,25 @@
9
  * @package Sitewards_Giveaway
10
  * @copyright Copyright (c) 2012 Sitewards GmbH (http://www.sitewards.com/de/)
11
  */
12
- class Sitewards_Giveaway_Model_Observer extends Mage_Core_Model_Observer {
 
 
 
 
 
 
 
 
 
 
 
13
 
14
- /**
15
- * Checks on adding a product to a cart if certain criteria are fulfilled
16
- * and redirect to the giveaway select page if so
17
- *
18
- * @param Varien_Event_Observer $oObserver
19
- */
20
- public function onCheckoutCartAddProductComplete(Varien_Event_Observer $oObserver){
21
-
22
- $iProductId = $oObserver->getEvent()->getProduct()->getId();
23
- $oProduct = Mage::getModel('catalog/product')->load($iProductId);
24
-
25
- /** @var $oHelper Sitewards_Giveaway_Helper_Data */
26
- $oHelper = Mage::helper('sitewards_giveaway');
27
-
28
- if ($oHelper->isExtensionEnabled()
29
- && $oHelper->isForwardToGiveawaysPageEnabled()
30
- && $oHelper->canAddGiveawaysToCart() !== false
31
- && !$oHelper->isProductGiveaway($oProduct)){
32
- $oObserver->getRequest()->setParam('return_url', Mage::getUrl($oHelper->getGiveawaysPage()));
33
- }
34
- }
35
- }
9
  * @package Sitewards_Giveaway
10
  * @copyright Copyright (c) 2012 Sitewards GmbH (http://www.sitewards.com/de/)
11
  */
12
+ class Sitewards_Giveaway_Model_Observer extends Mage_Core_Model_Observer
13
+ {
14
+ /**
15
+ * Checks on adding a product to a cart if certain criteria are fulfilled
16
+ * and redirect to the giveaway select page if so
17
+ *
18
+ * @param Varien_Event_Observer $oObserver
19
+ */
20
+ public function onCheckoutCartAddProductComplete(Varien_Event_Observer $oObserver)
21
+ {
22
+ /** @var $oHelper Sitewards_Giveaway_Helper_Data */
23
+ $oHelper = Mage::helper('sitewards_giveaway');
24
 
25
+ if ($oHelper->isExtensionEnabled()
26
+ && $oHelper->isForwardToGiveawaysPageEnabled()
27
+ && $oHelper->canAddGiveawaysToCart() !== false
28
+ && !$oHelper->getGiveawayIdentifierValue($oObserver->getEvent()->getProduct()->getId())
29
+ ) {
30
+ $oObserver->getRequest()->setParam('return_url', Mage::getUrl($oHelper->getGiveawaysPage()));
31
+ }
32
+ }
33
+ }
 
 
 
 
 
 
 
 
 
 
 
 
 
app/code/community/Sitewards/Giveaway/Model/Product/Quantity.php ADDED
@@ -0,0 +1,70 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Sitewards_Giveaway_Model_Product_Quantity
4
+ *
5
+ * Contain add to cart product information
6
+ *
7
+ * @category Sitewards
8
+ * @package Sitewards_Giveaway
9
+ * @copyright Copyright (c) 2013 Sitewards GmbH (http://www.sitewards.com/de/)
10
+ */
11
+ class Sitewards_Giveaway_Model_Product_Quantity extends Varien_Object
12
+ {
13
+ /**
14
+ * Product Id
15
+ *
16
+ * @var integer
17
+ */
18
+ protected $iId;
19
+
20
+ /**
21
+ * Product quantity
22
+ *
23
+ * @var integer
24
+ */
25
+ protected $iQty;
26
+
27
+ /**
28
+ * Setter for $iId
29
+ *
30
+ * @param integer $iId
31
+ * @return Sitewards_Giveaway_Model_Product_Quantity
32
+ */
33
+ public function setId($iId)
34
+ {
35
+ $this->iId = $iId;
36
+ return $this;
37
+ }
38
+
39
+ /**
40
+ * Setter for $iQty
41
+ *
42
+ * @param integer $iQty
43
+ * @return Sitewards_Giveaway_Model_Product_Quantity
44
+ */
45
+ public function setQty($iQty)
46
+ {
47
+ $this->iQty = $iQty;
48
+ return $this;
49
+ }
50
+
51
+ /**
52
+ * Getter for $iId
53
+ *
54
+ * @return int
55
+ */
56
+ public function getId()
57
+ {
58
+ return $this->iId;
59
+ }
60
+
61
+ /**
62
+ * Getter for $iQty
63
+ *
64
+ * @return int
65
+ */
66
+ public function getQty()
67
+ {
68
+ return $this->iQty;
69
+ }
70
+ }
app/code/community/Sitewards/Giveaway/Model/Product/Quantity/Collection.php ADDED
@@ -0,0 +1,13 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Sitewards_Giveaway_Model_Product_Quantity_Collection
4
+ *
5
+ * Collection for add to cart product information
6
+ *
7
+ * @category Sitewards
8
+ * @package Sitewards_Giveaway
9
+ * @copyright Copyright (c) 2013 Sitewards GmbH (http://www.sitewards.com/de/)
10
+ */
11
+ class Sitewards_Giveaway_Model_Product_Quantity_Collection extends Varien_Data_Collection
12
+ {
13
+ }
app/code/community/Sitewards/Giveaway/Model/Resource/Eav/Mysql4/Setup.php CHANGED
@@ -10,43 +10,43 @@
10
  */
11
  class Sitewards_Giveaway_Model_Resource_Eav_Mysql4_Setup extends Mage_Eav_Model_Entity_Setup
12
  {
13
- /**
14
- * adds the giveaway attribute to products
15
- * @return array
16
- */
17
- public function getDefaultEntities()
18
- {
19
- return array(
20
- 'catalog_product' => array(
21
- 'entity_model' => 'catalog/product',
22
- 'attribute_model' => 'catalog/resource_eav_attribute',
23
- 'table' => 'catalog/product',
24
- 'additional_attribute_table' => 'catalog/eav_attribute',
25
- 'entity_attribute_collection' => 'catalog/product_attribute_collection',
26
- 'attributes' => array(
27
- 'is_giveaway' => array(
28
- 'group' => 'Sitewards Giveaway',
29
- 'label' => 'Is Giveaway',
30
- 'type' => 'int',
31
- 'input' => 'boolean',
32
- 'default' => '0',
33
- 'class' => '',
34
- 'backend' => '',
35
- 'frontend' => '',
36
- 'source' => '',
37
- 'global' => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_STORE,
38
- 'visible' => true,
39
- 'required' => false,
40
- 'user_defined' => false,
41
- 'searchable' => false,
42
- 'filterable' => false,
43
- 'comparable' => false,
44
- 'visible_on_front' => false,
45
- 'visible_in_advanced_search' => false,
46
- 'unique' => false
47
- ),
48
- ),
49
- ),
50
- );
51
- }
52
  }
10
  */
11
  class Sitewards_Giveaway_Model_Resource_Eav_Mysql4_Setup extends Mage_Eav_Model_Entity_Setup
12
  {
13
+ /**
14
+ * adds the giveaway attribute to products
15
+ * @return array
16
+ */
17
+ public function getDefaultEntities()
18
+ {
19
+ return array(
20
+ 'catalog_product' => array(
21
+ 'entity_model' => 'catalog/product',
22
+ 'attribute_model' => 'catalog/resource_eav_attribute',
23
+ 'table' => 'catalog/product',
24
+ 'additional_attribute_table' => 'catalog/eav_attribute',
25
+ 'entity_attribute_collection' => 'catalog/product_attribute_collection',
26
+ 'attributes' => array(
27
+ 'is_giveaway' => array(
28
+ 'group' => 'Sitewards Giveaway',
29
+ 'label' => 'Is Giveaway',
30
+ 'type' => 'int',
31
+ 'input' => 'boolean',
32
+ 'default' => '0',
33
+ 'class' => '',
34
+ 'backend' => '',
35
+ 'frontend' => '',
36
+ 'source' => '',
37
+ 'global' => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_STORE,
38
+ 'visible' => true,
39
+ 'required' => false,
40
+ 'user_defined' => false,
41
+ 'searchable' => false,
42
+ 'filterable' => false,
43
+ 'comparable' => false,
44
+ 'visible_on_front' => false,
45
+ 'visible_in_advanced_search' => false,
46
+ 'unique' => false
47
+ ),
48
+ ),
49
+ ),
50
+ );
51
+ }
52
  }
app/code/community/Sitewards/Giveaway/Model/System/Config/Product/Identifier.php CHANGED
@@ -1,7 +1,7 @@
1
  <?php
2
  /**
3
  * Sitewards_Giveaway_Model_System_Config_Product_Identifier
4
- *
5
  * Return an array of all current product attributes
6
  * This is to be used with the main extension config to allow a user to select against which attribute the extension will check
7
  *
@@ -9,30 +9,32 @@
9
  * @package Sitewards_Giveaway
10
  * @copyright Copyright (c) 2012 Sitewards GmbH (http://www.sitewards.com/de/)
11
  */
12
- class Sitewards_Giveaway_Model_System_Config_Product_Identifier {
13
- /**
14
- * Returns an array of the value and attribute code for each product attribute
15
- *
16
- * @return array
17
- */
18
- public function toOptionArray() {
19
- $oEavEntityAttributeCollection = Mage::getResourceModel('eav/entity_attribute_collection');
20
- $oEavEntity = Mage::getModel('eav/entity');
21
- $iProductEntityTypeId = $oEavEntity->setType('catalog_product')->getTypeId();
 
 
 
 
22
 
23
- $aAttributeInfo = $oEavEntityAttributeCollection->setEntityTypeFilter($iProductEntityTypeId)->addSetInfo()->getData();
24
 
25
- $aReturnAttributes = array();
 
 
 
 
 
 
 
26
 
27
- if ( !empty ( $aAttributeInfo ) ) {
28
- foreach ( $aAttributeInfo as $aAttribute ) {
29
- $aReturnAttributes[] = array(
30
- 'value' => $aAttribute['attribute_code'],
31
- 'label' => $aAttribute['attribute_code']
32
- );
33
- }
34
- }
35
-
36
- return $aReturnAttributes;
37
- }
38
- }
1
  <?php
2
  /**
3
  * Sitewards_Giveaway_Model_System_Config_Product_Identifier
4
+ *
5
  * Return an array of all current product attributes
6
  * This is to be used with the main extension config to allow a user to select against which attribute the extension will check
7
  *
9
  * @package Sitewards_Giveaway
10
  * @copyright Copyright (c) 2012 Sitewards GmbH (http://www.sitewards.com/de/)
11
  */
12
+ class Sitewards_Giveaway_Model_System_Config_Product_Identifier
13
+ {
14
+ /**
15
+ * Returns an array of the value and attribute code for each product attribute
16
+ *
17
+ * @return array
18
+ */
19
+ public function toOptionArray()
20
+ {
21
+ $oEavEntityAttributeCollection = Mage::getResourceModel('eav/entity_attribute_collection');
22
+ $oEavEntity = Mage::getModel('eav/entity');
23
+ $iProductEntityTypeId = $oEavEntity->setType('catalog_product')->getTypeId();
24
+
25
+ $aAttributeInfo = $oEavEntityAttributeCollection->setEntityTypeFilter($iProductEntityTypeId)->addSetInfo()->getData();
26
 
27
+ $aReturnAttributes = array();
28
 
29
+ if (!empty($aAttributeInfo)) {
30
+ foreach ($aAttributeInfo as $aAttribute) {
31
+ $aReturnAttributes[] = array(
32
+ 'value' => $aAttribute['attribute_code'],
33
+ 'label' => $aAttribute['attribute_code']
34
+ );
35
+ }
36
+ }
37
 
38
+ return $aReturnAttributes;
39
+ }
40
+ }
 
 
 
 
 
 
 
 
 
app/code/community/Sitewards/Giveaway/controllers/CartController.php CHANGED
@@ -9,109 +9,63 @@
9
  * @copyright Copyright (c) 2012 Sitewards GmbH (http://www.sitewards.com/de/)
10
  */
11
  require_once 'Mage/Checkout/controllers/CartController.php';
12
- class Sitewards_Giveaway_CartController extends Mage_Checkout_CartController {
 
 
 
 
 
 
 
13
 
14
- /**
15
- * Adds products to cart
16
- * cancels if the product is giveaway and the max amount
17
- * of giveaway products in cart is already reached
18
- *
19
- * @return void
20
- */
21
- public function addAction() {
22
- $aParams = $this->getRequest()->getParams();
23
- $aProductInformation[] = array(
24
- 'id' => $aParams['product'],
25
- 'qty' => (isset($aParams['qty']) ? (int)$aParams['qty'] : Mage::helper('sitewards_giveaway')->getDefaultOrderQtyForProductId($aParams['product']))
26
- );
27
 
28
- if ($this->_canAddGiveaway($aProductInformation) == false) {
29
- $this->_getSession()->addNotice($this->__('Cannot add the item to shopping cart. You have already reached your limit of giveaway products.'));
30
- $this->_goBack();
31
- } else {
32
- parent::addAction();
33
- }
34
- }
 
 
 
 
35
 
36
- /**
37
- * Updades info in the cart. Adds a motice if trying to increase
38
- * the amount of giveaway product over the allowed limit
39
- */
40
- public function updatePostAction() {
41
- $aParams = $this->getRequest()->getParams();
42
- $oCart = $this->_getCart();
43
- $oCartItems = $oCart->getItems();
 
 
 
 
 
44
 
45
- $aProductInformation = array();
46
- foreach ($oCartItems as $iItemIndex => $oItem) {
47
- if (isset($aParams['cart'][$iItemIndex])) {
48
- if ($oItem->getQty() != $aParams['cart'][$iItemIndex]['qty']) {
49
- $aProductInformation[] = array(
50
- 'id' => $oItem->getProductId(),
51
- 'qty' => $aParams['cart'][$iItemIndex]['qty']
52
- );
53
- }
54
- }
55
- }
56
-
57
- if ($this->_canAddGiveaway($aProductInformation) == false) {
58
- $this->_getSession()->addNotice($this->__('Cannot add the item to shopping cart. You have already reached your limit of giveaway products.'));
59
- $this->_goBack();
60
- } else {
61
- parent::updatePostAction();
62
- }
63
- }
64
-
65
- /**
66
- * Get all items in the cart,
67
- * Check if any have the is_giveaway flag
68
- * If not call the parent action
69
- * Otherwise throw an error
70
- *
71
- * @param array $aProductInformation - an array with each element containing product id and quantity
72
- * @return boolean
73
- */
74
- protected function _canAddGiveaway($aProductInformation) {
75
- $oCart = $this->_getCart();
76
-
77
- $oSitewardsGiveawayHelper = Mage::helper('sitewards_giveaway');
78
- $sGiveawayAttributeCode = $oSitewardsGiveawayHelper->getGiveawayIdentifierName();
79
- $iGiveawayMaxCount = (int)$oSitewardsGiveawayHelper->getGiveawaysPerCart();
80
-
81
- /*
82
- * First check to see if the user has requested more than the allowed number of giveaway items
83
- */
84
- $iTotalUpdateQty = 0;
85
- $bUpdateIsGiveaway = false;
86
- foreach($aProductInformation as $aProduct) {
87
- $oProduct = Mage::getModel('catalog/product');
88
- $oProduct->load($aProduct['id']);
89
- if ($oProduct->getData($sGiveawayAttributeCode) == true) {
90
- $bUpdateIsGiveaway = true;
91
- $iTotalUpdateQty += $aProduct['qty'];
92
- if ($aProduct['qty'] > $iGiveawayMaxCount) {
93
- return false;
94
- }
95
- }
96
- }
97
-
98
- /*
99
- * Then check to see if the total giveaway items in the cart is already greater than the limit
100
- */
101
- if ($bUpdateIsGiveaway == true) {
102
- /*
103
- * Check to see if the new total would be greater than the limit
104
- * taking in count that we could just increase the amount of giveaway
105
- * products which are already in the cart
106
- */
107
- $aGiveawayProductsCount = $oSitewardsGiveawayHelper->getCartGiveawayProductsAmounts();
108
- foreach ($aProductInformation as $aProductInfo){
109
- $aGiveawayProductsCount[$aProductInfo['id']] = $aProductInfo['qty'];
110
- }
111
- if(array_sum($aGiveawayProductsCount) > $iGiveawayMaxCount) {
112
- return false;
113
- }
114
- }
115
- return true;
116
- }
117
- }
9
  * @copyright Copyright (c) 2012 Sitewards GmbH (http://www.sitewards.com/de/)
10
  */
11
  require_once 'Mage/Checkout/controllers/CartController.php';
12
+ class Sitewards_Giveaway_CartController extends Mage_Checkout_CartController
13
+ {
14
+ /**
15
+ * Update shopping cart action
16
+ *
17
+ * @type string
18
+ */
19
+ const S_CART_ACTION_UPDATE = 'update_qty';
20
 
21
+ /**
22
+ * Key to retrieve shopping cart action
23
+ *
24
+ * @type string
25
+ */
26
+ const S_CART_ACTION_KEY = 'update_cart_action';
 
 
 
 
 
 
 
27
 
28
+ /**
29
+ * Adds products to cart
30
+ * cancels if the product is giveaway and the max amount
31
+ * of giveaway products in cart is already reached
32
+ *
33
+ * @return void
34
+ */
35
+ public function addAction()
36
+ {
37
+ /** @var Sitewards_Giveaway_Helper_Data $oHelper */
38
+ $oHelper = Mage::helper('sitewards_giveaway');
39
 
40
+ $oProductQuantityCollection = $oHelper->getAddCartProductInfo($this->getRequest());
41
+ $bCanAddProducts = $oHelper->canAddProducts(
42
+ $oProductQuantityCollection,
43
+ Sitewards_Giveaway_Helper_Data::I_CART_ACTION_ADD
44
+ );
45
+ if ($oHelper->getGiveawayIdentifierValue($oProductQuantityCollection->getFirstItem()->getId())
46
+ && $bCanAddProducts == false
47
+ ) {
48
+ $this->_goBack();
49
+ } else {
50
+ parent::addAction();
51
+ }
52
+ }
53
 
54
+ /**
55
+ * Updates info in the cart. Adds a notice if trying to increase
56
+ * the amount of giveaway product over the allowed limit
57
+ */
58
+ public function updatePostAction()
59
+ {
60
+ $aParams = $this->getRequest()->getParams();
61
+ /** @var Sitewards_Giveaway_Helper_Data $oHelper */
62
+ $oHelper = Mage::helper('sitewards_giveaway');
63
+ $aProductInformation = $oHelper->getUpdateCartProductInfo($this->getRequest());
64
+ $bIsCartActionUpdate = ($aParams[self::S_CART_ACTION_KEY] == self::S_CART_ACTION_UPDATE);
65
+ if ($bIsCartActionUpdate && $oHelper->canAddProducts($aProductInformation) == false) {
66
+ $this->_goBack();
67
+ } else {
68
+ parent::updatePostAction();
69
+ }
70
+ }
71
+ }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
app/code/community/Sitewards/Giveaway/controllers/IndexController.php CHANGED
@@ -8,12 +8,14 @@
8
  * @package Sitewards_Giveaway
9
  * @copyright Copyright (c) 2012 Sitewards GmbH (http://www.sitewards.com/de/)
10
  */
11
- class Sitewards_Giveaway_IndexController extends Mage_Core_Controller_Front_Action {
12
- /**
13
- * URL: /giveaway/index/index
14
- */
15
- public function indexAction() {
16
- $this->loadLayout();
17
- $this->renderLayout();
18
- }
19
- }
 
 
8
  * @package Sitewards_Giveaway
9
  * @copyright Copyright (c) 2012 Sitewards GmbH (http://www.sitewards.com/de/)
10
  */
11
+ class Sitewards_Giveaway_IndexController extends Mage_Core_Controller_Front_Action
12
+ {
13
+ /**
14
+ * URL: /giveaway/index/index
15
+ */
16
+ public function indexAction()
17
+ {
18
+ $this->loadLayout();
19
+ $this->renderLayout();
20
+ }
21
+ }
app/code/community/Sitewards/Giveaway/etc/adminhtml.xml CHANGED
@@ -9,24 +9,24 @@
9
  */
10
  -->
11
  <config>
12
- <acl>
13
- <resources>
14
- <admin>
15
- <children>
16
- <system>
17
- <children>
18
- <config>
19
- <children>
20
- <sitewards_giveaway_config>
21
- <title>Sitewards Giveaway - Configuration</title>
22
- <sort_order>1000</sort_order>
23
- </sitewards_giveaway_config>
24
- </children>
25
- </config>
26
- </children>
27
- </system>
28
- </children>
29
- </admin>
30
- </resources>
31
- </acl>
32
  </config>
9
  */
10
  -->
11
  <config>
12
+ <acl>
13
+ <resources>
14
+ <admin>
15
+ <children>
16
+ <system>
17
+ <children>
18
+ <config>
19
+ <children>
20
+ <sitewards_giveaway_config>
21
+ <title>Sitewards Giveaway - Configuration</title>
22
+ <sort_order>1000</sort_order>
23
+ </sitewards_giveaway_config>
24
+ </children>
25
+ </config>
26
+ </children>
27
+ </system>
28
+ </children>
29
+ </admin>
30
+ </resources>
31
+ </acl>
32
  </config>
app/code/community/Sitewards/Giveaway/etc/config.xml CHANGED
@@ -9,112 +9,114 @@
9
  */
10
  -->
11
  <config>
12
- <modules>
13
- <Sitewards_Giveaway>
14
- <version>1.0.1</version>
15
- </Sitewards_Giveaway>
16
- </modules>
17
- <!-- Set the default values for this extension -->
18
- <default>
19
- <sitewards_giveaway_config>
20
- <sitewards_giveaway_general>
21
- <enable_ext>1</enable_ext>
22
- <giveaway_identifier_name>is_giveaway</giveaway_identifier_name>
23
- <giveaways_per_cart>1</giveaways_per_cart>
24
- <giveaways_forward_to_list>1</giveaways_forward_to_list>
25
- </sitewards_giveaway_general>
26
- </sitewards_giveaway_config>
27
- </default>
28
- <global>
29
- <helpers>
30
- <sitewards_giveaway>
31
- <class>Sitewards_Giveaway_Helper</class>
32
- </sitewards_giveaway>
33
- </helpers>
34
- <models>
35
- <sitewards_giveaway>
36
- <class>Sitewards_Giveaway_Model</class>
37
- </sitewards_giveaway>
38
- </models>
39
- <blocks>
40
- <sitewards_giveaway>
41
- <class>Sitewards_Giveaway_Block</class>
42
- </sitewards_giveaway>
43
- <checkout>
44
- <rewrite>
45
- <onepage_link>Sitewards_Giveaway_Block_Checkout_Onepage_Link</onepage_link>
46
- <multishipping_link>Sitewards_Giveaway_Block_Checkout_Multishipping_Link</multishipping_link>
47
- <links>Sitewards_Giveaway_Block_Checkout_Links</links>
48
- <cart_sidebar>Sitewards_Giveaway_Block_Checkout_Cart_Sidebar</cart_sidebar>
49
- </rewrite>
50
- </checkout>
51
- </blocks>
52
- <resources>
53
- <sitewards_giveaway_setup>
54
- <setup>
55
- <module>Sitewards_Giveaway</module>
56
- <class>Sitewards_Giveaway_Model_Resource_Eav_Mysql4_Setup</class>
57
- </setup>
58
- <connection>
59
- <use>core_setup</use>
60
- </connection>
61
- </sitewards_giveaway_setup>
62
- </resources>
63
- </global>
64
- <frontend>
65
- <events>
66
- <checkout_cart_add_product_complete>
67
- <observers>
68
- <myEventForCheckoutCartAddProductComplete>
69
- <type>singleton</type>
70
- <class>sitewards_giveaway/observer</class>
71
- <method>onCheckoutCartAddProductComplete</method>
72
- </myEventForCheckoutCartAddProductComplete>
73
- </observers>
74
- </checkout_cart_add_product_complete>
75
- </events>
76
- <layout>
77
- <updates>
78
- <sitewards_giveaway>
79
- <file>sitewards/giveaway.xml</file>
80
- </sitewards_giveaway>
81
- </updates>
82
- </layout>
83
- <routers>
84
- <sitewards_giveaway>
85
- <use>standard</use>
86
- <args>
87
- <module>Sitewards_Giveaway</module>
88
- <frontName>giveaway</frontName>
89
- </args>
90
- </sitewards_giveaway>
91
- <checkout>
92
- <args>
93
- <modules>
94
- <Sitewards_Giveaway before="Mage_Checkout">Sitewards_Giveaway</Sitewards_Giveaway>
95
- </modules>
96
- </args>
97
- </checkout>
98
- </routers>
99
- <translate>
100
- <modules>
101
- <sitewards_giveaway>
102
- <files>
103
- <default>Sitewards_Giveaway.csv</default>
104
- </files>
105
- </sitewards_giveaway>
106
- </modules>
107
- </translate>
108
- </frontend>
109
- <adminhtml>
110
- <translate>
111
- <modules>
112
- <sitewards_giveaway>
113
- <files>
114
- <default>Sitewards_Giveaway.csv</default>
115
- </files>
116
- </sitewards_giveaway>
117
- </modules>
118
- </translate>
119
- </adminhtml>
 
 
120
  </config>
9
  */
10
  -->
11
  <config>
12
+ <modules>
13
+ <Sitewards_Giveaway>
14
+ <version>1.0.2</version>
15
+ </Sitewards_Giveaway>
16
+ </modules>
17
+ <!-- Set the default values for this extension -->
18
+ <default>
19
+ <sitewards_giveaway_config>
20
+ <sitewards_giveaway_general>
21
+ <enable_ext>1</enable_ext>
22
+ <giveaway_identifier_name>is_giveaway</giveaway_identifier_name>
23
+ <giveaways_per_cart>1</giveaways_per_cart>
24
+ <giveaways_forward_to_list>1</giveaways_forward_to_list>
25
+ <min_products>1</min_products>
26
+ <min_total>0</min_total>
27
+ </sitewards_giveaway_general>
28
+ </sitewards_giveaway_config>
29
+ </default>
30
+ <global>
31
+ <helpers>
32
+ <sitewards_giveaway>
33
+ <class>Sitewards_Giveaway_Helper</class>
34
+ </sitewards_giveaway>
35
+ </helpers>
36
+ <models>
37
+ <sitewards_giveaway>
38
+ <class>Sitewards_Giveaway_Model</class>
39
+ </sitewards_giveaway>
40
+ </models>
41
+ <blocks>
42
+ <sitewards_giveaway>
43
+ <class>Sitewards_Giveaway_Block</class>
44
+ </sitewards_giveaway>
45
+ <checkout>
46
+ <rewrite>
47
+ <onepage_link>Sitewards_Giveaway_Block_Checkout_Onepage_Link</onepage_link>
48
+ <multishipping_link>Sitewards_Giveaway_Block_Checkout_Multishipping_Link</multishipping_link>
49
+ <links>Sitewards_Giveaway_Block_Checkout_Links</links>
50
+ <cart_sidebar>Sitewards_Giveaway_Block_Checkout_Cart_Sidebar</cart_sidebar>
51
+ </rewrite>
52
+ </checkout>
53
+ </blocks>
54
+ <resources>
55
+ <sitewards_giveaway_setup>
56
+ <setup>
57
+ <module>Sitewards_Giveaway</module>
58
+ <class>Sitewards_Giveaway_Model_Resource_Eav_Mysql4_Setup</class>
59
+ </setup>
60
+ <connection>
61
+ <use>core_setup</use>
62
+ </connection>
63
+ </sitewards_giveaway_setup>
64
+ </resources>
65
+ </global>
66
+ <frontend>
67
+ <events>
68
+ <checkout_cart_add_product_complete>
69
+ <observers>
70
+ <myEventForCheckoutCartAddProductComplete>
71
+ <type>singleton</type>
72
+ <class>sitewards_giveaway/observer</class>
73
+ <method>onCheckoutCartAddProductComplete</method>
74
+ </myEventForCheckoutCartAddProductComplete>
75
+ </observers>
76
+ </checkout_cart_add_product_complete>
77
+ </events>
78
+ <layout>
79
+ <updates>
80
+ <sitewards_giveaway>
81
+ <file>sitewards/giveaway.xml</file>
82
+ </sitewards_giveaway>
83
+ </updates>
84
+ </layout>
85
+ <routers>
86
+ <sitewards_giveaway>
87
+ <use>standard</use>
88
+ <args>
89
+ <module>Sitewards_Giveaway</module>
90
+ <frontName>giveaway</frontName>
91
+ </args>
92
+ </sitewards_giveaway>
93
+ <checkout>
94
+ <args>
95
+ <modules>
96
+ <Sitewards_Giveaway before="Mage_Checkout">Sitewards_Giveaway</Sitewards_Giveaway>
97
+ </modules>
98
+ </args>
99
+ </checkout>
100
+ </routers>
101
+ <translate>
102
+ <modules>
103
+ <sitewards_giveaway>
104
+ <files>
105
+ <default>Sitewards_Giveaway.csv</default>
106
+ </files>
107
+ </sitewards_giveaway>
108
+ </modules>
109
+ </translate>
110
+ </frontend>
111
+ <adminhtml>
112
+ <translate>
113
+ <modules>
114
+ <sitewards_giveaway>
115
+ <files>
116
+ <default>Sitewards_Giveaway.csv</default>
117
+ </files>
118
+ </sitewards_giveaway>
119
+ </modules>
120
+ </translate>
121
+ </adminhtml>
122
  </config>
app/code/community/Sitewards/Giveaway/etc/system.xml CHANGED
@@ -9,72 +9,90 @@
9
  */
10
  -->
11
  <config>
12
- <tabs>
13
- <sitewards_giveaway_tab translate="label" module="sitewards_giveaway">
14
- <label>Sitewards Giveaway</label>
15
- <sort_order>1000</sort_order>
16
- </sitewards_giveaway_tab>
17
- </tabs>
18
 
19
- <sections>
20
- <sitewards_giveaway_config translate="label" module="sitewards_giveaway">
21
- <label>Configuration</label>
22
- <tab>sitewards_giveaway_tab</tab>
23
- <show_in_default>1</show_in_default>
24
- <show_in_website>1</show_in_website>
25
- <show_in_store>1</show_in_store>
26
- <sort_order>10</sort_order>
27
- <groups>
28
- <sitewards_giveaway_general translate="label">
29
- <label>General Options</label>
30
- <frontend_type>text</frontend_type>
31
- <sort_order>1</sort_order>
32
- <show_in_default>1</show_in_default>
33
- <show_in_website>1</show_in_website>
34
- <show_in_store>1</show_in_store>
35
- <fields>
36
- <enable_ext translate="label comment">
37
- <label>Enable Extension</label>
38
- <comment>Enable/Disable the Sitewards Giveaway Extension</comment>
39
- <frontend_type>select</frontend_type>
40
- <source_model>adminhtml/system_config_source_yesno</source_model>
41
- <sort_order>1</sort_order>
42
- <show_in_default>1</show_in_default>
43
- <show_in_website>1</show_in_website>
44
- <show_in_store>1</show_in_store>
45
- </enable_ext>
46
- <giveaway_identifier_name translate="label comment">
47
- <label>Product Idetifier</label>
48
- <comment>Attribute that identifies a product as a giveaway</comment>
49
- <frontend_type>select</frontend_type>
50
- <sort_order>2</sort_order>
51
- <show_in_default>1</show_in_default>
52
- <show_in_website>1</show_in_website>
53
- <show_in_store>1</show_in_store>
54
- <source_model>sitewards_giveaway/system_config_product_identifier</source_model>
55
- </giveaway_identifier_name>
56
- <giveaways_per_cart translate="label comment">
57
- <label>Product Count</label>
58
- <comment>Number of giveaway products allowed per cart</comment>
59
- <frontend_type>text</frontend_type>
60
- <sort_order>3</sort_order>
61
- <show_in_default>1</show_in_default>
62
- <show_in_website>1</show_in_website>
63
- <show_in_store>1</show_in_store>
64
- </giveaways_per_cart>
65
- <giveaways_forward_to_list translate="label comment">
66
- <label>Forward to Giveaway Page</label>
67
- <comment>Should users be forwarded to giveaways page after adding a product to the cart?</comment>
68
- <frontend_type>select</frontend_type>
69
- <source_model>adminhtml/system_config_source_yesno</source_model>
70
- <sort_order>4</sort_order>
71
- <show_in_default>1</show_in_default>
72
- <show_in_website>1</show_in_website>
73
- <show_in_store>1</show_in_store>
74
- </giveaways_forward_to_list>
75
- </fields>
76
- </sitewards_giveaway_general>
77
- </groups>
78
- </sitewards_giveaway_config>
79
- </sections>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
80
  </config>
9
  */
10
  -->
11
  <config>
12
+ <tabs>
13
+ <sitewards_giveaway_tab translate="label" module="sitewards_giveaway">
14
+ <label>Sitewards Giveaway</label>
15
+ <sort_order>1000</sort_order>
16
+ </sitewards_giveaway_tab>
17
+ </tabs>
18
 
19
+ <sections>
20
+ <sitewards_giveaway_config translate="label" module="sitewards_giveaway">
21
+ <label>Configuration</label>
22
+ <tab>sitewards_giveaway_tab</tab>
23
+ <show_in_default>1</show_in_default>
24
+ <show_in_website>1</show_in_website>
25
+ <show_in_store>1</show_in_store>
26
+ <sort_order>10</sort_order>
27
+ <groups>
28
+ <sitewards_giveaway_general translate="label">
29
+ <label>General Options</label>
30
+ <frontend_type>text</frontend_type>
31
+ <sort_order>1</sort_order>
32
+ <show_in_default>1</show_in_default>
33
+ <show_in_website>1</show_in_website>
34
+ <show_in_store>1</show_in_store>
35
+ <fields>
36
+ <enable_ext translate="label comment">
37
+ <label>Enable Extension</label>
38
+ <comment>Enable/Disable the Sitewards Giveaway Extension</comment>
39
+ <frontend_type>select</frontend_type>
40
+ <source_model>adminhtml/system_config_source_yesno</source_model>
41
+ <sort_order>1</sort_order>
42
+ <show_in_default>1</show_in_default>
43
+ <show_in_website>1</show_in_website>
44
+ <show_in_store>1</show_in_store>
45
+ </enable_ext>
46
+ <giveaway_identifier_name translate="label comment">
47
+ <label>Product Idetifier</label>
48
+ <comment>Attribute that identifies a product as a giveaway</comment>
49
+ <frontend_type>select</frontend_type>
50
+ <sort_order>2</sort_order>
51
+ <show_in_default>1</show_in_default>
52
+ <show_in_website>1</show_in_website>
53
+ <show_in_store>1</show_in_store>
54
+ <source_model>sitewards_giveaway/system_config_product_identifier</source_model>
55
+ </giveaway_identifier_name>
56
+ <giveaways_per_cart translate="label comment">
57
+ <label>Giveaway Count</label>
58
+ <comment>Number of giveaway products allowed per cart</comment>
59
+ <frontend_type>text</frontend_type>
60
+ <sort_order>3</sort_order>
61
+ <show_in_default>1</show_in_default>
62
+ <show_in_website>1</show_in_website>
63
+ <show_in_store>1</show_in_store>
64
+ </giveaways_per_cart>
65
+ <giveaways_forward_to_list translate="label comment">
66
+ <label>Forward to Giveaway Page</label>
67
+ <comment>Should users be forwarded to giveaways page after adding a product to the cart?</comment>
68
+ <frontend_type>select</frontend_type>
69
+ <source_model>adminhtml/system_config_source_yesno</source_model>
70
+ <sort_order>4</sort_order>
71
+ <show_in_default>1</show_in_default>
72
+ <show_in_website>1</show_in_website>
73
+ <show_in_store>1</show_in_store>
74
+ </giveaways_forward_to_list>
75
+ <min_products translate="label comment">
76
+ <label>Product Count</label>
77
+ <comment>Number of products required in cart to add giveaways</comment>
78
+ <frontend_type>text</frontend_type>
79
+ <sort_order>5</sort_order>
80
+ <show_in_default>1</show_in_default>
81
+ <show_in_website>1</show_in_website>
82
+ <show_in_store>1</show_in_store>
83
+ </min_products>
84
+ <min_total translate="label comment">
85
+ <label>Min. Total</label>
86
+ <comment>Min. total required in cart to add giveaways</comment>
87
+ <frontend_type>text</frontend_type>
88
+ <sort_order>6</sort_order>
89
+ <show_in_default>1</show_in_default>
90
+ <show_in_website>1</show_in_website>
91
+ <show_in_store>1</show_in_store>
92
+ </min_total>
93
+ </fields>
94
+ </sitewards_giveaway_general>
95
+ </groups>
96
+ </sitewards_giveaway_config>
97
+ </sections>
98
  </config>
app/design/frontend/base/default/layout/sitewards/giveaway.xml CHANGED
@@ -9,33 +9,44 @@
9
  */
10
  -->
11
  <layout>
12
- <!--
13
- Giveaway default layout
14
- url: giveaway/index/index
15
- -->
16
- <sitewards_giveaway_index_index>
17
- <label>Quick Search Form</label>
18
- <reference name="root">
19
- <action method="setTemplate"><template>page/2columns-left.phtml</template></action>
20
- </reference>
21
- <reference name="content">
22
- <block type="catalogsearch/result" name="search.result" template="catalogsearch/result.phtml">
23
- <action method="setHeaderText" translate="text"><text>Free Allowances</text></action>
24
- <block type="sitewards_giveaway/product_list_giveaway" name="search_result_list" template="catalog/product/list.phtml">
25
- <block type="catalog/product_list_toolbar" name="product_list_toolbar" template="catalog/product/list/toolbar.phtml">
26
- <block type="page/html_pager" name="product_list_toolbar_pager"/>
27
- </block>
28
- <action method="addColumnCountLayoutDepend"><layout>empty</layout><count>6</count></action>
29
- <action method="addColumnCountLayoutDepend"><layout>one_column</layout><count>5</count></action>
30
- <action method="addColumnCountLayoutDepend"><layout>two_columns_left</layout><count>4</count></action>
31
- <action method="addColumnCountLayoutDepend"><layout>two_columns_right</layout><count>4</count></action>
32
- <action method="addColumnCountLayoutDepend"><layout>three_columns</layout><count>3</count></action>
33
- <action method="setToolbarBlockName"><name>product_list_toolbar</name></action>
34
- </block>
35
- <action method="setListOrders"/>
36
- <action method="setListModes"/>
37
- <action method="setListCollection"/>
38
- </block>
39
- </reference>
40
- </sitewards_giveaway_index_index>
 
 
 
 
 
 
 
 
 
 
 
41
  </layout>
9
  */
10
  -->
11
  <layout>
12
+ <!--
13
+ Giveaway default layout
14
+ url: giveaway/index/index
15
+ -->
16
+ <sitewards_giveaway_index_index>
17
+ <label>Quick Search Form</label>
18
+ <reference name="root">
19
+ <action method="setTemplate"><template>page/2columns-left.phtml</template></action>
20
+ </reference>
21
+ <reference name="content">
22
+ <block type="sitewards_giveaway/product_list_giveaway" name="allowanceslist" template="catalog/product/list.phtml">
23
+ <block type="catalog/product_list_toolbar" name="product_list_toolbar" template="catalog/product/list/toolbar.phtml">
24
+ <block type="page/html_pager" name="product_list_toolbar_pager"/>
25
+ </block>
26
+ <action method="addColumnCountLayoutDepend">
27
+ <layout>empty</layout>
28
+ <count>6</count>
29
+ </action>
30
+ <action method="addColumnCountLayoutDepend">
31
+ <layout>one_column</layout>
32
+ <count>5</count>
33
+ </action>
34
+ <action method="addColumnCountLayoutDepend">
35
+ <layout>two_columns_left</layout>
36
+ <count>4</count>
37
+ </action>
38
+ <action method="addColumnCountLayoutDepend">
39
+ <layout>two_columns_right</layout>
40
+ <count>4</count>
41
+ </action>
42
+ <action method="addColumnCountLayoutDepend">
43
+ <layout>three_columns</layout>
44
+ <count>3</count>
45
+ </action>
46
+ <action method="setToolbarBlockName">
47
+ <name>product_list_toolbar</name>
48
+ </action>
49
+ </block>
50
+ </reference>
51
+ </sitewards_giveaway_index_index>
52
  </layout>
app/etc/modules/Sitewards_Giveaway.xml CHANGED
@@ -1,14 +1,14 @@
1
- <?xml version="1.0"?>
2
- <config>
3
- <modules>
4
- <Sitewards_Giveaway>
5
- <active>true</active>
6
- <codePool>community</codePool>
7
- <depends>
8
- <Mage_Catalog />
9
- <Mage_CatalogSearch />
10
- <Mage_Eav />
11
- </depends>
12
- </Sitewards_Giveaway>
13
- </modules>
14
- </config>
1
+ <?xml version="1.0"?>
2
+ <config>
3
+ <modules>
4
+ <Sitewards_Giveaway>
5
+ <active>true</active>
6
+ <codePool>community</codePool>
7
+ <depends>
8
+ <Mage_Catalog />
9
+ <Mage_CatalogSearch />
10
+ <Mage_Eav />
11
+ </depends>
12
+ </Sitewards_Giveaway>
13
+ </modules>
14
+ </config>
app/locale/de_DE/Sitewards_Giveaway.csv CHANGED
@@ -1,11 +1,17 @@
1
- "Configuration","Konfiguration"
2
- "General Options","Allgemeine Optionen"
3
- "Enable Extension","Extension aktivieren"
4
- "Enable/Disable the Sitewards Giveaway Extension","Aktivieren oder Deaktiveren der Sitewards Giveaway-Extension"
5
- "Product Idetifier","Produktattribut"
6
- "Attribute that identifies a product as a giveaway","Attribut, um Produkte als Giveaways zu kennzeichnen"
7
- "Product Count","Produktanzahl"
8
- "Number of giveaway products allowed per cart","Anzahl der Giveaway-Produkte, die pro Warenkorb erlaubt sind"
9
- "Forward to Giveaway Page","Zu Giveaway-Seite weiterleiten"
10
- "Should users be forwarded to giveaways page after adding a product to the cart?","Sollen die Kunden zu Giveaway-Seite weitergeleitet werden, nachdem sie ein Produkt in den Warenkorb gelegt haben?"
11
- "Cannot add the item to shopping cart. You have already reached your limit of giveaway products.","Dieses Produkt kann nicht in den Warenkorb gelegt werden. Sie haben bereits die Maximalanzahl der Giveaway-Produkte im Warenkorb erreicht."
 
 
 
 
 
 
1
+ "Configuration","Konfiguration"
2
+ "General Options","Allgemeine Optionen"
3
+ "Enable Extension","Extension aktivieren"
4
+ "Enable/Disable the Sitewards Giveaway Extension","Aktivieren oder Deaktiveren der Sitewards Giveaway-Extension"
5
+ "Product Idetifier","Produktattribut"
6
+ "Attribute that identifies a product as a giveaway","Attribut, um Produkte als Giveaways zu kennzeichnen"
7
+ "Giveaway Count","Giveawayanzahl"
8
+ "Product Count","Produktanzahl"
9
+ "Number of giveaway products allowed per cart","Anzahl der Giveaway-Produkte, die pro Warenkorb erlaubt sind"
10
+ "Forward to Giveaway Page","Zu Giveaway-Seite weiterleiten"
11
+ "Should users be forwarded to giveaways page after adding a product to the cart?","Sollen die Kunden zu Giveaway-Seite weitergeleitet werden, nachdem sie ein Produkt in den Warenkorb gelegt haben?"
12
+ "Number of products required in cart to add giveaways","Anzahl an normalen Produkten, die im Warenkorb benötigt werden, um Giveaways hinzuzufügen"
13
+ "Min. total required in cart to add giveaways","Mindeststumme die benötigt wird, um Giveaways in den Warenkorb hinzuzufügen"
14
+ "Cannot add item(s) to your shopping cart.","Das Produkt kann leider nicht zum Warenkorb hinzugefügt werden."
15
+ "You can have only %s giveaway item(s) per cart.","Sie können nur %s Giveaway(s) pro Warenkorb haben."
16
+ "The total number of items in your cart must be at least %s.","Sie müssen mindestens %s Produkte in Ihrem Warenkorb haben."
17
+ "The total of the cart must be at least %s.","Die Gesamtsumme Ihres Warenkorbs muss mindestens %s betragen."
package.xml CHANGED
@@ -1,7 +1,7 @@
1
  <?xml version="1.0"?>
2
  <package>
3
  <name>sitewards_giveaway</name>
4
- <version>1.0.1</version>
5
  <stability>stable</stability>
6
  <license uri="http://www.opensource.org/licenses/gpl-license.php">GPL</license>
7
  <channel>community</channel>
@@ -22,11 +22,12 @@ Installation instruction&#xD;
22
  2. Edit products you want to be available as giveaways. Price of these products should be 0, but can be higher if required&#xD;
23
  3. Change the giveaway-attribute of these products to "yes"&#xD;
24
  4. If needed, adjust the allowed amount of giveaway products per cart in the configuration section </description>
25
- <notes>Fixed block names for *nix systems</notes>
 
26
  <authors><author><name>Sitewards Magento Team</name><user>sitewards</user><email>magento@sitewards.com</email></author></authors>
27
- <date>2013-02-07</date>
28
- <time>14:28:15</time>
29
- <contents><target name="magecommunity"><dir name="Sitewards"><dir name="Giveaway"><dir name="Block"><dir name="Checkout"><dir name="Cart"><file name="Sidebar.php" hash="5253c8684ac81739e4ef844b4a8256e5"/></dir><file name="Links.php" hash="385d0a4351445086d36db43eafc41889"/><dir name="Multishipping"><file name="Link.php" hash="ee5179d4b013ceab59ccf3574cde2bca"/></dir><dir name="Onepage"><file name="Link.php" hash="4e76c136d314206ba44c88e222032311"/></dir></dir><dir name="Product"><dir name="List"><file name="Giveaway.php" hash="30fd87c8b0f30d83b27b3b6ac60a61bf"/></dir><file name="ListTitle.php" hash="133048adeb2fb03da81445719a984fea"/></dir></dir><dir name="Helper"><file name="Data.php" hash="4a62d7daceffa80ddcbf108089107f75"/></dir><dir name="Model"><file name="Observer.php" hash="80728f02442ca2b6b8ceee0a01201bcf"/><dir name="Resource"><dir name="Eav"><dir name="Mysql4"><file name="Setup.php" hash="27b268c161c0c3ebbedada6e9cd78d27"/></dir></dir></dir><dir name="System"><dir name="Config"><dir name="Product"><file name="Identifier.php" hash="20c9c69bd43019c3bd56b568ed521aad"/></dir></dir></dir></dir><dir name="controllers"><file name="CartController.php" hash="6224f8ce2a8b8ae81d4b7fa594bf4bf9"/><file name="IndexController.php" hash="7b1a51d0924883992318bb3d72dd1fa5"/></dir><dir name="etc"><file name="adminhtml.xml" hash="69a88bc583b6a811f47fbd33196f036b"/><file name="config.xml" hash="d0630e7e7074b29232b30e8a36698fa5"/><file name="system.xml" hash="13ae3261b97f8ae704d85096e21c5da1"/></dir><dir name="sql"><dir name="sitewards_giveaway_setup"><file name="mysql4-install-1.0.0.php" hash="2df441a6f1f7a7be6734c0e9105fda17"/></dir></dir></dir></dir></target><target name="magedesign"><dir name="frontend"><dir name="base"><dir name="default"><dir name="layout"><dir name="sitewards"><file name="giveaway.xml" hash="cfb9a1785d6f4be7ce980984513ff296"/></dir></dir><dir name="template"><dir name="sitewards"><dir name="giveaway"><dir name="catalog"><dir name="product"><file name="list_title.phtml" hash="9721358bb3d1e3a9586cf4366a8475f8"/></dir></dir></dir></dir></dir></dir></dir></dir></target><target name="mageetc"><dir name="modules"><file name="Sitewards_Giveaway.xml" hash="bf14932448cc724744ce93ac06226b5e"/></dir></target><target name="magelocale"><dir name="de_DE"><file name="Sitewards_Giveaway.csv" hash="db5754d5d983abeb4d9efee07b13476e"/></dir></target></contents>
30
  <compatible/>
31
- <dependencies><required><php><min>5.2.0</min><max>6.0.0</max></php></required></dependencies>
32
  </package>
1
  <?xml version="1.0"?>
2
  <package>
3
  <name>sitewards_giveaway</name>
4
+ <version>1.0.2</version>
5
  <stability>stable</stability>
6
  <license uri="http://www.opensource.org/licenses/gpl-license.php">GPL</license>
7
  <channel>community</channel>
22
  2. Edit products you want to be available as giveaways. Price of these products should be 0, but can be higher if required&#xD;
23
  3. Change the giveaway-attribute of these products to "yes"&#xD;
24
  4. If needed, adjust the allowed amount of giveaway products per cart in the configuration section </description>
25
+ <notes>Fixed problems with adding products to shopping cart.&#xD;
26
+ Now extension requires php 5.3 and later.</notes>
27
  <authors><author><name>Sitewards Magento Team</name><user>sitewards</user><email>magento@sitewards.com</email></author></authors>
28
+ <date>2013-10-29</date>
29
+ <time>17:11:58</time>
30
+ <contents><target name="magecommunity"><dir name="Sitewards"><dir name="Giveaway"><dir name="Block"><dir name="Checkout"><dir name="Cart"><file name="Sidebar.php" hash="be8d03f390d69d85425251e9d9bd8732"/></dir><file name="Links.php" hash="2365017c4b2a562c03f35757cc243639"/><dir name="Multishipping"><file name="Link.php" hash="8e657966a5cdbcb7fdb533d903e1a19c"/></dir><dir name="Onepage"><file name="Link.php" hash="4d5af83e5ad75edbb565a167b86a1c59"/></dir></dir><dir name="Product"><dir name="List"><file name="Giveaway.php" hash="180bd33b9af118bb43ceba08da1c04a4"/></dir><file name="ListTitle.php" hash="988356bdf3b5556e8493297a4066794e"/></dir></dir><dir name="Helper"><file name="Data.php" hash="08b7a484b453ac1f4ab07f10d3586363"/></dir><dir name="Model"><file name="Observer.php" hash="5625c5b0346377152c4310a67ee40344"/><dir name="Product"><dir name="Quantity"><file name="Collection.php" hash="d1cb66cf0be7171c76b9bc030ea0bf7e"/></dir><file name="Quantity.php" hash="a8cb19d4844da5b98a08f6e3814b92e7"/></dir><dir name="Resource"><dir name="Eav"><dir name="Mysql4"><file name="Setup.php" hash="9218bf7a84061def3656ef0982c48607"/></dir></dir></dir><dir name="System"><dir name="Config"><dir name="Product"><file name="Identifier.php" hash="1d468d4bab7dec446519fe7404aadfb9"/></dir></dir></dir></dir><dir name="controllers"><file name="CartController.php" hash="b5cf9f0309cac9e1e518c0930601b6c0"/><file name="IndexController.php" hash="967ca053bfdece22dc7af7e9db030c33"/></dir><dir name="etc"><file name="adminhtml.xml" hash="3e15322a141e4c66aeede21ce57a846a"/><file name="config.xml" hash="d7d549e635e16cf383a1a6bb78afeb34"/><file name="system.xml" hash="56de839b74eb72d0dabe8cd1d8b4dba9"/></dir><dir name="sql"><dir name="sitewards_giveaway_setup"><file name="mysql4-install-1.0.0.php" hash="2df441a6f1f7a7be6734c0e9105fda17"/></dir></dir></dir></dir></target><target name="mageetc"><dir name="modules"><file name="Sitewards_Giveaway.xml" hash="2972fa61d19ff88c192839929cc34be7"/></dir></target><target name="magelocale"><dir name="de_DE"><file name="Sitewards_Giveaway.csv" hash="b922e57e6bd1ef755581ae7ff6fa6e8b"/></dir></target><target name="magedesign"><dir name="frontend"><dir name="base"><dir name="default"><dir name="layout"><dir name="sitewards"><file name="giveaway.xml" hash="ec6db9c32019e9b19d216ab9d6aeb677"/></dir></dir><dir name="template"><dir name="sitewards"><dir name="giveaway"><dir name="catalog"><dir name="product"><file name="list_title.phtml" hash="9721358bb3d1e3a9586cf4366a8475f8"/></dir></dir></dir></dir></dir></dir></dir></dir></target></contents>
31
  <compatible/>
32
+ <dependencies><required><php><min>5.3.0</min><max>6.0.0</max></php></required></dependencies>
33
  </package>