shareagift_core - Version 0.0.1

Version Notes

Initial Release

Download this release

Release Info

Developer Magento Core Team
Extension shareagift_core
Version 0.0.1
Comparing to
See all releases


Version 0.0.1

app/code/community/Shareagift/Core/Helper/Config.php ADDED
@@ -0,0 +1,20 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Shareagift_Core_Helper_Config extends Mage_Core_Helper_Abstract {
4
+
5
+ public function isEnabled() {
6
+ return Mage::getStoreConfigFlag('shareagift/general/enabled');
7
+ }
8
+
9
+ public function getMerchantId() {
10
+ return Mage::getStoreConfig('shareagift/general/merchantid');
11
+ }
12
+
13
+ public function isConfigured() {
14
+ return $this->isEnabled() && $this->getMerchantId() != "";
15
+ }
16
+
17
+ public function useButton() {
18
+ return !Mage::getStoreConfig('shareagift/general/button');
19
+ }
20
+ }
app/code/community/Shareagift/Core/Helper/Data.php ADDED
@@ -0,0 +1,117 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Shareagift_Core_Helper_Data extends Mage_Core_Helper_Abstract {
4
+
5
+ const SHAREAGIFT_URL = 'http://www.shareagift.com/API/default.aspx';
6
+ const USD_CODE = 'USD';
7
+
8
+ /**
9
+ * Get Group Gift URL
10
+ * @param $product Mage_Catalog_Model_Product
11
+ * @return string
12
+ */
13
+ public function getGroupGiftUrl($product) {
14
+ /** @var $config Shareagift_Core_Helper_Config */
15
+ $config = Mage::helper('shareagift/config');
16
+
17
+ /** @var $imageHelper Mage_Catalog_Helper_Image */
18
+ $imageHelper = Mage::helper('catalog/image');
19
+
20
+
21
+
22
+ if (!$config->isConfigured())
23
+ return false;
24
+
25
+ if (!$product instanceof Mage_Catalog_Model_Product)
26
+ return false;
27
+
28
+ $params = array(
29
+ 'MerchantID' => $config->getMerchantId(),
30
+ 'ProductID' => $product->getSku(),
31
+ 'ProductName' => $product->getName(),
32
+ 'ProductDescription' => $this->stripTags($product->getDescription()),
33
+ 'ProductPrice' => $this->getDisplayPrice($product), // This won't work for bundle products
34
+ 'ProductCurrency' => Mage::app()->getStore()->getCurrentCurrencyCode(),
35
+ 'ProductImageUrl' => (string) $imageHelper->init($product, 'image')->__toString(),
36
+ 'ProductURL' => $product->getProductUrl()
37
+ );
38
+
39
+ /** @var Mage_Customer_Model_Session $customer */
40
+ $customer = Mage::getSingleton('customer/session');
41
+ if($customer->isLoggedIn()) {
42
+ $customer = Mage::getModel('customer/customer')->load($customer->getId());
43
+ $params = array_merge($params, array(
44
+ 'CustomerFirstname' => $customer->getFirstname(),
45
+ 'CustomerSurname' => $customer->getLastname(),
46
+ 'CustomerEmail' => $customer->getEmail()
47
+ ));
48
+ }
49
+
50
+ return self::SHAREAGIFT_URL . "?" . http_build_query($params);
51
+ }
52
+
53
+
54
+ /**
55
+ * Convert product price to USD
56
+ * @param $price float
57
+ * @return float
58
+ */
59
+ private function convertToUSD($price) {
60
+ /** @var Mage_Directory_Model_Currency $currencyModel */
61
+ $currencyModel = Mage::getModel('directory/currency');
62
+ $currentCurrencyCode = Mage::app()->getStore()->getCurrentCurrencyCode();
63
+
64
+ /** Return current price if already in USD */
65
+ if($currentCurrencyCode == self::USD_CODE)
66
+ return $price;
67
+
68
+ /** Check if USD currency is configured and rates imported */
69
+ if(in_array(self::USD_CODE, $currencyModel->getConfigAllowCurrencies()) &&
70
+ $currencyModel->getCurrencyRates($currentCurrencyCode, self::USD_CODE)) {
71
+ return (float) round(Mage::helper('directory')->currencyConvert($price, $currentCurrencyCode, self::USD_CODE), 2);
72
+ }
73
+
74
+ // Otherwise return current price and log an error
75
+ Mage::log('Shareagift: USD Currency not configured and/or rates not imported in Magento.');
76
+ return $price;
77
+ }
78
+
79
+ /**
80
+ * Get price for a product, bundle product special case
81
+ * @url http://stackoverflow.com/questions/15160491/magento-get-max-and-min-price-for-bundle-product
82
+ * @param $product Mage_Catalog_Model_Product
83
+ * @return float
84
+ */
85
+ public function getDisplayPrice($product) {
86
+ if($product->getFinalPrice()) {
87
+ return $product->getFinalPrice();
88
+ } else if ($product->getTypeId() == Mage_Catalog_Model_Product_Type::TYPE_BUNDLE) {
89
+ $optionCol= $product->getTypeInstance(true)
90
+ ->getOptionsCollection($product);
91
+ $selectionCol= $product->getTypeInstance(true)
92
+ ->getSelectionsCollection(
93
+ $product->getTypeInstance(true)->getOptionsIds($product),
94
+ $product
95
+ );
96
+ $optionCol->appendSelections($selectionCol);
97
+ $price = $product->getPrice();
98
+
99
+ foreach ($optionCol as $option) {
100
+ if($option->required) {
101
+ $selections = $option->getSelections();
102
+ $minPrice = min(array_map(function ($s) {
103
+ return $s->price;
104
+ }, $selections));
105
+ if($product->getSpecialPrice() > 0) {
106
+ $minPrice *= $product->getSpecialPrice()/100;
107
+ }
108
+
109
+ $price += round($minPrice,2);
110
+ }
111
+ }
112
+ return $price;
113
+ } else {
114
+ return false;
115
+ }
116
+ }
117
+ }
app/code/community/Shareagift/Core/Test/Config/Base.php ADDED
@@ -0,0 +1,23 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ class Shareagift_Core_Test_Config_Base extends EcomDev_PHPUnit_Test_Case_Config {
3
+ public function testBlockAlias() {
4
+ $this->assertBlockAlias('shareagift/test', 'Shareagift_Core_Block_Test');
5
+ }
6
+
7
+ public function testHelperAlias() {
8
+ $this->assertHelperAlias('shareagift/test', 'Shareagift_Core_Helper_Test');
9
+ }
10
+
11
+ public function testCodePool() {
12
+ $this->assertModuleCodePool('community');
13
+ }
14
+
15
+ public function testDepends() {
16
+ $this->assertModuleDepends('Mage_Catalog');
17
+ }
18
+
19
+ public function testLayoutFile() {
20
+ $this->assertLayoutFileDefined('frontend', 'shareagift/core.xml');
21
+ $this->assertLayoutFileExistsInTheme('frontend', 'shareagift/core.xml', 'default', 'base');
22
+ }
23
+ }
app/code/community/Shareagift/Core/etc/config.xml ADDED
@@ -0,0 +1,84 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <config>
3
+ <modules>
4
+ <Shareagift_Core>
5
+ <version>0.0.1</version>
6
+ </Shareagift_Core>
7
+ </modules>
8
+
9
+ <global>
10
+ <helpers>
11
+ <shareagift>
12
+ <class>Shareagift_Core_Helper</class>
13
+ </shareagift>
14
+ </helpers>
15
+ </global>
16
+
17
+ <frontend>
18
+ <layout>
19
+ <updates>
20
+ <shareagift>
21
+ <file>shareagift/core.xml</file>
22
+ </shareagift>
23
+ </updates>
24
+ </layout>
25
+ <routers>
26
+ <shareagift>
27
+ <use>standard</use>
28
+ <args>
29
+ <module>Shareagift_Core</module>
30
+ <frontName>shareagift</frontName>
31
+ </args>
32
+ </shareagift>
33
+ </routers>
34
+ <translate>
35
+ <modules>
36
+ <shareagift>
37
+ <files>
38
+ <default>Shareagift_Core.csv</default>
39
+ </files>
40
+ </shareagift>
41
+ </modules>
42
+ </translate>
43
+ </frontend>
44
+
45
+ <adminhtml>
46
+ <acl>
47
+ <resources>
48
+ <admin>
49
+ <children>
50
+ <system>
51
+ <children>
52
+ <config>
53
+ <children>
54
+ <shareagift>
55
+ <title>Shareagift Settings</title>
56
+ </shareagift>
57
+ </children>
58
+ </config>
59
+ </children>
60
+ </system>
61
+ </children>
62
+ </admin>
63
+ </resources>
64
+ </acl>
65
+ </adminhtml>
66
+
67
+ <default>
68
+ <shareagift>
69
+ <general>
70
+ <enabled>0</enabled>
71
+ <button>0</button>
72
+ </general>
73
+ </shareagift>
74
+ </default>
75
+
76
+
77
+ <phpunit>
78
+ <suite>
79
+ <modules>
80
+ <shareagift_Core />
81
+ </modules>
82
+ </suite>
83
+ </phpunit>
84
+ </config>
app/code/community/Shareagift/Core/etc/system.xml ADDED
@@ -0,0 +1,64 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <config>
3
+ <tabs>
4
+ <shareagift translate="label" module="shareagift">
5
+ <label>Shareagift</label>
6
+ <sort_order>450</sort_order>
7
+ </shareagift>
8
+ </tabs>
9
+ <sections>
10
+ <shareagift translate="label" module="shareagift">
11
+ <label>Configuration</label>
12
+ <tab>shareagift</tab>
13
+ <frontend_type>text</frontend_type>
14
+ <sort_order>355</sort_order>
15
+ <show_in_default>1</show_in_default>
16
+ <show_in_website>1</show_in_website>
17
+ <show_in_store>1</show_in_store>
18
+ <groups>
19
+ <general translate="label" module="shareagift">
20
+ <label>General</label>
21
+ <frontend_type>text</frontend_type>
22
+ <sort_order>10</sort_order>
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
+ <fields>
27
+ <enabled translate="label" module="shareagift">
28
+ <label>Enabled</label>
29
+ <frontend_type>select</frontend_type>
30
+ <source_model>adminhtml/system_config_source_yesno</source_model>
31
+ <sort_order>10</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
+ </enabled>
36
+ <merchantid translate="label" module="shareagift">
37
+ <label>Merchant ID</label>
38
+ <frontend_type>text</frontend_type>
39
+ <sort_order>20</sort_order>
40
+ <show_in_default>1</show_in_default>
41
+ <show_in_website>1</show_in_website>
42
+ <show_in_store>1</show_in_store>
43
+ <comment>
44
+ <![CDATA[Sign up for an account at <a href="http://www.shareagift.com/" target="_blank">Shareagift.com</a>]]>
45
+ </comment>
46
+ </merchantid>
47
+ <button translate="label" module="shareagift">
48
+ <label>Use text link?</label>
49
+ <frontend_type>select</frontend_type>
50
+ <source_model>adminhtml/system_config_source_yesno</source_model>
51
+ <sort_order>30</sort_order>
52
+ <show_in_default>1</show_in_default>
53
+ <show_in_website>1</show_in_website>
54
+ <show_in_store>1</show_in_store>
55
+ <comment>
56
+ <![CDATA[If selected, a text link will be used instead of a button.]]>
57
+ </comment>
58
+ </button>
59
+ </fields>
60
+ </general>
61
+ </groups>
62
+ </shareagift>
63
+ </sections>
64
+ </config>
app/design/frontend/base/default/layout/shareagift/core.xml ADDED
@@ -0,0 +1,20 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <layout>
3
+ <catalog_product_view>
4
+ <reference name="head">
5
+ <action method="addItem"><type>skin_css</type><name>css/shareagift.css</name></action>
6
+ </reference>
7
+
8
+ <reference name="product.info">
9
+ <block type="catalog/product_view" name="product.info.addto.shareagift" as="addto" template="shareagift/link.phtml" ifconfig="shareagift/settings/enabled">
10
+ <action method="setChild"><name>addto</name><block>product.info.addto</block></action>
11
+ </block>
12
+ </reference>
13
+
14
+ <reference name="product.info.options.wrapper.bottom">
15
+ <action method="append"><name>product.info.addto.shareagift</name></action>
16
+ <action method="setChild"><name>product.info.addto</name><block>product.info.addto.shareagift</block></action>
17
+ </reference>
18
+
19
+ </catalog_product_view>
20
+ </layout>
app/design/frontend/base/default/template/shareagift/link.phtml ADDED
@@ -0,0 +1,37 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Magento
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Academic Free License (AFL 3.0)
8
+ * that is bundled with this package in the file LICENSE_AFL.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/afl-3.0.php
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@magentocommerce.com so we can send you a copy immediately.
14
+ *
15
+ * DISCLAIMER
16
+ *
17
+ * Do not edit or add to this file if you wish to upgrade Magento to newer
18
+ * versions in the future. If you wish to customize Magento for your
19
+ * needs please refer to http://www.magentocommerce.com for more information.
20
+ *
21
+ * @category design
22
+ * @package base_default
23
+ * @copyright Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
24
+ * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
25
+ */
26
+ ?>
27
+ <?php $_product = $this->getProduct(); ?>
28
+ <?php /** @var Shareagift_Core_Helper_Data $_helper */ ?>
29
+ <?php $_helper = Mage::helper('shareagift'); ?>
30
+ <?php /** @var Shareagift_Core_Helper_Config $_config */ ?>
31
+ <?php $_config = Mage::helper('shareagift/config') ?>
32
+ <div class="shareagift-container">
33
+ <?php echo $this->getChildHtml('addto'); ?>
34
+ <?php if ($_groupGiftUrl = $_helper->getGroupGiftUrl($_product)): ?>
35
+ <a class="shareagift<?php if ($_config->useButton()) { echo " button"; } ?>" href="<?php echo $_groupGiftUrl ?>" title="<?php echo $this->__('Start Group Gift') ?>"><?php echo $this->__('Start Group Gift') ?></a>
36
+ <?php endif; ?>
37
+ </div>
app/etc/modules/Shareagift_Core.xml ADDED
@@ -0,0 +1,12 @@
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <config>
3
+ <modules>
4
+ <Shareagift_Core>
5
+ <active>true</active>
6
+ <codePool>community</codePool>
7
+ <depends>
8
+ <Mage_Catalog />
9
+ </depends>
10
+ </Shareagift_Core>
11
+ </modules>
12
+ </config>
app/locale/en_GB/Shareagift_Core.csv ADDED
@@ -0,0 +1 @@
 
1
+ "Start Group Gift","Start Group Gift"
app/locale/en_US/Shareagift_Core.csv ADDED
@@ -0,0 +1 @@
 
1
+ "Start Group Gift","Start Group Gift"
package.xml ADDED
@@ -0,0 +1,23 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <package>
3
+ <name>shareagift_core</name>
4
+ <version>0.0.1</version>
5
+ <stability>stable</stability>
6
+ <license uri="http://opensource.org/licenses/osl-3.0.php">Open Source License (OSL)</license>
7
+ <channel>community</channel>
8
+ <extends/>
9
+ <summary>Collect funds easily with your friends&#xD;
10
+ For any group gift, fund or cause</summary>
11
+ <description>The official Shareagift Magento extension.&#xD;
12
+ &#xD;
13
+ Shareagift is a unique social network for gifting.&#xD;
14
+ &#xD;
15
+ We provide a specialized place where consumers group together with their friends to suggest, recommend, choose and buy gifts together.</description>
16
+ <notes>Initial Release</notes>
17
+ <authors><author><name>Shareagift</name><user>auto-converted</user><email>business@shareagift.com</email></author></authors>
18
+ <date>2013-08-28</date>
19
+ <time>11:51:09</time>
20
+ <contents><target name="magecommunity"><dir name="Shareagift"><dir name="Core"><dir name="Helper"><file name="Config.php" hash="1e3dc95b8b498ff125313a0e852d681f"/><file name="Data.php" hash="6755011d341bbcdd222e47e914ebf100"/></dir><dir name="Test"><dir name="Config"><file name="Base.php" hash="b19e6c220fae8c4c9a15e128298d06b3"/></dir></dir><dir name="etc"><file name="config.xml" hash="d6eb364af9116870e74c7a913a79e173"/><file name="system.xml" hash="5bde60459aeeaac4791f312a374a08ad"/></dir></dir></dir></target><target name="magedesign"><dir name="frontend"><dir name="base"><dir name="default"><dir name="layout"><dir name="shareagift"><file name="core.xml" hash="19b504389a2fe332b0120278259a987c"/></dir></dir><dir name="template"><dir name="shareagift"><file name="link.phtml" hash="11e327e4da3fb97345ca09b7036ad463"/></dir></dir></dir></dir></dir></target><target name="mageetc"><dir name="modules"><file name="Shareagift_Core.xml" hash="7c0193ec90fad383c03b493e05c637e0"/></dir></target><target name="magelocale"><dir name="en_US"><file name="Shareagift_Core.csv" hash="47c2a1773426a1c7b12ecf1e29d37639"/></dir><dir name="en_GB"><file name="Shareagift_Core.csv" hash="47c2a1773426a1c7b12ecf1e29d37639"/></dir></target><target name="mageskin"><dir name="frontend"><dir name="base"><dir name="default"><dir name="css"><file name="shareagift.css" hash="1c102ff9d2c629653ebd47d998be19db"/></dir><dir name="images"><dir name="shareagift"><file name="shareagift_button.png" hash="0a3ce3f5264d577a9678a3c38e6f8c32"/></dir></dir></dir></dir></dir></target></contents>
21
+ <compatible/>
22
+ <dependencies/>
23
+ </package>
skin/frontend/base/default/css/shareagift.css ADDED
@@ -0,0 +1,31 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ .shareagift {
2
+ float: right;
3
+ }
4
+
5
+ .shareagift.button {
6
+ background: url('../images/shareagift/shareagift_button.png') top left;
7
+ height: 22px;
8
+ margin-top: 5px;
9
+ text-indent: -9999px;
10
+ width: 102px;
11
+ }
12
+
13
+ #product_addtocart_form > .product-options-bottom .shareagift {
14
+ font-weight: bold;
15
+ font-size: 0.9em;
16
+ }
17
+
18
+ .add-to-box .shareagift-container {
19
+ float: left;
20
+ }
21
+
22
+ .add-to-box .shareagift {
23
+ display: block;
24
+ float: none;
25
+ }
26
+
27
+ .add-to-box .shareagift.button {
28
+ clear: both;
29
+ display: inline-block !important;
30
+ float: left;
31
+ }
skin/frontend/base/default/images/shareagift/shareagift_button.png ADDED
Binary file