Version Notes
First release
Download this release
Release Info
Developer | Sitewards Magento Team |
Extension | sitewards_giveaway |
Version | 1.0.0 |
Comparing to | |
See all releases |
Version 1.0.0
- app/code/community/Sitewards/Giveaway/Block/Checkout/Cart/Sidebar.php +29 -0
- app/code/community/Sitewards/Giveaway/Block/Checkout/Links.php +28 -0
- app/code/community/Sitewards/Giveaway/Block/Checkout/Multishipping/Link.php +28 -0
- app/code/community/Sitewards/Giveaway/Block/Checkout/Onepage/Link.php +31 -0
- app/code/community/Sitewards/Giveaway/Block/Product/List/Giveaway.php +102 -0
- app/code/community/Sitewards/Giveaway/Block/Product/ListTitle.php +16 -0
- app/code/community/Sitewards/Giveaway/Helper/Data.php +160 -0
- app/code/community/Sitewards/Giveaway/Model/Observer.php +35 -0
- app/code/community/Sitewards/Giveaway/Model/Resource/Eav/Mysql4/Setup.php +52 -0
- app/code/community/Sitewards/Giveaway/Model/System/Config/Product/Identifier.php +38 -0
- app/code/community/Sitewards/Giveaway/controllers/CartController.php +117 -0
- app/code/community/Sitewards/Giveaway/controllers/IndexController.php +19 -0
- app/code/community/Sitewards/Giveaway/etc/adminhtml.xml +32 -0
- app/code/community/Sitewards/Giveaway/etc/config.xml +120 -0
- app/code/community/Sitewards/Giveaway/etc/system.xml +80 -0
- app/code/community/Sitewards/Giveaway/sql/sitewards_giveaway_setup/mysql4-install-1.0.0.php +4 -0
- app/design/frontend/base/default/layout/sitewards/giveaway.xml +41 -0
- app/design/frontend/base/default/template/sitewards/giveaway/catalog/product/list_title.phtml +1 -0
- app/etc/modules/Sitewards_Giveaway.xml +14 -0
- app/locale/de_DE/Sitewards_Giveaway.csv +11 -0
- package.xml +32 -0
app/code/community/Sitewards/Giveaway/Block/Checkout/Cart/Sidebar.php
ADDED
@@ -0,0 +1,29 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* Sitewards_Giveaway_Block_Checkout_Onepage_Cart_Sidebar
|
4 |
+
*
|
5 |
+
* Handling of checkout button in the cart block on sidebar
|
6 |
+
*
|
7 |
+
* @category Sitewards
|
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 |
+
}
|
app/code/community/Sitewards/Giveaway/Block/Checkout/Links.php
ADDED
@@ -0,0 +1,28 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* Sitewards_Giveaway_Block_Checkout_Links
|
4 |
+
*
|
5 |
+
* Handling of checkout link in the header
|
6 |
+
*
|
7 |
+
* @category Sitewards
|
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 |
+
}
|
app/code/community/Sitewards/Giveaway/Block/Checkout/Multishipping/Link.php
ADDED
@@ -0,0 +1,28 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* Sitewards_Giveaway_Block_Checkout_Multishipping_Link
|
4 |
+
*
|
5 |
+
* Handling of "checkout with multiple addresses" link in the cart
|
6 |
+
*
|
7 |
+
* @category Sitewards
|
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 |
+
}
|
app/code/community/Sitewards/Giveaway/Block/Checkout/Onepage/Link.php
ADDED
@@ -0,0 +1,31 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* Sitewards_Giveaway_Block_Checkout_Onepage_Link
|
4 |
+
*
|
5 |
+
* Handling of checkout button in the cart
|
6 |
+
*
|
7 |
+
* @category Sitewards
|
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 |
+
}
|
app/code/community/Sitewards/Giveaway/Block/Product/List/Giveaway.php
ADDED
@@ -0,0 +1,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 |
+
*
|
8 |
+
* @category Sitewards
|
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 |
+
}
|
app/code/community/Sitewards/Giveaway/Block/Product/ListTitle.php
ADDED
@@ -0,0 +1,16 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* Sitewards_Giveaway_Block_Product_ListTitle
|
4 |
+
*
|
5 |
+
* Basic block for rendering of page title
|
6 |
+
*
|
7 |
+
* @category Sitewards
|
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 |
+
}
|
app/code/community/Sitewards/Giveaway/Helper/Data.php
ADDED
@@ -0,0 +1,160 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* Sitewards_Giveaway_Helper_Data
|
4 |
+
*
|
5 |
+
* A helper class to read all the extension setting variables
|
6 |
+
*
|
7 |
+
* @category Sitewards
|
8 |
+
* @package Sitewards_Giveaway
|
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 |
+
}
|
app/code/community/Sitewards/Giveaway/Model/Observer.php
ADDED
@@ -0,0 +1,35 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* Sitewards_Giveaway_Model_Observer
|
4 |
+
*
|
5 |
+
* An observer for adding a product to the cart and
|
6 |
+
* redirecting to giveaway page if certain criteria are fulfilled
|
7 |
+
*
|
8 |
+
* @category Sitewards
|
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 |
+
}
|
app/code/community/Sitewards/Giveaway/Model/Resource/Eav/Mysql4/Setup.php
ADDED
@@ -0,0 +1,52 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* Sitewards_Giveaway_Model_Resource_Eav_Mysql4_Setup
|
4 |
+
*
|
5 |
+
* New attribute for giveaway products
|
6 |
+
*
|
7 |
+
* @category Sitewards
|
8 |
+
* @package Sitewards_Giveaway
|
9 |
+
* @copyright Copyright (c) 2012 Sitewards GmbH (http://www.sitewards.com/de/)
|
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
ADDED
@@ -0,0 +1,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 |
+
*
|
8 |
+
* @category Sitewards
|
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 |
+
}
|
app/code/community/Sitewards/Giveaway/controllers/CartController.php
ADDED
@@ -0,0 +1,117 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* Sitewards_Giveaway_CartController
|
4 |
+
*
|
5 |
+
* Extends the main cart functionality for handling of giveaway products
|
6 |
+
*
|
7 |
+
* @category Sitewards
|
8 |
+
* @package Sitewards_Giveaway
|
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 |
+
}
|
app/code/community/Sitewards/Giveaway/controllers/IndexController.php
ADDED
@@ -0,0 +1,19 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* Sitewards_Giveaway_IndexController
|
4 |
+
*
|
5 |
+
* Loads and renders the layout for all actions in the Sitewards_Giveaway module
|
6 |
+
*
|
7 |
+
* @category Sitewards
|
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 |
+
}
|
app/code/community/Sitewards/Giveaway/etc/adminhtml.xml
ADDED
@@ -0,0 +1,32 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?xml version="1.0" encoding="UTF-8"?>
|
2 |
+
<!--
|
3 |
+
/**
|
4 |
+
* The adminhtml config file of the Sitewards Giveaway extension
|
5 |
+
*
|
6 |
+
* @category Sitewards
|
7 |
+
* @package Sitewards_Giveaway
|
8 |
+
* @copyright Copyright (c) 2012 Sitewards GmbH (http://www.sitewards.com/de/)
|
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
ADDED
@@ -0,0 +1,120 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?xml version="1.0" encoding="UTF-8"?>
|
2 |
+
<!--
|
3 |
+
/**
|
4 |
+
* The main config file of the Sitewards Giveaway extension
|
5 |
+
*
|
6 |
+
* @category Sitewards
|
7 |
+
* @package Sitewards_Giveaway
|
8 |
+
* @copyright Copyright (c) 2012 Sitewards GmbH (http://www.sitewards.com/de/)
|
9 |
+
*/
|
10 |
+
-->
|
11 |
+
<config>
|
12 |
+
<modules>
|
13 |
+
<Sitewards_Giveaway>
|
14 |
+
<version>1.0.0</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>
|
app/code/community/Sitewards/Giveaway/etc/system.xml
ADDED
@@ -0,0 +1,80 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?xml version="1.0" encoding="UTF-8"?>
|
2 |
+
<!--
|
3 |
+
/**
|
4 |
+
* The system config file of the Sitewards Giveaway extension
|
5 |
+
*
|
6 |
+
* @category Sitewards
|
7 |
+
* @package Sitewards_Giveaway
|
8 |
+
* @copyright Copyright (c) 2012 Sitewards GmbH (http://www.sitewards.com/de/)
|
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>
|
app/code/community/Sitewards/Giveaway/sql/sitewards_giveaway_setup/mysql4-install-1.0.0.php
ADDED
@@ -0,0 +1,4 @@
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
$installer = $this;
|
3 |
+
|
4 |
+
$installer->installEntities();
|
app/design/frontend/base/default/layout/sitewards/giveaway.xml
ADDED
@@ -0,0 +1,41 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?xml version="1.0" encoding="UTF-8"?>
|
2 |
+
<!--
|
3 |
+
/**
|
4 |
+
* The layout xml file of the Sitewards Giveaway extension
|
5 |
+
*
|
6 |
+
* @category Sitewards
|
7 |
+
* @package Sitewards_Giveaway
|
8 |
+
* @copyright Copyright (c) 2012 Sitewards GmbH (http://www.sitewards.com/de/)
|
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>
|
app/design/frontend/base/default/template/sitewards/giveaway/catalog/product/list_title.phtml
ADDED
@@ -0,0 +1 @@
|
|
|
1 |
+
<div class="page-title category-title"><h1><?php echo $this->getPageTitle(); ?></h1></div>
|
app/etc/modules/Sitewards_Giveaway.xml
ADDED
@@ -0,0 +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>
|
app/locale/de_DE/Sitewards_Giveaway.csv
ADDED
@@ -0,0 +1,11 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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."
|
package.xml
ADDED
@@ -0,0 +1,32 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?xml version="1.0"?>
|
2 |
+
<package>
|
3 |
+
<name>sitewards_giveaway</name>
|
4 |
+
<version>1.0.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>This magento extension provides functionality for handling giveaway products in the shop.</summary>
|
10 |
+
<description>Customization
|
11 |
+
-------------
|
12 |
+

|
13 |
+
You can adjust following behaviour:
|
14 |
+
* Define products as giveaways
|
15 |
+
* Change allowed amount of giveaway products per cart
|
16 |
+
* Decide if the customer should be forwarded to giveaway overview page after adding a product to the cart 
|
17 |
+

|
18 |
+
Installation instruction
|
19 |
+
------------------------
|
20 |
+

|
21 |
+
1. Install and activate the extension
|
22 |
+
2. Edit products you want to be available as giveaways. Price of these products should be 0, but can be higher if required
|
23 |
+
3. Change the giveaway-attribute of these products to "yes"
|
24 |
+
4. If needed, adjust the allowed amount of giveaway products per cart in the configuration section </description>
|
25 |
+
<notes>First release</notes>
|
26 |
+
<authors><author><name>Sitewards Magento Team</name><user>sitewards</user><email>magento@sitewards.com</email></author></authors>
|
27 |
+
<date>2013-02-06</date>
|
28 |
+
<time>10:50:53</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="d387dc272607dd9fb5799d6811dd4b1a"/></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="a5d13c3ad028a1694b4d2a994330086c"/><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>
|