Flayr_Marketplace - Version 1.0.0

Version Notes

First release

Download this release

Release Info

Developer GroupDocs
Extension Flayr_Marketplace
Version 1.0.0
Comparing to
See all releases


Version 1.0.0

app/code/local/Flayr/Marketplace/Model/Carrier.php ADDED
@@ -0,0 +1,57 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ class Flayr_Marketplace_Model_Carrier
3
+ extends Mage_Shipping_Model_Carrier_Abstract
4
+ implements Mage_Shipping_Model_Carrier_Interface
5
+ {
6
+ protected $_code = 'flayr_marketplace';
7
+
8
+ public function collectRates(
9
+ Mage_Shipping_Model_Rate_Request $request
10
+ )
11
+ {
12
+ $api_running = Mage::getSingleton('api/server')->getAdapter();
13
+ if (empty($api_running))
14
+ return false;
15
+ $result = Mage::getModel('shipping/rate_result');
16
+ /* @var $result Mage_Shipping_Model_Rate_Result */
17
+
18
+ $result->append($this->_getStandardShippingRate());
19
+
20
+ return $result;
21
+ }
22
+
23
+ protected function _getStandardShippingRate()
24
+ {
25
+ $rate = Mage::getModel('shipping/rate_result_method');
26
+ /* @var $rate Mage_Shipping_Model_Rate_Result_Method */
27
+
28
+ $rate->setCarrier($this->_code);
29
+ /**
30
+ * getConfigData(config_key) returns the configuration value for the
31
+ * carriers/[carrier_code]/[config_key]
32
+ */
33
+ $rate->setCarrierTitle($this->getConfigData('title'));
34
+
35
+ $rate->setMethod('standard');
36
+ $rate->setMethodTitle('Standard');
37
+
38
+ $shippingPrice = $this->getConfigData('price');
39
+ if(empty($shippingPrice))
40
+ $shippingPrice = 0;
41
+
42
+
43
+ $rate->setPrice((float)$shippingPrice);
44
+ $rate->setCost(0);
45
+
46
+ return $rate;
47
+ }
48
+
49
+ public function getAllowedMethods()
50
+ {
51
+ return array(
52
+ 'standard' => 'Standard',
53
+ );
54
+ }
55
+ }
56
+
57
+ ?>
app/code/local/Flayr/Marketplace/Model/Flayrpay.php ADDED
@@ -0,0 +1,11 @@
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Flayr_Marketplace_Model_Flayrpay extends Mage_Payment_Model_Method_Abstract
4
+ {
5
+ protected $_code = 'flayrpay';
6
+ protected $_canUseInternal = true;
7
+ protected $_canUseCheckout = false;
8
+
9
+ }
10
+
11
+ ?>
app/code/local/Flayr/Marketplace/Model/Freecarrier.php ADDED
@@ -0,0 +1,54 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ class Flayr_Marketplace_Model_Freecarrier
3
+ extends Mage_Shipping_Model_Carrier_Abstract
4
+ implements Mage_Shipping_Model_Carrier_Interface
5
+ {
6
+ protected $_code = 'flayrfree_marketplace';
7
+
8
+ public function collectRates(
9
+ Mage_Shipping_Model_Rate_Request $request
10
+ )
11
+ {
12
+ $api_running = Mage::getSingleton('api/server')->getAdapter();
13
+ if (empty($api_running))
14
+ return false;
15
+ $result = Mage::getModel('shipping/rate_result');
16
+ /* @var $result Mage_Shipping_Model_Rate_Result */
17
+
18
+ $result->append($this->_getStandardShippingRate());
19
+
20
+ return $result;
21
+ }
22
+
23
+ protected function _getStandardShippingRate()
24
+ {
25
+ $rate = Mage::getModel('shipping/rate_result_method');
26
+ /* @var $rate Mage_Shipping_Model_Rate_Result_Method */
27
+
28
+ $rate->setCarrier($this->_code);
29
+ /**
30
+ * getConfigData(config_key) returns the configuration value for the
31
+ * carriers/[carrier_code]/[config_key]
32
+ */
33
+ $rate->setCarrierTitle($this->getConfigData('title'));
34
+
35
+ $rate->setMethod('standard');
36
+ $rate->setMethodTitle('Standard');
37
+
38
+ $shippingPrice = 0;
39
+
40
+ $rate->setPrice((float)$shippingPrice);
41
+ $rate->setCost(0);
42
+
43
+ return $rate;
44
+ }
45
+
46
+ public function getAllowedMethods()
47
+ {
48
+ return array(
49
+ 'standard' => 'Standard',
50
+ );
51
+ }
52
+ }
53
+
54
+ ?>
app/code/local/Flayr/Marketplace/etc/config.xml ADDED
@@ -0,0 +1,45 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <config>
3
+ <modules>
4
+ <Flayr_Marketplace>
5
+ <module>0.0.1</module>
6
+ </Flayr_Marketplace>
7
+ </modules>
8
+ <global>
9
+ <models>
10
+ <flayr_marketplace>
11
+ <class>Flayr_Marketplace_Model</class>
12
+ </flayr_marketplace>
13
+ </models>
14
+ </global>
15
+ <!-- Default configuration -->
16
+ <default>
17
+ <carriers>
18
+ <flayr_marketplace>
19
+ <active>1</active>
20
+ <model>flayr_marketplace/carrier</model>
21
+ <title>Flayr Carrier</title>
22
+ <sort_order>10</sort_order>
23
+ <sallowspecific>0</sallowspecific>
24
+ </flayr_marketplace>
25
+ <flayrfree_marketplace>
26
+ <active>1</active>
27
+ <model>flayr_marketplace/freecarrier</model>
28
+ <title>Flayr Free Carrier</title>
29
+ <sort_order>11</sort_order>
30
+ <sallowspecific>0</sallowspecific>
31
+ </flayrfree_marketplace>
32
+ </carriers>
33
+ <payment>
34
+ <flayrpay>
35
+ <active>1</active>
36
+ <model>flayr_marketplace/flayrpay</model>
37
+ <order_status>processing</order_status>
38
+ <title>Flayr Payment</title>
39
+ <sort_order>10</sort_order>
40
+ <sallowspecific>0</sallowspecific>
41
+ <group>offline</group>
42
+ </flayrpay>
43
+ </payment>
44
+ </default>
45
+ </config>
app/code/local/Flayr/Marketplace/etc/system.xml ADDED
@@ -0,0 +1,187 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <config>
3
+ <sections>
4
+ <carriers translate="label" module="shipping">
5
+ <groups>
6
+ <flayr_marketplace translate="label">
7
+ <label>Flayr Carrier</label>
8
+ <frontend_type>text</frontend_type>
9
+ <sort_order>2</sort_order>
10
+ <show_in_default>1</show_in_default>
11
+ <show_in_website>0</show_in_website>
12
+ <show_in_store>0</show_in_store>
13
+ <fields>
14
+ <active translate="label">
15
+ <label>Enabled</label>
16
+ <frontend_type>select</frontend_type>
17
+ <source_model>adminhtml/system_config_source_yesno</source_model>
18
+ <sort_order>1</sort_order>
19
+ <show_in_default>1</show_in_default>
20
+ <show_in_website>0</show_in_website>
21
+ <show_in_store>0</show_in_store>
22
+ </active>
23
+ <title translate="label">
24
+ <label>Title</label>
25
+ <frontend_type>text</frontend_type>
26
+ <sort_order>2</sort_order>
27
+ <show_in_default>1</show_in_default>
28
+ <show_in_website>0</show_in_website>
29
+ <show_in_store>1</show_in_store>
30
+ </title>
31
+
32
+ <price translate="label">
33
+ <label>Price (TTC per order)</label>
34
+ <frontend_type>text</frontend_type>
35
+ <sort_order>3</sort_order>
36
+ <show_in_default>1</show_in_default>
37
+ <show_in_website>0</show_in_website>
38
+ <show_in_store>1</show_in_store>
39
+ </price>
40
+ <sort_order translate="label">
41
+ <label>Sort Order</label>
42
+ <frontend_type>text</frontend_type>
43
+ <sort_order>100</sort_order>
44
+ <show_in_default>1</show_in_default>
45
+ <show_in_website>0</show_in_website>
46
+ <show_in_store>0</show_in_store>
47
+ </sort_order>
48
+ <sallowspecific translate="label">
49
+ <label>Ship to Applicable Countries</label>
50
+ <frontend_type>select</frontend_type>
51
+ <sort_order>90</sort_order>
52
+ <frontend_class>shipping-applicable-country</frontend_class>
53
+ <source_model>adminhtml/system_config_source_shipping_allspecificcountries</source_model>
54
+ <show_in_default>1</show_in_default>
55
+ <show_in_website>0</show_in_website>
56
+ <show_in_store>0</show_in_store>
57
+ </sallowspecific>
58
+ <specificcountry translate="label">
59
+ <label>Ship to Specific Countries</label>
60
+ <frontend_type>multiselect</frontend_type>
61
+ <sort_order>91</sort_order>
62
+ <source_model>adminhtml/system_config_source_country</source_model>
63
+ <show_in_default>1</show_in_default>
64
+ <show_in_website>0</show_in_website>
65
+ <show_in_store>0</show_in_store>
66
+ <can_be_empty>1</can_be_empty>
67
+ </specificcountry>
68
+ </fields>
69
+ </flayr_marketplace>
70
+ <flayrfree_marketplace translate="label">
71
+ <label>Flayr Free Carrier</label>
72
+ <frontend_type>text</frontend_type>
73
+ <sort_order>3</sort_order>
74
+ <show_in_default>1</show_in_default>
75
+ <show_in_website>0</show_in_website>
76
+ <show_in_store>0</show_in_store>
77
+ <fields>
78
+ <active translate="label">
79
+ <label>Enabled</label>
80
+ <frontend_type>select</frontend_type>
81
+ <source_model>adminhtml/system_config_source_yesno</source_model>
82
+ <sort_order>1</sort_order>
83
+ <show_in_default>1</show_in_default>
84
+ <show_in_website>0</show_in_website>
85
+ <show_in_store>0</show_in_store>
86
+ </active>
87
+ <title translate="label">
88
+ <label>Title</label>
89
+ <frontend_type>text</frontend_type>
90
+ <sort_order>2</sort_order>
91
+ <show_in_default>1</show_in_default>
92
+ <show_in_website>0</show_in_website>
93
+ <show_in_store>1</show_in_store>
94
+ </title>
95
+ <sort_order translate="label">
96
+ <label>Sort Order</label>
97
+ <frontend_type>text</frontend_type>
98
+ <sort_order>101</sort_order>
99
+ <show_in_default>1</show_in_default>
100
+ <show_in_website>0</show_in_website>
101
+ <show_in_store>0</show_in_store>
102
+ </sort_order>
103
+ <sallowspecific translate="label">
104
+ <label>Ship to Applicable Countries</label>
105
+ <frontend_type>select</frontend_type>
106
+ <sort_order>90</sort_order>
107
+ <frontend_class>shipping-applicable-country</frontend_class>
108
+ <source_model>adminhtml/system_config_source_shipping_allspecificcountries</source_model>
109
+ <show_in_default>1</show_in_default>
110
+ <show_in_website>0</show_in_website>
111
+ <show_in_store>0</show_in_store>
112
+ </sallowspecific>
113
+ <specificcountry translate="label">
114
+ <label>Ship to Specific Countries</label>
115
+ <frontend_type>multiselect</frontend_type>
116
+ <sort_order>91</sort_order>
117
+ <source_model>adminhtml/system_config_source_country</source_model>
118
+ <show_in_default>1</show_in_default>
119
+ <show_in_website>0</show_in_website>
120
+ <show_in_store>0</show_in_store>
121
+ <can_be_empty>1</can_be_empty>
122
+ </specificcountry>
123
+ </fields>
124
+ </flayrfree_marketplace>
125
+ </groups>
126
+ </carriers>
127
+ <payment translate="label" module="payment">
128
+ <groups>
129
+ <flayrpay translate="label">
130
+ <label>Flayr Payment</label>
131
+ <sort_order>10</sort_order>
132
+ <show_in_default>1</show_in_default>
133
+ <show_in_website>1</show_in_website>
134
+ <show_in_store>1</show_in_store>
135
+ <fields>
136
+ <active translate="label">
137
+ <label>Enabled</label>
138
+ <frontend_type>select</frontend_type>
139
+ <source_model>adminhtml/system_config_source_yesno</source_model>
140
+ <sort_order>1</sort_order>
141
+ <show_in_default>1</show_in_default>
142
+ <show_in_website>1</show_in_website>
143
+ <show_in_store>1</show_in_store>
144
+ </active>
145
+ <order_status translate="label">
146
+ <label>New order status</label>
147
+ <frontend_type>select</frontend_type>
148
+ <source_model>adminhtml/system_config_source_order_status_processing</source_model>
149
+ <sort_order>3</sort_order>
150
+ <show_in_default>1</show_in_default>
151
+ <show_in_website>1</show_in_website>
152
+ <show_in_store>0</show_in_store>
153
+ </order_status>
154
+ <title translate="label">
155
+ <label>Title</label>
156
+ <frontend_type>text</frontend_type>
157
+ <sort_order>2s</sort_order>
158
+ <show_in_default>1</show_in_default>
159
+ <show_in_website>1</show_in_website>
160
+ <show_in_store>0</show_in_store>
161
+ </title>
162
+ <sallowspecific translate="label">
163
+ <label>Ship to Applicable Countries</label>
164
+ <frontend_type>select</frontend_type>
165
+ <sort_order>90</sort_order>
166
+ <frontend_class>shipping-applicable-country</frontend_class>
167
+ <source_model>adminhtml/system_config_source_shipping_allspecificcountries</source_model>
168
+ <show_in_default>1</show_in_default>
169
+ <show_in_website>1</show_in_website>
170
+ <show_in_store>0</show_in_store>
171
+ </sallowspecific>
172
+ <specificcountry translate="label">
173
+ <label>Ship to Specific Countries</label>
174
+ <frontend_type>multiselect</frontend_type>
175
+ <sort_order>91</sort_order>
176
+ <source_model>adminhtml/system_config_source_country</source_model>
177
+ <show_in_default>1</show_in_default>
178
+ <show_in_website>1</show_in_website>
179
+ <show_in_store>0</show_in_store>
180
+ <can_be_empty>1</can_be_empty>
181
+ </specificcountry>
182
+ </fields>
183
+ </flayrpay>
184
+ </groups>
185
+ </payment>
186
+ </sections>
187
+ </config>
app/code/local/Mage/Catalog/Model/Product/Link/Api.php ADDED
@@ -0,0 +1,364 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Magento
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-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@magento.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.magento.com for more information.
20
+ *
21
+ * @category Mage
22
+ * @package Mage_Catalog
23
+ * @copyright Copyright (c) 2006-2014 X.commerce, Inc. (http://www.magento.com)
24
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
+ */
26
+
27
+ /**
28
+ * Catalog product link api
29
+ *
30
+ * @category Mage
31
+ * @package Mage_Catalog
32
+ * @author Magento Core Team <core@magentocommerce.com>
33
+ */
34
+ class Mage_Catalog_Model_Product_Link_Api extends Mage_Catalog_Model_Api_Resource
35
+ {
36
+ /**
37
+ * Product link type mapping, used for references and validation
38
+ *
39
+ * @var array
40
+ */
41
+ protected $_typeMap = array(
42
+ 'related' => Mage_Catalog_Model_Product_Link::LINK_TYPE_RELATED,
43
+ 'up_sell' => Mage_Catalog_Model_Product_Link::LINK_TYPE_UPSELL,
44
+ 'cross_sell' => Mage_Catalog_Model_Product_Link::LINK_TYPE_CROSSSELL,
45
+ 'grouped' => Mage_Catalog_Model_Product_Link::LINK_TYPE_GROUPED
46
+ );
47
+
48
+ public function __construct()
49
+ {
50
+ $this->_storeIdSessionField = 'product_store_id';
51
+ }
52
+
53
+ /**
54
+ * Retrieve product link associations
55
+ *
56
+ * @param string $type
57
+ * @param int|sku $productId
58
+ * @param string $identifierType
59
+ * @return array
60
+ */
61
+ public function items($type, $productId, $identifierType = null)
62
+ {
63
+ if($type == "associated"){
64
+ $product = $this->_initProduct($productId);
65
+ try
66
+ {
67
+ $result = Mage::getModel('catalog/product_type_configurable')->getUsedProducts(null,$product);
68
+ }
69
+ catch (Exception $e)
70
+ {
71
+ $this->_fault('data_invalid', Mage::helper('catalog')->__('The product is not configurable.'));
72
+ }
73
+
74
+ }
75
+ else {
76
+
77
+ $typeId = $this->_getTypeId($type);
78
+
79
+ $product = $this->_initProduct($productId, $identifierType);
80
+
81
+ $link = $product->getLinkInstance()
82
+ ->setLinkTypeId($typeId);
83
+
84
+ $collection = $this->_initCollection($link, $product);
85
+
86
+ $result = array();
87
+
88
+ foreach ($collection as $linkedProduct) {
89
+ $row = array(
90
+ 'product_id' => $linkedProduct->getId(),
91
+ 'type' => $linkedProduct->getTypeId(),
92
+ 'set' => $linkedProduct->getAttributeSetId(),
93
+ 'sku' => $linkedProduct->getSku()
94
+ );
95
+
96
+ foreach ($link->getAttributes() as $attribute) {
97
+ $row[$attribute['code']] = $linkedProduct->getData($attribute['code']);
98
+ }
99
+
100
+ $result[] = $row;
101
+ }
102
+ }
103
+
104
+ return $result;
105
+ }
106
+
107
+ /**
108
+ * Add product link association
109
+ *
110
+ * @param string $type
111
+ * @param int|string $productId
112
+ * @param int|string $linkedProductId
113
+ * @param array $data
114
+ * @param string $identifierType
115
+ * @return boolean
116
+ */
117
+ public function assign($type, $productId, $linkedProductId, $data = array(), $identifierType = null)
118
+ {
119
+ $typeId = $this->_getTypeId($type);
120
+
121
+ $product = $this->_initProduct($productId, $identifierType);
122
+
123
+ $link = $product->getLinkInstance()
124
+ ->setLinkTypeId($typeId);
125
+
126
+ $collection = $this->_initCollection($link, $product);
127
+ $idBySku = $product->getIdBySku($linkedProductId);
128
+ if ($idBySku) {
129
+ $linkedProductId = $idBySku;
130
+ }
131
+
132
+ $links = $this->_collectionToEditableArray($collection);
133
+
134
+ $links[(int)$linkedProductId] = array();
135
+
136
+ foreach ($collection->getLinkModel()->getAttributes() as $attribute) {
137
+ if (isset($data[$attribute['code']])) {
138
+ $links[(int)$linkedProductId][$attribute['code']] = $data[$attribute['code']];
139
+ }
140
+ }
141
+
142
+ try {
143
+ if ($type == 'grouped') {
144
+ $link->getResource()->saveGroupedLinks($product, $links, $typeId);
145
+ } else {
146
+ $link->getResource()->saveProductLinks($product, $links, $typeId);
147
+ }
148
+
149
+ $_linkInstance = Mage::getSingleton('catalog/product_link');
150
+ $_linkInstance->saveProductRelations($product);
151
+
152
+ $indexerStock = Mage::getModel('cataloginventory/stock_status');
153
+ $indexerStock->updateStatus($productId);
154
+
155
+ $indexerPrice = Mage::getResourceModel('catalog/product_indexer_price');
156
+ $indexerPrice->reindexProductIds($productId);
157
+ } catch (Exception $e) {
158
+ $this->_fault('data_invalid', Mage::helper('catalog')->__('Link product does not exist.'));
159
+ }
160
+
161
+ return true;
162
+ }
163
+
164
+ /**
165
+ * Update product link association info
166
+ *
167
+ * @param string $type
168
+ * @param int|string $productId
169
+ * @param int|string $linkedProductId
170
+ * @param array $data
171
+ * @param string $identifierType
172
+ * @return boolean
173
+ */
174
+ public function update($type, $productId, $linkedProductId, $data = array(), $identifierType = null)
175
+ {
176
+ $typeId = $this->_getTypeId($type);
177
+
178
+ $product = $this->_initProduct($productId, $identifierType);
179
+
180
+ $link = $product->getLinkInstance()
181
+ ->setLinkTypeId($typeId);
182
+
183
+ $collection = $this->_initCollection($link, $product);
184
+
185
+ $links = $this->_collectionToEditableArray($collection);
186
+
187
+ $idBySku = $product->getIdBySku($linkedProductId);
188
+ if ($idBySku) {
189
+ $linkedProductId = $idBySku;
190
+ }
191
+
192
+ foreach ($collection->getLinkModel()->getAttributes() as $attribute) {
193
+ if (isset($data[$attribute['code']])) {
194
+ $links[(int)$linkedProductId][$attribute['code']] = $data[$attribute['code']];
195
+ }
196
+ }
197
+
198
+ try {
199
+ if ($type == 'grouped') {
200
+ $link->getResource()->saveGroupedLinks($product, $links, $typeId);
201
+ } else {
202
+ $link->getResource()->saveProductLinks($product, $links, $typeId);
203
+ }
204
+
205
+ $_linkInstance = Mage::getSingleton('catalog/product_link');
206
+ $_linkInstance->saveProductRelations($product);
207
+
208
+ $indexerStock = Mage::getModel('cataloginventory/stock_status');
209
+ $indexerStock->updateStatus($productId);
210
+
211
+ $indexerPrice = Mage::getResourceModel('catalog/product_indexer_price');
212
+ $indexerPrice->reindexProductIds($productId);
213
+ } catch (Exception $e) {
214
+ $this->_fault('data_invalid', Mage::helper('catalog')->__('Link product does not exist.'));
215
+ }
216
+
217
+ return true;
218
+ }
219
+
220
+ /**
221
+ * Remove product link association
222
+ *
223
+ * @param string $type
224
+ * @param int|string $productId
225
+ * @param int|string $linkedProductId
226
+ * @param string $identifierType
227
+ * @return boolean
228
+ */
229
+ public function remove($type, $productId, $linkedProductId, $identifierType = null)
230
+ {
231
+ $typeId = $this->_getTypeId($type);
232
+
233
+ $product = $this->_initProduct($productId, $identifierType);
234
+
235
+ $link = $product->getLinkInstance()
236
+ ->setLinkTypeId($typeId);
237
+
238
+ $collection = $this->_initCollection($link, $product);
239
+
240
+ $idBySku = $product->getIdBySku($linkedProductId);
241
+ if ($idBySku) {
242
+ $linkedProductId = $idBySku;
243
+ }
244
+
245
+ $links = $this->_collectionToEditableArray($collection);
246
+
247
+ if (isset($links[$linkedProductId])) {
248
+ unset($links[$linkedProductId]);
249
+ }
250
+
251
+ try {
252
+ $link->getResource()->saveProductLinks($product, $links, $typeId);
253
+ } catch (Exception $e) {
254
+ $this->_fault('not_removed');
255
+ }
256
+
257
+ return true;
258
+ }
259
+
260
+ /**
261
+ * Retrieve attribute list for specified type
262
+ *
263
+ * @param string $type
264
+ * @return array
265
+ */
266
+ public function attributes($type)
267
+ {
268
+ $typeId = $this->_getTypeId($type);
269
+
270
+ $attributes = Mage::getModel('catalog/product_link')
271
+ ->getAttributes($typeId);
272
+
273
+ $result = array();
274
+
275
+ foreach ($attributes as $attribute) {
276
+ $result[] = array(
277
+ 'code' => $attribute['code'],
278
+ 'type' => $attribute['type']
279
+ );
280
+ }
281
+
282
+ return $result;
283
+ }
284
+
285
+ /**
286
+ * Retrieve link types
287
+ *
288
+ * @return array
289
+ */
290
+ public function types()
291
+ {
292
+ return array_keys($this->_typeMap);
293
+ }
294
+
295
+ /**
296
+ * Retrieve link type id by code
297
+ *
298
+ * @param string $type
299
+ * @return int
300
+ */
301
+ protected function _getTypeId($type)
302
+ {
303
+ if (!isset($this->_typeMap[$type])) {
304
+ $this->_fault('type_not_exists');
305
+ }
306
+
307
+ return $this->_typeMap[$type];
308
+ }
309
+
310
+ /**
311
+ * Initialize and return product model
312
+ *
313
+ * @param int $productId
314
+ * @param string $identifierType
315
+ * @return Mage_Catalog_Model_Product
316
+ */
317
+ protected function _initProduct($productId, $identifierType = null)
318
+ {
319
+ $product = Mage::helper('catalog/product')->getProduct($productId, null, $identifierType);
320
+ if (!$product->getId()) {
321
+ $this->_fault('product_not_exists');
322
+ }
323
+
324
+ return $product;
325
+ }
326
+
327
+ /**
328
+ * Initialize and return linked products collection
329
+ *
330
+ * @param Mage_Catalog_Model_Product_Link $link
331
+ * @param Mage_Catalog_Model_Product $product
332
+ * @return Mage_Catalog_Model_Resource_Eav_Mysql4_Product_Link_Product_Collection
333
+ */
334
+ protected function _initCollection($link, $product)
335
+ {
336
+ $collection = $link
337
+ ->getProductCollection()
338
+ ->setIsStrongMode()
339
+ ->setProduct($product);
340
+
341
+ return $collection;
342
+ }
343
+
344
+ /**
345
+ * Export collection to editable array
346
+ *
347
+ * @param Mage_Catalog_Model_Resource_Eav_Mysql4_Product_Link_Product_Collection $collection
348
+ * @return array
349
+ */
350
+ protected function _collectionToEditableArray($collection)
351
+ {
352
+ $result = array();
353
+
354
+ foreach ($collection as $linkedProduct) {
355
+ $result[$linkedProduct->getId()] = array();
356
+
357
+ foreach ($collection->getLinkModel()->getAttributes() as $attribute) {
358
+ $result[$linkedProduct->getId()][$attribute['code']] = $linkedProduct->getData($attribute['code']);
359
+ }
360
+ }
361
+
362
+ return $result;
363
+ }
364
+ } // Class Mage_Catalog_Model_Product_Link_Api End
app/etc/modules/Flayr_Marketplace.xml ADDED
@@ -0,0 +1,13 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <config>
3
+ <modules>
4
+ <Flayr_Marketplace>
5
+ <active>true</active>
6
+ <codePool>local</codePool>
7
+ <depends>
8
+ <Mage_Shipping />
9
+ <Mage_Payment />
10
+ </depends>
11
+ </Flayr_Marketplace>
12
+ </modules>
13
+ </config>
package.xml ADDED
@@ -0,0 +1,22 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <package>
3
+ <name>Flayr_Marketplace</name>
4
+ <version>1.0.0</version>
5
+ <stability>stable</stability>
6
+ <license>GPL</license>
7
+ <channel>community</channel>
8
+ <extends/>
9
+ <summary>Flayr est une plateforme leader en Europe du Discovery Shopping sur Mobile. Avec pr&#xE8;s d' 1 000 000 d'utilisateurs, Flayr propose la meilleure exp&#xE9;rience de shopping du Mobile dans des univers comme la Mode, la d&#xE9;coration ou le High Tech. Ne ratez pas la r&#xE9;volution du Shopping Mobile qui repr&#xE9;sentera bient&#xF4;t 50% des transactions en ligne.</summary>
10
+ <description>Ce module permet de faire conna&#xEE;tre votre marque et vos produits dans un environnement premium sur les applications mobiles (iPhone et Android). Flayr offre une nouvelle exp&#xE9;rience de shopping et permet &#xE0; ses membres de d&#xE9;couvrir et d'acheter les produits qu'ils aiment parmi les plus grandes marques et jeunes cr&#xE9;ateurs en un seul et m&#xEA;me endroit. &#xD;
11
+ &#xD;
12
+ Nos membres peuvent &#xE9;galement partager leurs d&#xE9;couvertes entre amis et cr&#xE9;er ainsi un vrai engagement autour de votre marque (exemple: cr&#xE9;er des Flayrlists pour un cadeau d&#x2019;anniversaire...).&#xD;
13
+ &#xD;
14
+ Vous aurez &#xE9;galement une page d&#xE9;di&#xE9;e &#xE0; votre marque sur Flayr. Flayr offre aussi &#xE0; ses partenaires la possibilit&#xE9; d'augmenter leur visibilit&#xE9; &#xE0; travers des op&#xE9;rations d&#xE9;di&#xE9;es et des mises-en-avant ponctuelles (s&#xE9;lections &#xE9;ditorialis&#xE9;es sur la homepage, promotions exclusives, etc...). </description>
15
+ <notes>First release</notes>
16
+ <authors><author><name>Flayr</name><user>Marketplace</user><email>jerome.pellegrin@flayr.com</email></author></authors>
17
+ <date>2015-07-16</date>
18
+ <time>15:45:40</time>
19
+ <contents><target name="mageetc"><dir name="modules"><file name="Flayr_Marketplace.xml" hash="562a2f53e1e8f481d6923b53c1c85647"/></dir></target><target name="magelocal"><dir name="Flayr"><dir name="Marketplace"><dir name="Model"><file name="Carrier.php" hash="fde83869df14df2257ed07cf4f9073b4"/><file name="Flayrpay.php" hash="08cf04b9f9070e5687ffd4bab3a754b7"/><file name="Freecarrier.php" hash="133ac07e5c03bbe16a6f2eaa4fe48a7d"/></dir><dir name="etc"><file name="config.xml" hash="e35704c8d353569dbeec07a824bf7de2"/><file name="system.xml" hash="bcb441bff03c64b2c15b07ed4af1abae"/></dir></dir></dir><dir name="Mage"><dir name="Catalog"><dir name="Model"><dir name="Product"><dir name="Link"><file name="Api.php" hash="b30ee184331e0409eee20b66e3f38bbe"/></dir></dir></dir></dir></dir></target></contents>
20
+ <compatible/>
21
+ <dependencies><required><php><min>5.3.0</min><max>6.0.0</max></php></required></dependencies>
22
+ </package>