├── .gitignore
├── CHANGELOG.md
├── README.md
├── app
├── code
│ └── community
│ │ └── Oro
│ │ └── Api
│ │ ├── Helper
│ │ └── Data.php
│ │ ├── Model
│ │ ├── Admin
│ │ │ └── Redirectpolicy.php
│ │ ├── Catalog
│ │ │ └── Product
│ │ │ │ └── Api
│ │ │ │ └── V2.php
│ │ ├── Customer
│ │ │ ├── Address
│ │ │ │ ├── Api.php
│ │ │ │ └── Api
│ │ │ │ │ └── V2.php
│ │ │ ├── Api.php
│ │ │ └── Api
│ │ │ │ └── V2.php
│ │ ├── Directory
│ │ │ └── Region
│ │ │ │ ├── Api.php
│ │ │ │ └── Api
│ │ │ │ └── V2.php
│ │ ├── Newsletter
│ │ │ └── Subscriber
│ │ │ │ ├── Api.php
│ │ │ │ └── Api
│ │ │ │ └── V2.php
│ │ ├── Observer.php
│ │ ├── Observer
│ │ │ ├── Crm
│ │ │ │ └── Controller.php
│ │ │ └── Sales
│ │ │ │ └── Order.php
│ │ ├── Ping.php
│ │ ├── Ping
│ │ │ └── V2.php
│ │ ├── Report
│ │ │ └── Product
│ │ │ │ └── Viewed
│ │ │ │ ├── Api.php
│ │ │ │ └── Api
│ │ │ │ └── V2.php
│ │ ├── Resource
│ │ │ ├── Reports
│ │ │ │ └── Product
│ │ │ │ │ └── Index
│ │ │ │ │ └── Viewed
│ │ │ │ │ └── Collection.php
│ │ │ ├── Setup.php
│ │ │ └── Wishlist
│ │ │ │ ├── Status.php
│ │ │ │ └── Status
│ │ │ │ └── Collection.php
│ │ ├── Sales
│ │ │ ├── Order
│ │ │ │ ├── Api.php
│ │ │ │ └── Api
│ │ │ │ │ └── V2.php
│ │ │ └── Quote
│ │ │ │ ├── Api.php
│ │ │ │ ├── Api
│ │ │ │ └── V2.php
│ │ │ │ └── Item.php
│ │ ├── Website
│ │ │ ├── Api.php
│ │ │ └── Api
│ │ │ │ └── V2.php
│ │ └── Wishlist
│ │ │ ├── Api.php
│ │ │ ├── Api
│ │ │ └── V2.php
│ │ │ ├── Item
│ │ │ ├── Api.php
│ │ │ └── Api
│ │ │ │ └── V2.php
│ │ │ ├── Observer.php
│ │ │ ├── Status.php
│ │ │ └── Status
│ │ │ ├── Api.php
│ │ │ └── Api
│ │ │ └── V2.php
│ │ ├── controllers
│ │ └── Adminhtml
│ │ │ └── Oro
│ │ │ ├── GatewayController.php
│ │ │ └── SalesController.php
│ │ ├── etc
│ │ ├── adminhtml.xml
│ │ ├── api.xml
│ │ ├── config.xml
│ │ ├── system.xml
│ │ ├── workflow.xml
│ │ ├── wsdl.xml
│ │ └── wsi.xml
│ │ └── sql
│ │ └── oro_api_setup
│ │ ├── install-1.2.5.php
│ │ └── upgrade-1.2.5.0-1.2.5.1.php
├── design
│ └── adminhtml
│ │ └── default
│ │ └── default
│ │ └── template
│ │ └── oro
│ │ └── api
│ │ ├── check.phtml
│ │ ├── login_styles.phtml
│ │ ├── page.phtml
│ │ └── script.phtml
└── etc
│ └── modules
│ └── Oro_Api.xml
├── modman
├── skin
└── adminhtml
│ └── default
│ └── default
│ ├── images
│ └── oro
│ │ ├── add_button_icon_dark.png
│ │ ├── apply_button_icon.png
│ │ ├── error.png
│ │ ├── grid_sort_asc.gif
│ │ ├── grid_sort_desc.gif
│ │ └── loader.gif
│ └── oro_style.css
└── var
└── connect
├── Oro_Api-1.1.3.tgz
├── Oro_Api-1.1.4.1.tgz
├── Oro_Api-1.1.4.2.tgz
├── Oro_Api-1.1.4.3.tgz
├── Oro_Api-1.1.4.4.tgz
├── Oro_Api-1.1.4.tgz
├── Oro_Api-1.2.0.0.tgz
├── Oro_Api-1.2.1.0.tgz
├── Oro_Api-1.2.10.0.tgz
├── Oro_Api-1.2.11.0.tgz
├── Oro_Api-1.2.12.0.tgz
├── Oro_Api-1.2.13.0.tgz
├── Oro_Api-1.2.14.0.tgz
├── Oro_Api-1.2.15.0.tgz
├── Oro_Api-1.2.16.0.tgz
├── Oro_Api-1.2.17.0.tgz
├── Oro_Api-1.2.18.0.tgz
├── Oro_Api-1.2.19.0.tgz
├── Oro_Api-1.2.2.0.tgz
├── Oro_Api-1.2.3.0.tgz
├── Oro_Api-1.2.4.0.tgz
├── Oro_Api-1.2.5.0.tgz
├── Oro_Api-1.2.6.0.tgz
├── Oro_Api-1.2.7.0.tgz
├── Oro_Api-1.2.8.0.tgz
├── Oro_Api-1.2.9.0.tgz
├── Oro_Api.xml
└── package.xml
/.gitignore:
--------------------------------------------------------------------------------
1 | .idea/*
2 | app/etc/local.xml
3 | downloader/.cache/*
4 | tests/config.sh
5 | var/log/*
6 | var/locks/*
7 | var/report/*
8 | var/cache/*
9 | var/export/*
10 | var/session/*
11 |
--------------------------------------------------------------------------------
/CHANGELOG.md:
--------------------------------------------------------------------------------
1 | ## Changelog for 1.2.19
2 |
3 | - In the "sales_order.info" request, the value of the "entity_id" is now returned as the "increment_id" field (part of the status history data)
4 |
5 | ## Changelog for 1.2.17
6 |
7 | - made version compatible with OroCRM version 1.*
8 | - fixed: https://github.com/oroinc/magento-orocrm-bridge/issues/13
9 |
10 | ## Changelog for 1.2.16
11 |
12 | - fixed version on application config file
13 |
14 | ## Changelog for 1.2.15
15 |
16 | - Fixed bug with missing Gift Order Message during sync with OroCRM.
17 |
18 | ## Changelog for 1.2.14
19 |
20 | - Added new endpoint for getting Regions list
21 |
22 | ## Changelog for 1.1.4.4
23 |
24 | - Fixed issue on some environments with CE when class_exist is called on class from EE.
25 |
26 | ## Changelog for 1.1.4.3
27 |
28 | - Added possibility to see shopping cart management page in iframe using Oro_Api extension
29 |
30 | ## Changelog for 1.1.4.2
31 |
32 | - Removed "forgot password" link from login form in Oro-IFRAME
33 |
34 | ## Changelog for 1.1.4.1
35 |
36 | - Fix php notice during "shopping cart list" API call
37 |
38 | ## Changelog for 1.1.4
39 |
40 | - "Order form" styled with Oro-styles
41 | - Warning message for iframe if third-party cookies is denied by browser security policy
42 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | OroCRM Bridge Magento Extension
2 | =============
3 |
4 | The OroCRM Bridge extension improves on the Magento SOAP API v2 to expose additional shopping cart and customer data. These additional improvements allow companies to see:
5 |
6 | - List of active shopping carts
7 | - List of newsletter subscribers
8 | - List of viewed products
9 | - Customer wish list information
10 | - List of all regions
11 |
12 | The OroCRM Bridge is recommended for better integration between OroCRM and Magento. It can also be used for other integrations that require an API for the features listed.
13 |
--------------------------------------------------------------------------------
/app/code/community/Oro/Api/Helper/Data.php:
--------------------------------------------------------------------------------
1 | _getModuleName();
29 | }
30 |
31 | /**
32 | * Parse filters and format them to be applicable for collection filtration
33 | *
34 | * @param null|object|array $filters
35 | * @param array $fieldsMap Map of field names in format: array('field_name_in_filter' => 'field_name_in_db')
36 | * @return array
37 | */
38 | public function parseFilters($filters, $fieldsMap = null)
39 | {
40 | // if filters are used in SOAP they must be represented in array format to be used for collection filtration
41 | if (is_object($filters)) {
42 | $parsedFilters = array();
43 | // parse simple filter
44 | if (isset($filters->filter) && is_array($filters->filter)) {
45 | foreach ($filters->filter as $field => $value) {
46 | if (is_object($value) && isset($value->key) && isset($value->value)) {
47 | $parsedFilters[$value->key] = $value->value;
48 | } else {
49 | $parsedFilters[$field] = $value;
50 | }
51 | }
52 | }
53 | // parse complex filter
54 | if (isset($filters->complex_filter) && is_array($filters->complex_filter)) {
55 | $parsedFilters += $this->_parseComplexFilter($filters->complex_filter);
56 | }
57 |
58 | $filters = $parsedFilters;
59 | }
60 | // make sure that method result is always array
61 | if (!is_array($filters)) {
62 | $filters = array();
63 | }
64 | // apply fields mapping
65 | if (isset($fieldsMap) && is_array($fieldsMap)) {
66 | foreach ($filters as $field => $value) {
67 | if (isset($fieldsMap[$field])) {
68 | unset($filters[$field]);
69 | $field = $fieldsMap[$field];
70 | $filters[$field] = $value;
71 | }
72 | }
73 | }
74 | return $filters;
75 | }
76 |
77 | /**
78 | * Parses complex filter, which may contain several nodes, e.g. when user want to fetch orders which were updated
79 | * between two dates.
80 | *
81 | * @param array $complexFilter
82 | * @return array
83 | */
84 | protected function _parseComplexFilter($complexFilter)
85 | {
86 | $parsedFilters = array();
87 |
88 | foreach ($complexFilter as $filter) {
89 | if (!isset($filter->key) || !isset($filter->value)) {
90 | continue;
91 | }
92 |
93 | list($fieldName, $condition) = array($filter->key, $filter->value);
94 | $conditionName = $condition->key;
95 | $conditionValue = $condition->value;
96 | $this->formatFilterConditionValue($conditionName, $conditionValue);
97 |
98 | if (array_key_exists($fieldName, $parsedFilters)) {
99 | $parsedFilters[$fieldName] += array($conditionName => $conditionValue);
100 | } else {
101 | $parsedFilters[$fieldName] = array($conditionName => $conditionValue);
102 | }
103 | }
104 |
105 | return $parsedFilters;
106 | }
107 |
108 | /**
109 | * Convert condition value from the string into the array
110 | * for the condition operators that require value to be an array.
111 | * Condition value is changed by reference
112 | *
113 | * @param string $conditionOperator
114 | * @param string $conditionValue
115 | */
116 | public function formatFilterConditionValue($conditionOperator, &$conditionValue)
117 | {
118 | if (is_string($conditionOperator) && in_array($conditionOperator, array('in', 'nin', 'finset'))
119 | && is_string($conditionValue)
120 | ) {
121 | $delimiter = ',';
122 | $conditionValue = explode($delimiter, $conditionValue);
123 | }
124 | }
125 |
126 | /**
127 | * @param Varien_Data_Collection_Db $collection
128 | * @param \stdClass|null $pager
129 | *
130 | * @return boolean
131 | */
132 | public function applyPager($collection, $pager)
133 | {
134 | if ($pager->pageSize && $pager->page) {
135 | $collection->setCurPage($pager->page);
136 | $collection->setPageSize($pager->pageSize);
137 |
138 | if ($collection->getCurPage() != $pager->page) {
139 | return false;
140 | }
141 | }
142 |
143 | return true;
144 | }
145 |
146 | /**
147 | * @return bool
148 | */
149 | public function isOroRequest()
150 | {
151 | return (bool) Mage::registry('is-oro-request');
152 | }
153 |
154 | /**
155 | * Get WSDL/WSI complexType attributes by complex type name.
156 | *
157 | * @param string $typeName
158 | * @return array
159 | */
160 | public function getComplexTypeAttributes($typeName)
161 | {
162 | /** @var Mage_Api_Model_Wsdl_Config $wsdlModel */
163 | $wsdlModel = Mage::getModel('api/wsdl_config');
164 | $wsdlModel->init();
165 |
166 | $elements = array();
167 | if ($this->isComplianceWSI()) {
168 | $elements = $wsdlModel->getXpath(
169 | 'wsdl:types/xsd:schema/xsd:complexType[@name="' . $typeName . '"]/xsd:sequence/xsd:element'
170 | );
171 | } else {
172 | $typeDefinition = $wsdlModel->getNode('types/schema/complexType@name="' . $typeName . '"/all');
173 | if ($typeDefinition && $typeDefinition->children()->count() > 0) {
174 | $elements = $typeDefinition->children();
175 | }
176 | }
177 |
178 | $exposedAttributes = array();
179 | /** @var Mage_Api_Model_Wsdl_Config_Element $definitionNode */
180 | foreach ($elements as $definitionNode) {
181 | $name = (string)$definitionNode->getAttribute('name');
182 | $type = (string)$definitionNode->getAttribute('type');
183 | $exposedAttributes[$name] = $type;
184 | }
185 |
186 | return $exposedAttributes;
187 | }
188 |
189 | /**
190 | * Get WSDL/WSI complexType scalar attributes by complex type name.
191 | *
192 | * @param string $typeName
193 | * @return array
194 | */
195 | public function getComplexTypeScalarAttributes($typeName)
196 | {
197 | $scalarTypes = array('xsd:string', 'xsd:int', 'xsd:double', 'xsd:boolean', 'xsd:long');
198 |
199 | $result = array();
200 | $attributes = $this->getComplexTypeAttributes($typeName);
201 | foreach ($attributes as $typeName => $type) {
202 | if (in_array($type, $scalarTypes, true)) {
203 | $result[] = $typeName;
204 | }
205 | }
206 |
207 | return $result;
208 | }
209 |
210 | /**
211 | * Get entity attributes that are not not present in known attributes list.
212 | *
213 | * @param Varien_Object $entity
214 | * @param array $data
215 | * @param array $exclude
216 | * @param array $include
217 | * @return array
218 | */
219 | public function getNotIncludedAttributes(
220 | Varien_Object $entity,
221 | array $data,
222 | array $exclude = array(),
223 | array $include = array()
224 | ) {
225 | if (!Mage::getStoreConfig(self::XPATH_ATTRIBUTES_ENABLED)) {
226 | return array();
227 | }
228 |
229 | $entityData = $entity->__toArray();
230 | $knownAttributes = array_diff(array_keys($entityData), $exclude);
231 | $attributesToExpose = array_merge($knownAttributes, $include);
232 |
233 | $attributes = array();
234 |
235 | if (!empty($attributesToExpose)) {
236 | $attributes = array_intersect_key(
237 | array_merge($data, $entityData),
238 | array_combine($attributesToExpose, $attributesToExpose)
239 | );
240 | }
241 |
242 | return $this->packAssoc($attributes);
243 | }
244 |
245 | /**
246 | * Pack associative array to format supported by API.
247 | *
248 | * @param array $data
249 | * @return array
250 | */
251 | public function packAssoc(array $data)
252 | {
253 | $result = array();
254 | foreach ($data as $key => $value) {
255 | $result[] = array(
256 | 'key' => $key,
257 | 'value' => $value
258 | );
259 | }
260 |
261 | return $result;
262 | }
263 |
264 | /**
265 | * Get store/wibsite filter data as array from filter condition
266 | *
267 | * @param array $condition
268 | * @return array
269 | */
270 | public function getDataFromFilterCondition($condition)
271 | {
272 | $result = array();
273 |
274 | if (is_array($condition)) {
275 | if (isset($condition['eq'])) {
276 | $result = array($condition['eq']);
277 | } elseif (isset($condition['in'])) {
278 | $result = $condition['in'];
279 | }
280 | }
281 |
282 | return $result;
283 | }
284 | }
285 |
--------------------------------------------------------------------------------
/app/code/community/Oro/Api/Model/Admin/Redirectpolicy.php:
--------------------------------------------------------------------------------
1 | getControllerModule() === 'Oro_Api_Adminhtml'
25 | && $request->getControllerName() === 'oro_gateway') {
26 | return $alternativeUrl;
27 | }
28 | return parent::getRedirectUrl($user, $request, $alternativeUrl);
29 | }
30 | }
31 |
--------------------------------------------------------------------------------
/app/code/community/Oro/Api/Model/Catalog/Product/Api/V2.php:
--------------------------------------------------------------------------------
1 | getCollection();
32 | $collection->addStoreFilter($this->_getStoreId($store));
33 | $collection->addAttributeToSelect(array('name', 'price', 'special_price'));
34 |
35 | /** @var $apiHelper Mage_Api_Helper_Data */
36 | $apiHelper = Mage::helper('oro_api');
37 | $filters = $apiHelper->parseFilters($filters, $this->_filtersMap);
38 | try {
39 | foreach ($filters as $field => $value) {
40 | $collection->addFieldToFilter($field, $value);
41 | }
42 | } catch (Mage_Core_Exception $e) {
43 | $this->_fault('filters_invalid', $e->getMessage());
44 | }
45 | $result = array();
46 | foreach ($collection as $product) {
47 | $result[] = array(
48 | 'product_id' => $product->getId(),
49 | 'sku' => $product->getSku(),
50 | 'name' => $product->getName(),
51 | 'set' => $product->getAttributeSetId(),
52 | 'type' => $product->getTypeId(),
53 | 'category_ids' => $product->getCategoryIds(),
54 | 'website_ids' => $product->getWebsiteIds(),
55 | 'price' => $product->getPrice(),
56 | 'special_price' => $product->getSpecialPrice(),
57 | );
58 | }
59 | return $result;
60 | }
61 | }
--------------------------------------------------------------------------------
/app/code/community/Oro/Api/Model/Customer/Address/Api.php:
--------------------------------------------------------------------------------
1 | 'entity_id'
23 | );
24 |
25 | /**
26 | * @var Oro_Api_Helper_Data
27 | */
28 | protected $_apiHelper;
29 |
30 | /**
31 | * @var array|null
32 | */
33 | protected $_knownApiAttributes;
34 |
35 | public function __construct()
36 | {
37 | $this->_apiHelper = Mage::helper('oro_api');
38 | }
39 |
40 | /**
41 | * Retrieve customer addresses list
42 | *
43 | * @param int $customerId
44 | * @return array
45 | */
46 | public function items($customerId)
47 | {
48 | /* @var Mage_Customer_Model_Customer $customer */
49 | $customer = Mage::getModel('customer/customer')->load($customerId);
50 |
51 | if (!$customer->getId()) {
52 | $this->_fault('not_exists');
53 | }
54 |
55 | return $this->getAddressItems($customer);
56 | }
57 |
58 | /**
59 | * Retrieve address data
60 | *
61 | * @param int $addressId
62 | * @return array
63 | */
64 | public function info($addressId)
65 | {
66 | /** @var Mage_Customer_Model_Address $address */
67 | $address = Mage::getModel('customer/address')->load($addressId);
68 |
69 | if (!$address->getId()) {
70 | $this->_fault('address_not_exists');
71 | }
72 |
73 | return $this->getAddressData($address);
74 | }
75 |
76 | /**
77 | * Retrieve customer addresses list
78 | *
79 | * @param Mage_Customer_Model_Customer $customer
80 | * @return array
81 | */
82 | public function getAddressItems($customer)
83 | {
84 | $result = array();
85 | /** @var Mage_Customer_Model_Address $address */
86 | foreach ($customer->getAddresses() as $address) {
87 | $result[] = $this->getAddressData($address, $customer);
88 | }
89 |
90 | return $result;
91 | }
92 |
93 | /**
94 | * Get customer address data applicable for API response.
95 | *
96 | * @param Mage_Customer_Model_Address $address
97 | * @param Mage_Customer_Model_Customer|null $customer
98 | * @return array
99 | */
100 | public function getAddressData($address, $customer = null)
101 | {
102 | if (!$customer) {
103 | $customer = $address->getCustomer();
104 | }
105 |
106 | $data = $address->toArray();
107 | $row = array();
108 |
109 | foreach ($this->_mapAttributes as $attributeAlias => $attributeCode) {
110 | $row[$attributeAlias] = isset($data[$attributeCode]) ? $data[$attributeCode] : null;
111 | }
112 |
113 | foreach ($this->getAllowedAttributes($address) as $attributeCode => $attribute) {
114 | if (isset($data[$attributeCode])) {
115 | $row[$attributeCode] = $data[$attributeCode];
116 | }
117 | }
118 |
119 | $row['attributes'] = $this->_apiHelper
120 | ->getNotIncludedAttributes($address, $row, $this->_getKnownApiAttributes());
121 | $row['is_default_billing'] = $customer->getDefaultBilling() == $address->getId();
122 | $row['is_default_shipping'] = $customer->getDefaultShipping() == $address->getId();
123 |
124 | return $row;
125 | }
126 |
127 | /**
128 | * Get list of attributes exposed to API.
129 | *
130 | * @return array
131 | */
132 | protected function _getKnownApiAttributes()
133 | {
134 | if (!$this->_knownApiAttributes) {
135 | $this->_knownApiAttributes = array_merge(
136 | $this->_apiHelper->getComplexTypeScalarAttributes('customerAddressEntityItem'),
137 | array('entity_id')
138 | );
139 | }
140 |
141 | return $this->_knownApiAttributes;
142 | }
143 | }
144 |
--------------------------------------------------------------------------------
/app/code/community/Oro/Api/Model/Customer/Address/Api/V2.php:
--------------------------------------------------------------------------------
1 | 'entity_id'
23 | );
24 |
25 | /**
26 | * Attributes must be processed with source
27 | *
28 | * @var array
29 | */
30 | protected $_sourcedAttributes = array(
31 | 'gender'
32 | );
33 |
34 | /**
35 | * @var Oro_Api_Helper_Data
36 | */
37 | protected $_apiHelper;
38 |
39 | /**
40 | * @var array
41 | */
42 | protected $_knownApiAttributes = array();
43 |
44 | /**
45 | * @var Oro_Api_Model_Customer_Address_Api
46 | */
47 | protected $_addressModel;
48 |
49 | public function __construct()
50 | {
51 | $this->_apiHelper = Mage::helper('oro_api');
52 | $this->_addressModel = Mage::getModel('oro_api/customer_address_api');
53 | }
54 |
55 | /**
56 | * Create new customer
57 | *
58 | * @param array $customerData
59 | * @return int
60 | */
61 | public function create($customerData)
62 | {
63 | $customerData = $this->_prepareData($customerData);
64 |
65 | /** @var Mage_Customer_Model_Customer $customer */
66 | $customer = Mage::getModel('customer/customer');
67 | try {
68 | $customer->setData($customerData);
69 | $customer->save();
70 | } catch (Mage_Core_Exception $e) {
71 | $this->_fault('data_invalid', $e->getMessage());
72 | }
73 |
74 | return $customer->getId();
75 | }
76 |
77 | /**
78 | * Update customer data
79 | *
80 | * @param int $customerId
81 | * @param array $customerData
82 | * @return boolean
83 | */
84 | public function update($customerId, $customerData)
85 | {
86 | $customerData = $this->_prepareData($customerData);
87 |
88 | /** @var Mage_Customer_Model_Customer $customer */
89 | $customer = Mage::getModel('customer/customer')->load($customerId);
90 |
91 | if (!$customer->getId()) {
92 | $this->_fault('not_exists');
93 | }
94 |
95 | foreach ($this->getAllowedAttributes($customer) as $attributeCode => $attribute) {
96 | if (isset($customerData[$attributeCode])) {
97 | $customer->setData($attributeCode, $customerData[$attributeCode]);
98 | }
99 | }
100 |
101 | $customer->save();
102 |
103 | if (!empty($customerData['password'])) {
104 | $customer->changePassword($customerData['password']);
105 | }
106 |
107 | return true;
108 | }
109 |
110 | /**
111 | * Retrieve customers data
112 | *
113 | * @param object|array $filters
114 | * @param \stdClass $pager
115 | *
116 | * @return array
117 | */
118 | public function items($filters, $pager)
119 | {
120 | /** @var Mage_Customer_Model_Entity_Customer_Collection $collection */
121 | $collection = Mage::getModel('customer/customer')->getCollection()->addAttributeToSelect('*');
122 |
123 | $filters = $this->_apiHelper->parseFilters($filters, $this->_mapAttributes);
124 | try {
125 | foreach ($filters as $field => $value) {
126 | $collection->addFieldToFilter($field, $value);
127 | }
128 | } catch (Mage_Core_Exception $e) {
129 | $this->_fault('filters_invalid', $e->getMessage());
130 | }
131 |
132 | $collection->setOrder('entity_id', Varien_Data_Collection_Db::SORT_ORDER_ASC);
133 | if (!$this->_apiHelper->applyPager($collection, $pager)) {
134 | // there's no such page, so no results for it
135 | return array();
136 | }
137 |
138 | $result = array();
139 | /** @var Mage_Customer_Model_Customer $customer */
140 | foreach ($collection as $customer) {
141 | $row = $this->_getCustomerData($customer);
142 |
143 | $result[] = $row;
144 | }
145 |
146 | return $result;
147 | }
148 |
149 | /**
150 | * Retrieve customer data
151 | *
152 | * @param int $customerId
153 | * @param array $attributes
154 | * @return array
155 | */
156 | public function info($customerId, array $attributes = null)
157 | {
158 | /** @var Mage_Customer_Model_Customer $customer */
159 | $customer = Mage::getModel('customer/customer')->load($customerId);
160 |
161 | if (!$customer->getId()) {
162 | $this->_fault('not_exists');
163 | }
164 |
165 | return $this->_getCustomerData($customer, $attributes);
166 | }
167 |
168 | /**
169 | * Get customer data applicable for API response.
170 | *
171 | * @param Mage_Customer_Model_Customer $customer
172 | * @param array $allowedAttributes
173 | * @return array
174 | * @throws Mage_Core_Exception
175 | */
176 | protected function _getCustomerData($customer, array $allowedAttributes = null)
177 | {
178 | $row = array();
179 |
180 | if (!is_null($allowedAttributes) && !is_array($allowedAttributes)) {
181 | $allowedAttributes = array($allowedAttributes);
182 | }
183 |
184 | foreach ($this->_mapAttributes as $attributeAlias => $attributeCode) {
185 | $row[$attributeAlias] = $customer->getData($attributeCode);
186 | }
187 |
188 | foreach ($this->getAllowedAttributes($customer, $allowedAttributes) as $attributeCode => $attribute) {
189 | /** @var $attribute Mage_Customer_Model_Attribute */
190 | $row[$attributeCode] = $customer->getData($attributeCode);
191 | if (in_array($attributeCode, $this->_sourcedAttributes)) {
192 | $attributeValue = $attribute->getSource()->getOptionText($customer->getData($attributeCode));
193 | $row[$attributeCode] = !empty($attributeValue) ? $attributeValue : null;
194 | }
195 | }
196 | $row['addresses'] = $this->_addressModel->getAddressItems($customer);
197 |
198 | $attributes = $this->_apiHelper->getNotIncludedAttributes(
199 | $customer,
200 | $row,
201 | $this->_getKnownApiAttributes(),
202 | array('confirmation')
203 | );
204 | if ($attributes) {
205 | $row['attributes'] = $attributes;
206 | }
207 |
208 | return $row;
209 | }
210 |
211 | /**
212 | * @param array|\stdClass $data
213 | * @return array
214 | */
215 | protected function _prepareData($data)
216 | {
217 | $data = (array)$data;
218 | foreach ($this->_mapAttributes as $attributeAlias => $attributeCode) {
219 | if (isset($data[$attributeAlias])) {
220 | $data[$attributeCode] = $data[$attributeAlias];
221 | unset($data[$attributeAlias]);
222 | }
223 | }
224 |
225 | return $data;
226 | }
227 |
228 | /**
229 | * Get list of attributes exposed to API.
230 | *
231 | * @return array
232 | */
233 | protected function _getKnownApiAttributes()
234 | {
235 | if (!$this->_knownApiAttributes) {
236 | $this->_knownApiAttributes = array_merge(
237 | $this->_apiHelper->getComplexTypeScalarAttributes('oroCustomerEntity'),
238 | array('entity_id', 'default_shipping', 'default_billing')
239 | );
240 | }
241 |
242 | return $this->_knownApiAttributes;
243 | }
244 | }
245 |
--------------------------------------------------------------------------------
/app/code/community/Oro/Api/Model/Customer/Api/V2.php:
--------------------------------------------------------------------------------
1 | _apiHelper = Mage::helper('oro_api');
13 | }
14 |
15 |
16 | /**
17 | * Retrive list of regions
18 | *
19 | * @param object|array $filters
20 | * @param \stdClass $pager
21 | *
22 | * @return array
23 | */
24 | public function items($filters, $pager)
25 | {
26 | /** @var Mage_Directory_Model_Resource_Region_Collection $collection */
27 | $collection = Mage::getModel('directory/region')->getCollection();
28 |
29 | $filters = $this->_apiHelper->parseFilters($filters);
30 | try {
31 | foreach ($filters as $field => $value) {
32 | $collection->addFieldToFilter($field, $value);
33 | }
34 | } catch (Mage_Core_Exception $e) {
35 | $this->_fault('filters_invalid', $e->getMessage());
36 | }
37 |
38 | $collection->unshiftOrder('region_id', Varien_Data_Collection_Db::SORT_ORDER_ASC);
39 | if (!$this->_apiHelper->applyPager($collection, $pager)) {
40 | // there's no such page, so no results for it
41 | return array();
42 | }
43 |
44 | $result = array();
45 | /** @var Mage_Directory_Model_Region $region */
46 | foreach ($collection as $region) {
47 | $result[] = array(
48 | 'region_id' => $region->getId(),
49 | 'code' => $region->getCode(),
50 | 'countryCode' => $region->getCountryId(),
51 | 'name' => $region->getName(),
52 | );
53 | }
54 |
55 | return $result;
56 | }
57 | }
58 |
--------------------------------------------------------------------------------
/app/code/community/Oro/Api/Model/Directory/Region/Api/V2.php:
--------------------------------------------------------------------------------
1 | parseFilters($filters);
36 | try {
37 | foreach ($filters as $field => $value) {
38 | $collection->addFieldToFilter($field, $value);
39 | }
40 | } catch (Mage_Core_Exception $e) {
41 | $this->_fault('filters_invalid', $e->getMessage());
42 | }
43 | $collection->setOrder('subscriber_id', Varien_Data_Collection_Db::SORT_ORDER_DESC);
44 |
45 | if ($apiHelper->applyPager($collection, $pager)) {
46 | $result = $collection->toArray();
47 |
48 | if (array_key_exists('items', $result)) {
49 | return $result['items'];
50 | }
51 | }
52 |
53 | return array();
54 | }
55 |
56 | /**
57 | * Create new newsletter subscriber.
58 | *
59 | * @param object|array $subscriberData
60 | * @return array
61 | */
62 | public function create($subscriberData)
63 | {
64 | /** @var Mage_Newsletter_Model_Subscriber $subscriber */
65 | $subscriber = Mage::getModel('newsletter/subscriber');
66 |
67 | $subscriberData = (array)$subscriberData;
68 | if (empty($subscriberData['subscriber_confirm_code'])) {
69 | $subscriberData['subscriber_confirm_code'] = $subscriber->randomSequence();
70 | }
71 |
72 | $hasCustomer = !empty($subscriberData['customer_id']);
73 | /** @var Mage_Customer_Model_Customer $customer */
74 | $customer = null;
75 | if ($hasCustomer) {
76 | $customer = Mage::getModel('customer/customer')->load($subscriberData['customer_id']);
77 | if (!$customer->getId()) {
78 | $this->_fault('customer_not_found');
79 | }
80 |
81 | $subscriber->loadByCustomer($customer);
82 | if ($subscriber->getId()) {
83 | $this->_fault('customer_already_subscribed');
84 | }
85 | }
86 | if (!empty($subscriberData['subscriber_email'])) {
87 | $subscriber->loadByEmail($subscriberData['subscriber_email']);
88 | if ($subscriber->getId()) {
89 | if (!$subscriber->getCustomerId()) {
90 | $subscriber->setCustomerId($subscriberData['customer_id']);
91 | $subscriber->save();
92 | } else {
93 | $this->_fault('email_already_subscribed');
94 | }
95 | }
96 | } else {
97 | if ($customer && $customer->getEmail()) {
98 | $subscriberData['subscriber_email'] = $customer->getEmail();
99 | } else {
100 | $this->_fault('email_is_empty');
101 | }
102 | }
103 |
104 | // store_id can be 0
105 | if ($customer && $customer->getStore()
106 | && (!array_key_exists('store_id', $subscriberData) || strlen($subscriberData['store_id']) === 0)
107 | ) {
108 | $subscriberData['store_id'] = $customer->getStore()->getId();
109 | }
110 |
111 | if (!$subscriber->getId()) {
112 | $this->_saveSubscriber($subscriber, $subscriberData);
113 | }
114 |
115 | // Send subscribe confirmation email if needed.
116 | $isConfirmNeed = Mage::getStoreConfig(Mage_Newsletter_Model_Subscriber::XML_PATH_CONFIRMATION_FLAG) == 1;
117 | if ($isConfirmNeed) {
118 | if ($subscriber->getStatus() === Mage_Newsletter_Model_Subscriber::STATUS_SUBSCRIBED) {
119 | $subscriber->sendConfirmationSuccessEmail();
120 | } elseif ($subscriber->getStatus() === Mage_Newsletter_Model_Subscriber::STATUS_NOT_ACTIVE) {
121 | $subscriber->sendConfirmationRequestEmail();
122 | }
123 | }
124 |
125 | return $subscriber->toArray();
126 | }
127 |
128 | /**
129 | * Update newsletter subscriber data
130 | *
131 | * @param int $subscriberId
132 | * @param object|array $subscriberData
133 | * @return array
134 | * @throws Mage_Api_Exception
135 | */
136 | public function update($subscriberId, $subscriberData)
137 | {
138 | $subscriberData = (array)$subscriberData;
139 |
140 | /** @var Mage_Newsletter_Model_Subscriber $subscriber */
141 | $subscriber = Mage::getModel('newsletter/subscriber')
142 | ->load($subscriberId);
143 | if (!$subscriber->getId()) {
144 | $this->_fault('not_exists');
145 | }
146 |
147 | if (!empty($subscriberData['customer_id'])) {
148 | if ($subscriber->getCustomerId() && $subscriber->getCustomerId() != $subscriberData['customer_id']) {
149 | $this->_fault('subscriber_customer_change_forbidden');
150 | } elseif (!$subscriber->getCustomerId()) {
151 | /** @var Mage_Customer_Model_Customer $customer */
152 | $customer = Mage::getModel('customer/customer')->load($subscriberData['customer_id']);
153 | if (!$customer->getId()) {
154 | $this->_fault('customer_not_found');
155 | }
156 |
157 | $subscriber->loadByCustomer($customer);
158 | if ($subscriber->getId() != $subscriberId) {
159 | $this->_fault('customer_already_subscribed');
160 | }
161 | }
162 | }
163 | if (!empty($subscriberData['subscriber_email'])) {
164 | $subscriber->loadByEmail($subscriberData['subscriber_email']);
165 | if ($subscriber->getId() != $subscriberId) {
166 | $this->_fault('email_already_subscribed');
167 | }
168 | } else {
169 | unset($subscriberData['subscriber_email']);
170 | }
171 |
172 | $this->_saveSubscriber($subscriber, $subscriberData);
173 |
174 | return $subscriber->toArray();
175 | }
176 |
177 | /**
178 | * Subscribe by email.
179 | *
180 | * @param string $email
181 | * @return array
182 | * @throws Mage_Api_Exception
183 | */
184 | public function subscribeEmail($email)
185 | {
186 | /** @var Mage_Newsletter_Model_Subscriber $subscriber */
187 | $subscriber = Mage::getModel('newsletter/subscriber');
188 | try {
189 | $subscriber->subscribe($email);
190 | } catch (Mage_Core_Exception $e) {
191 | $this->_fault('data_invalid', $e->getMessage());
192 | }
193 |
194 | return $subscriber->toArray();
195 | }
196 |
197 | /**
198 | * Unsubscribe newsletter subscriber.
199 | *
200 | * @param int $subscriberId
201 | * @return bool
202 | * @throws Mage_Api_Exception
203 | */
204 | public function unsubscribe($subscriberId)
205 | {
206 | /** @var Mage_Newsletter_Model_Subscriber $subscriber */
207 | $subscriber = Mage::getModel('newsletter/subscriber')
208 | ->load($subscriberId);
209 |
210 | if (!$subscriber->getId()) {
211 | $this->_fault('not_exists');
212 | }
213 |
214 | try {
215 | $subscriber->unsubscribe();
216 | } catch (Mage_Core_Exception $e) {
217 | $this->_fault('data_invalid', $e->getMessage());
218 | }
219 |
220 | return true;
221 | }
222 |
223 | /**
224 | * @param Mage_Newsletter_Model_Subscriber $subscriber
225 | * @param array $data
226 | * @throws Exception
227 | * @throws Mage_Api_Exception
228 | */
229 | protected function _saveSubscriber(Mage_Newsletter_Model_Subscriber $subscriber, array $data)
230 | {
231 | unset($data['subscriber_id']);
232 | foreach ($data as $key => $value) {
233 | $subscriber->setData($key, $value);
234 | }
235 |
236 | try {
237 | $subscriber->save();
238 | } catch (Mage_Core_Exception $e) {
239 | $this->_fault('data_invalid', $e->getMessage());
240 | }
241 | }
242 | }
--------------------------------------------------------------------------------
/app/code/community/Oro/Api/Model/Newsletter/Subscriber/Api/V2.php:
--------------------------------------------------------------------------------
1 | getSubscriber();
26 | $now = new \DateTime('now', new \DateTimeZone('UTC'));
27 | $subscriber['change_status_at'] = $now->format('Y-m-d H:i:s');
28 | }
29 | }
30 |
--------------------------------------------------------------------------------
/app/code/community/Oro/Api/Model/Observer/Crm/Controller.php:
--------------------------------------------------------------------------------
1 | getEvent()->getData('controller_action');
30 |
31 | if (!preg_match('/^.+?\\/oro_gateway\\/clearSession/ui', $controller->getRequest()->getPathInfo())) {
32 | if (preg_match('/^.+?\\/oro_gateway\\/do$/ui', $controller->getRequest()->getOriginalPathInfo()) || $controller->getRequest()->getParam('is-oro-request') || $controller->getRequest()->getCookie('is-oro-request')) {
33 | $controller->setFlag('', 'is-oro-request', true);
34 | if (!Mage::registry('is-oro-request')) {
35 | Mage::register('is-oro-request', true);
36 | }
37 | }
38 | }
39 | }
40 |
41 | /**
42 | * @param Varien_Event_Observer $observer
43 | */
44 | public function handleResponse(Varien_Event_Observer $observer)
45 | {
46 | /** @var Mage_Core_Controller_Front_Action $controller */
47 | $controller = $observer->getEvent()->getData('controller_action');
48 | $session = Mage::getSingleton('adminhtml/session');
49 | if (Mage::helper('oro_api')->isOroRequest()) {
50 | if ($controller->getFullActionName() == $session->getData('oro_end_point')) {
51 | $messages = Mage::getSingleton('adminhtml/session')->getMessages(false);
52 | $quoteMessages = Mage::getSingleton('adminhtml/session_quote')->getMessages(false);
53 | $errors = array_merge($messages->getErrors(), $quoteMessages->getErrors());
54 |
55 | // assume that if error messages exist then do no redirect to "success_url"
56 | if (empty($errors)) {
57 | $this->_setCookieValue(0);
58 |
59 | // clear all messages
60 | Mage::getSingleton('adminhtml/session')->getMessages(true);
61 | Mage::getSingleton('adminhtml/session_quote')->getMessages(true);
62 |
63 | $controller->getResponse()->clearHeader('Location');
64 | $controller->getResponse()->clearBody();
65 | $controller->getResponse()->appendBody(
66 | ''
69 | )->sendResponse();
70 | return;
71 | }
72 | }
73 |
74 | $this->_setCookieValue(1);
75 | }
76 | }
77 |
78 | /**
79 | * @param Varien_Event_Observer $observer
80 | */
81 | public function handleRenderLayout(Varien_Event_Observer $observer)
82 | {
83 | $layout = Mage::app()->getLayout();
84 |
85 | //add check cookies script
86 | $layout->createBlock('adminhtml/template', 'oro_check_script', array('template' => 'oro/api/check.phtml'));
87 | $this->_insertBlock('oro_check_script', $layout);
88 |
89 | if (Mage::helper('oro_api')->isOroRequest()) {
90 | // Remove back button on Manage Shopping Cart of Customer if it's rendered in Oro Request.
91 | if (class_exists('Enterprise_Checkout_Block_Adminhtml_Manage', false) &&
92 | ($manageBlock = $layout->getBlock('ID')) instanceof Enterprise_Checkout_Block_Adminhtml_Manage
93 | ) {
94 | $manageBlock->removeButton('back');
95 | }
96 |
97 | if (($contentBlock = $layout->getBlock('content')) instanceof Mage_Adminhtml_Block_Sales_Order_Create) {
98 | $contentBlock->removeButton('reset');
99 |
100 | // remove cart sidebar in case if we create order for active shopping cart
101 | // because it has no sense to duplicate items info in two blocks
102 | $sidebar = $layout->getBlock('sidebar');
103 | /** @var $cartBlock Mage_Adminhtml_Block_Sales_Order_Create_Sidebar_Cart */
104 | $cartBlock = $sidebar->getChild('cart');
105 | if ($cartBlock && (bool)$cartBlock->getQuote()->getOrigData('is_active')) {
106 | $sidebar->unsetChild('cart');
107 | }
108 | }
109 |
110 | /** @var Mage_Core_Block_Text $script */
111 | $layout->createBlock('adminhtml/template', 'oro_script', array('template' => 'oro/api/script.phtml'));
112 |
113 | if (($loginForm = $layout->getBlock('form.additional.info')) instanceof Mage_Core_Block_Text_List) {
114 | $layout->createBlock(
115 | 'adminhtml/template',
116 | 'oro_login_styles',
117 | array('template' => 'oro/api/login_styles.phtml')
118 | );
119 | $loginForm->insert('oro_login_styles');
120 | } elseif ($layout->getBlock('head')) {
121 | $layout->getBlock('head')->addCss('oro_style.css');
122 | }
123 |
124 | $this->_insertBlock('oro_script', $layout);
125 |
126 | if ($layout->getBlock('root') instanceof Mage_Core_Block_Template) {
127 | $layout->getBlock('root')->setTemplate('oro/api/page.phtml');
128 | }
129 | }
130 | }
131 |
132 | /**
133 | * Insert block
134 | *
135 | * @param string $blockName
136 | * @param Mage_Core_Model_Layout $layout
137 | */
138 | protected function _insertBlock($blockName, Mage_Core_Model_Layout $layout)
139 | {
140 | $destination = null;
141 |
142 | switch (true) {
143 | case $layout->getBlock('form.additional.info') instanceof Mage_Core_Block_Text_List:
144 | $destination = $layout->getBlock('form.additional.info');
145 | break;
146 | case $layout->getBlock('before_body_end') instanceof Mage_Core_Block_Text_List:
147 | $destination = $layout->getBlock('before_body_end');
148 | break;
149 | case $layout->getBlock('content') instanceof Mage_Core_Block_Text_List:
150 | $destination = $layout->getBlock('content');
151 | break;
152 | default:
153 | $destination = null;
154 | break;
155 | }
156 |
157 | if ($destination) {
158 | $destination->insert($blockName);
159 | }
160 | }
161 |
162 | /**
163 | * Set oro cookie value
164 | *
165 | * @param mixed $value
166 | */
167 | protected function _setCookieValue($value)
168 | {
169 | Mage::getSingleton('core/cookie')->set('is-oro-request', $value, null, null, null, null, false);
170 | }
171 | }
172 |
--------------------------------------------------------------------------------
/app/code/community/Oro/Api/Model/Observer/Sales/Order.php:
--------------------------------------------------------------------------------
1 | getQuote();
30 |
31 | if (Mage::helper('oro_api')->isOroRequest() && (bool)$quote->getOrigData('is_active')) {
32 | $quote->setIsActive(false)
33 | ->save();
34 | }
35 | }
36 | }
37 |
--------------------------------------------------------------------------------
/app/code/community/Oro/Api/Model/Ping.php:
--------------------------------------------------------------------------------
1 | isWebsiteScope();
26 |
27 | return array(
28 | 'version' => (string)Mage::getConfig()->getNode('modules/Oro_Api/version'),
29 | 'mage_version' => Mage::getVersion(),
30 | 'admin_url' => Mage::getUrl('adminhtml'),
31 | 'customer_scope' => $customerScope,
32 | );
33 | }
34 | }
35 |
--------------------------------------------------------------------------------
/app/code/community/Oro/Api/Model/Ping/V2.php:
--------------------------------------------------------------------------------
1 | addIndexFilter();
30 | /** @var $apiHelper Mage_Api_Helper_Data */
31 | $apiHelper = Mage::helper('oro_api');
32 | $filters = $apiHelper->parseFilters($filters);
33 | try {
34 | foreach ($filters as $field => $value) {
35 | $collection->addFieldToFilter($field, $value);
36 | }
37 | } catch (Mage_Core_Exception $e) {
38 | $this->_fault('filters_invalid', $e->getMessage());
39 | }
40 |
41 | return $collection->load()->toArray();
42 | }
43 | }
44 |
--------------------------------------------------------------------------------
/app/code/community/Oro/Api/Model/Report/Product/Viewed/Api/V2.php:
--------------------------------------------------------------------------------
1 | getFlag('is_idx_table_joined')) {
24 | $this->joinTable(
25 | array('idx_table' => $this->_getTableName()),
26 | 'product_id=entity_id',
27 | '*',
28 | $this->_getWhereCondition()
29 | );
30 | $this->setFlag('is_idx_table_joined', true);
31 | }
32 | return $this;
33 | }
34 |
35 | /**
36 | * Retrieve Where Condition to Index table
37 | *
38 | * @return array
39 | */
40 | protected function _getWhereCondition()
41 | {
42 | return array();
43 | }
44 | }
--------------------------------------------------------------------------------
/app/code/community/Oro/Api/Model/Resource/Setup.php:
--------------------------------------------------------------------------------
1 | _init('oro_api/wishlist_status', 'wishlist_id');
37 | }
38 |
39 | /**
40 | * Clean status logs
41 | *
42 | * @param Oro_Api_Model_Wishlist_Status $object
43 | * @return Oro_Api_Model_Resource_Wishlist_Status
44 | */
45 | public function clean(Oro_Api_Model_Wishlist_Status $object)
46 | {
47 | $cleanTime = $object->getLogCleanTime();
48 | $this->_cleanStatuses($cleanTime);
49 |
50 | return $this;
51 | }
52 |
53 | /**
54 | * Clean statuses table
55 | *
56 | * @param int $time
57 | * @return Oro_Api_Model_Resource_Wishlist_Status
58 | */
59 | protected function _cleanStatuses($time)
60 | {
61 | $writeAdapter = $this->_getWriteAdapter();
62 | $timeLimit = $this->formatDate(Mage::getModel('core/date')->gmtTimestamp() - $time);
63 | $condition = array('deleted_at < ?' => $timeLimit);
64 |
65 | // remove wishlist statuses from oro_api/wishlist_status
66 | try {
67 | $writeAdapter->delete($this->getTable('oro_api/wishlist_status'), $condition);
68 | } catch (Exception $e) {
69 | Mage::log($e->getMessage());
70 | }
71 |
72 | return $this;
73 | }
74 | }
75 |
--------------------------------------------------------------------------------
/app/code/community/Oro/Api/Model/Resource/Wishlist/Status/Collection.php:
--------------------------------------------------------------------------------
1 | _init('oro_api/wishlist_status');
32 | }
33 | }
34 |
--------------------------------------------------------------------------------
/app/code/community/Oro/Api/Model/Sales/Order/Api.php:
--------------------------------------------------------------------------------
1 | array('order_id' => 'entity_id'),
23 | 'order_address' => array('address_id' => 'entity_id'),
24 | 'global' => array()
25 | );
26 |
27 | /**
28 | * @var Oro_Api_Helper_Data
29 | */
30 | protected $_apiHelper;
31 |
32 | /**
33 | * @var array
34 | */
35 | protected $_knownApiAttributes = array();
36 |
37 | public function __construct()
38 | {
39 | $this->_apiHelper = Mage::helper('oro_api');
40 | }
41 |
42 | /**
43 | * Retrieve list of orders. Filtration could be applied
44 | *
45 | * @param null|object|array $filters
46 | * @param null|\stdClass $pager
47 | *
48 | * @return array
49 | */
50 | public function items($filters = null, $pager = null)
51 | {
52 | $orders = array();
53 | $orderCollection = $this->getOrderCollection();
54 |
55 | $filters = $this->_apiHelper->parseFilters($filters, $this->_attributesMap['order']);
56 | try {
57 | foreach ($filters as $field => $value) {
58 | $orderCollection->addFieldToFilter($field, $value);
59 | }
60 | } catch (Mage_Core_Exception $e) {
61 | $this->_fault('filters_invalid', $e->getMessage());
62 | }
63 |
64 | $orderCollection->setOrder('entity_id', Varien_Data_Collection_Db::SORT_ORDER_ASC);
65 | if (!$this->_apiHelper->applyPager($orderCollection, $pager)) {
66 | // there's no such page, so no results for it
67 | return array();
68 | }
69 |
70 | foreach ($orderCollection as $order) {
71 | $orders[] = $this->_getOrderData($order);
72 | }
73 |
74 | return $orders;
75 | }
76 |
77 | /**
78 | * Retrieve full order information
79 | *
80 | * @param string $orderIncrementId
81 | * @return array
82 | */
83 | public function info($orderIncrementId)
84 | {
85 | /** @var Mage_Sales_Model_Order $order */
86 | $order = Mage::getModel('sales/order');
87 | $order->loadByIncrementId($orderIncrementId);
88 |
89 | if (!$order->getId()) {
90 | $this->_fault('not_exists');
91 | }
92 |
93 | return $this->_getOrderData($order);
94 | }
95 |
96 | /**
97 | * @param Mage_Sales_Model_Order $order
98 | * @return array
99 | */
100 | protected function _getOrderData($order)
101 | {
102 | /** @var array $orderData */
103 | $orderData = $this->_getAttributes($order, 'order');
104 |
105 | $attributes = $this->_apiHelper->getNotIncludedAttributes($order, $orderData, $this->getKnownApiAttributes());
106 | if ($attributes) {
107 | $orderData['attributes'] = $attributes;
108 | }
109 | $orderData = array_merge($orderData, $this->_getOrderAdditionalInfo($order));
110 |
111 | return $orderData;
112 | }
113 |
114 | /**
115 | * Retrieve detailed order information
116 | *
117 | * @param Mage_Sales_Model_Order $order
118 | * @return array
119 | */
120 | protected function _getOrderAdditionalInfo($order)
121 | {
122 | if ($order->getGiftMessageId() > 0) {
123 | $orderGiftMessage = Mage::getSingleton('giftmessage/message')->load($order->getGiftMessageId())
124 | ->getMessage();
125 | } else {
126 | $orderGiftMessage = null;
127 | }
128 |
129 | $result = array();
130 | $result['gift_message'] = $orderGiftMessage;
131 | $result['shipping_address'] = $this->_getAttributes($order->getShippingAddress(), 'order_address');
132 | $result['billing_address'] = $this->_getAttributes($order->getBillingAddress(), 'order_address');
133 | $result['items'] = array();
134 |
135 | /** @var Mage_Sales_Model_Order_Item $item */
136 | foreach ($order->getAllItems() as $item) {
137 | if ($item->getGiftMessageId() > 0) {
138 | $cartItemGiftMessage = Mage::getSingleton('giftmessage/message')->load($item->getGiftMessageId())
139 | ->getMessage();
140 | } else {
141 | $cartItemGiftMessage = null;
142 | }
143 |
144 | $cartItemInfo = $this->_getAttributes($item, 'order_item');
145 | $cartItemInfo['gift_message'] = $cartItemGiftMessage;
146 | $result['items'][] = $cartItemInfo;
147 | }
148 |
149 | $result['payment'] = $this->_getAttributes($order->getPayment(), 'order_payment');
150 |
151 | $result['status_history'] = array();
152 |
153 | foreach ($order->getAllStatusHistory() as $history) {
154 | $historyAttributes = $this->_getAttributes($history, 'order_status_history');
155 | // Force adding entity_id to history data for correct import
156 | $historyAttributes['increment_id'] = $history->getId();
157 | $result['status_history'][] = $historyAttributes;
158 | }
159 |
160 | $result['coupon_code'] = $order->getCouponCode();
161 |
162 | return $result;
163 | }
164 |
165 | /**
166 | * @return Mage_Sales_Model_Mysql4_Order_Collection
167 | */
168 | protected function getOrderCollection()
169 | {
170 | //TODO: add full name logic
171 | $billingAliasName = 'billing_o_a';
172 | $shippingAliasName = 'shipping_o_a';
173 |
174 | /** @var $orderCollection Mage_Sales_Model_Mysql4_Order_Collection */
175 | $orderCollection = Mage::getModel("sales/order")->getCollection();
176 |
177 | $billingFirstnameField = "$billingAliasName.firstname";
178 | $billingLastnameField = "$billingAliasName.lastname";
179 | $shippingFirstnameField = "$shippingAliasName.firstname";
180 | $shippingLastnameField = "$shippingAliasName.lastname";
181 |
182 | $orderCollection->addAttributeToSelect('*')
183 | ->addAddressFields()
184 | ->addExpressionFieldToSelect(
185 | 'billing_firstname',
186 | "{{billing_firstname}}",
187 | array('billing_firstname' => $billingFirstnameField)
188 | )
189 | ->addExpressionFieldToSelect(
190 | 'billing_lastname',
191 | "{{billing_lastname}}",
192 | array('billing_lastname' => $billingLastnameField)
193 | )
194 | ->addExpressionFieldToSelect(
195 | 'shipping_firstname',
196 | "{{shipping_firstname}}",
197 | array('shipping_firstname' => $shippingFirstnameField)
198 | )
199 | ->addExpressionFieldToSelect(
200 | 'shipping_lastname',
201 | "{{shipping_lastname}}",
202 | array('shipping_lastname' => $shippingLastnameField)
203 | )
204 | ->addExpressionFieldToSelect(
205 | 'billing_name',
206 | "CONCAT({{billing_firstname}}, ' ', {{billing_lastname}})",
207 | array('billing_firstname' => $billingFirstnameField, 'billing_lastname' => $billingLastnameField)
208 | )
209 | ->addExpressionFieldToSelect(
210 | 'shipping_name',
211 | 'CONCAT({{shipping_firstname}}, " ", {{shipping_lastname}})',
212 | array('shipping_firstname' => $shippingFirstnameField, 'shipping_lastname' => $shippingLastnameField)
213 | );
214 |
215 | $orderCollection->join(
216 | array('store' => 'core/store'),
217 | 'main_table.store_id = store.store_id',
218 | array('website_id' => 'website_id')
219 | );
220 | $orderCollection->addFilterToMap('store_id', 'main_table.store_id');
221 |
222 | return $orderCollection;
223 | }
224 |
225 | /**
226 | * Get list of attributes exposed to API.
227 | *
228 | * @return array
229 | */
230 | protected function getKnownApiAttributes()
231 | {
232 | if (!$this->_knownApiAttributes) {
233 | $this->_knownApiAttributes = array_merge(
234 | $this->_apiHelper->getComplexTypeScalarAttributes('salesOrderEntity'),
235 | array('entity_id')
236 | );
237 | }
238 |
239 | return $this->_knownApiAttributes;
240 | }
241 | }
242 |
--------------------------------------------------------------------------------
/app/code/community/Oro/Api/Model/Sales/Order/Api/V2.php:
--------------------------------------------------------------------------------
1 | _categoryCollection = Mage::getResourceModel('catalog/category_collection')
39 | ->addAttributeToSelect('name');
40 |
41 | $this->_apiHelper = Mage::helper('oro_api');
42 | }
43 |
44 | /**
45 | * Retrieve list of quotes. Filtration could be applied
46 | *
47 | * @param array|object $filters
48 | * @param \stdClass $pager
49 | *
50 | * @return array
51 | */
52 | public function items($filters, $pager)
53 | {
54 | /** @var Mage_Sales_Model_Resource_Quote_Collection $quoteCollection */
55 | $quoteCollection = Mage::getResourceModel('sales/quote_collection');
56 | $filters = $this->_apiHelper->parseFilters($filters);
57 | try {
58 | foreach ($filters as $field => $value) {
59 | $quoteCollection->addFieldToFilter($field, $value);
60 | }
61 | } catch (Mage_Core_Exception $e) {
62 | $this->_fault('filters_invalid', $e->getMessage());
63 | }
64 |
65 | $quoteCollection->setOrder('entity_id', Varien_Data_Collection_Db::SORT_ORDER_ASC);
66 | if (!$this->_apiHelper->applyPager($quoteCollection, $pager)) {
67 | // there's no such page, so no results for it
68 | return array();
69 | }
70 |
71 | $this->_preparesGiftMessages($quoteCollection);
72 |
73 | $resultArray = array();
74 | /** @var Mage_Sales_Model_Quote $quote */
75 | foreach ($quoteCollection as $quote) {
76 | $row = $quote->__toArray();
77 | $attributes = $this->_apiHelper->getNotIncludedAttributes($quote, $row, $this->_getKnownQuoteAttributes());
78 | if ($attributes) {
79 | $row['attributes'] = $attributes;
80 | }
81 | $row = array_merge($row, $this->info($quote));
82 | $resultArray[] = $row;
83 | }
84 |
85 | return $resultArray;
86 | }
87 |
88 | /**
89 | * Retrieve full information about quote
90 | *
91 | * @param Mage_Sales_Model_Quote $quote
92 | * @return array
93 | */
94 | protected function info($quote)
95 | {
96 | $result = $this->_getAttributes($quote, 'quote');
97 | $result['shipping_address'] = $this->_getAttributes($quote->getShippingAddress(), 'quote_address');
98 | $result['billing_address'] = $this->_getAttributes($quote->getBillingAddress(), 'quote_address');
99 | $result['items'] = array();
100 |
101 | /** @var Mage_Sales_Model_Quote_Item $item */
102 | foreach ($quote->getAllItems() as $item) {
103 | $quoteItem = $this->_getAttributes($item, 'quote_item');
104 | $productAttributes = $this->_getProductAttributes($item);
105 | $quoteItem = array_merge($quoteItem, $productAttributes);
106 |
107 | $result['items'][] = $quoteItem;
108 | }
109 |
110 | $result['payment'] = $this->_getAttributes($quote->getPayment(), 'quote_payment');
111 | if (isset($result['payment'], $result['payment']['additional_information'])
112 | && is_array($result['payment']['additional_information'])
113 | ) {
114 | $result['payment']['additional_information'] = serialize($result['payment']['additional_information']);
115 | }
116 |
117 | return $result;
118 | }
119 |
120 | /**
121 | * @param Mage_Sales_Model_Quote_Item $item
122 | * @return array
123 | */
124 | protected function _getProductAttributes($item)
125 | {
126 | $result = array();
127 | $product = $item->getProduct();
128 |
129 | if ($product) {
130 | $productImage = $product->getData('image');
131 | if ($productImage) {
132 | $result['product_image_url'] = Mage::getSingleton('catalog/product_media_config')
133 | ->getMediaUrl($productImage);
134 | }
135 | $result['product_url'] = $product->getProductUrl(false);
136 |
137 | $productCategoryIds = $product->getCategoryIds();
138 | foreach ($productCategoryIds as $categoryId) {
139 | $category = $this->_categoryCollection->getItemById($categoryId);
140 | if ($category) {
141 | $result['categories'][] = array(
142 | 'name' => $category->getName()
143 | );
144 | }
145 | }
146 | }
147 |
148 | return $result;
149 | }
150 |
151 | /**
152 | * Get list of attributes exposed to API.
153 | *
154 | * @return array
155 | */
156 | protected function _getKnownQuoteAttributes()
157 | {
158 | if (!$this->_knownAttributes) {
159 | $this->_knownAttributes = array_merge(
160 | $this->_apiHelper->getComplexTypeScalarAttributes('salesQuoteEntity'),
161 | array('entity_id')
162 | );
163 | }
164 |
165 | return $this->_knownAttributes;
166 | }
167 |
168 | /**
169 | * Set gift_message key to quote and quote item
170 | *
171 | * @param Mage_Sales_Model_Resource_Quote_Collection $quoteCollection
172 | */
173 | protected function _preparesGiftMessages($quoteCollection)
174 | {
175 | $messageIds = array();
176 | /* @var Mage_Sales_Model_Quote $quote */
177 | foreach ($quoteCollection as $quote) {
178 | if ($quote->getGiftMessageId()) {
179 | $messageIds[] = $quote->getGiftMessageId();
180 | }
181 | foreach ($quote->getAllItems() as $quoteItem) {
182 | if ($quoteItem->getGiftMessageId()) {
183 | $messageIds[] = $quoteItem->getGiftMessageId();
184 | }
185 | }
186 | }
187 |
188 | if (!$messageIds) {
189 | return;
190 | }
191 |
192 | $messageIds = array_unique($messageIds);
193 |
194 | $giftCollection = Mage::getResourceModel('giftmessage/message_collection');
195 | $giftCollection->addFieldToFilter('gift_message_id', array('in' => $messageIds));
196 |
197 | /* @var Mage_Sales_Model_Quote $quote */
198 | foreach ($quoteCollection as $quote) {
199 | if ($quote->getGiftMessageId()) {
200 | $quote->setGiftMessage($giftCollection->getItemById($quote->getGiftMessageId())->getMessage());
201 | }
202 | foreach ($quote->getAllItems() as $quoteItem) {
203 | if ($quoteItem->getGiftMessageId()) {
204 | $quoteItem->setGiftMessage($giftCollection->getItemById($quoteItem->getGiftMessageId())->getMessage());
205 | }
206 | }
207 | }
208 | }
209 | }
210 |
--------------------------------------------------------------------------------
/app/code/community/Oro/Api/Model/Sales/Quote/Api/V2.php:
--------------------------------------------------------------------------------
1 | getProductId()) {
28 | return $this;
29 | }
30 |
31 | return parent::checkData();
32 | }
33 | }
34 |
--------------------------------------------------------------------------------
/app/code/community/Oro/Api/Model/Website/Api.php:
--------------------------------------------------------------------------------
1 | getWebsites(true);
29 |
30 | // Make result array
31 | $result = array();
32 | foreach ($websites as $website) {
33 | $result[] = $website->toArray();
34 | }
35 |
36 | return $result;
37 | }
38 | }
39 |
--------------------------------------------------------------------------------
/app/code/community/Oro/Api/Model/Website/Api/V2.php:
--------------------------------------------------------------------------------
1 | 'entity_id'
26 | );
27 |
28 | /**
29 | * Store ids (website stores)
30 | *
31 | * @var array
32 | */
33 | protected $storeIds = null;
34 |
35 | /**
36 | * @var Oro_Api_Helper_Data
37 | */
38 | protected $apiHelper;
39 |
40 | /**
41 | * Constructor.
42 | */
43 | public function __construct()
44 | {
45 | $this->apiHelper = Mage::helper('oro_api');
46 | }
47 |
48 | /**
49 | * @param array|object $filters
50 | * @param \stdClass $pager
51 | * @return array
52 | */
53 | public function items($filters, $pager = null)
54 | {
55 | /** @var Mage_Wishlist_Model_Resource_Wishlist_Collection $collection */
56 | $collection = Mage::getResourceModel('wishlist/wishlist_collection');
57 | $filters = $this->apiHelper->parseFilters($filters);
58 | try {
59 | foreach ($filters as $field => $value) {
60 | $collection->addFieldToFilter($field, $value);
61 | }
62 | } catch (Mage_Core_Exception $e) {
63 | $this->_fault('filters_invalid', $e->getMessage());
64 | }
65 |
66 | if ($pager && !$this->apiHelper->applyPager($collection, $pager)) {
67 | // there's no such page, so no results for it
68 | return array();
69 | }
70 |
71 | $arr = $collection->toArray();
72 |
73 | return $arr['items'];
74 | }
75 |
76 | /**
77 | * Get wishlist with items info
78 | *
79 | * @param array|object $filters
80 | * @param null|\stdClass $pager
81 | * @return array
82 | *
83 | * @throws Mage_Api_Exception
84 | */
85 | public function listWithItems($filters, $pager = null)
86 | {
87 | /** @var Mage_Wishlist_Model_Resource_Wishlist_Collection $collection */
88 | $collection = Mage::getResourceModel('wishlist/wishlist_collection');
89 | $filters = $this->apiHelper->parseFilters($filters, array('updated_at' => 'main_table.updated_at'));
90 | /* Prepare store/website filters for wishlist */
91 | $filters = $this->prepareFilters($filters);
92 |
93 | try {
94 | foreach ($filters as $field => $value) {
95 | $collection->addFieldToFilter($field, $value);
96 | }
97 | // Load customer data
98 | $collection = $this->addCustomerData($collection);
99 | } catch (Mage_Core_Exception $e) {
100 | $this->_fault('filters_invalid', $e->getMessage());
101 | }
102 |
103 | if ($pager && !$this->apiHelper->applyPager($collection, $pager)) {
104 | // there's no such page, so no results for it
105 | return array();
106 | }
107 |
108 | $result = array();
109 | foreach ($collection as $wishlist) {
110 | /** @var Mage_Wishlist_Model_Wishlist $wishlist */
111 | $wishlistData = $this->info($wishlist);
112 | $result[] = $wishlistData;
113 | }
114 |
115 | return $result;
116 | }
117 |
118 | /**
119 | * Retrieve store ids
120 | *
121 | * @param null|integer $websiteId
122 | * @return array
123 | */
124 | public function getStoreIds($websiteId = null)
125 | {
126 | $storeIds = array();
127 | if ($websiteId) {
128 | $website = Mage::getModel('core/website')->load($websiteId);
129 | $storeIds = $website->getStoreIds();
130 | } else {
131 | $stores = Mage::app()->getStores();
132 | foreach ($stores as $store) {
133 | $storeIds[] = $store->getId();
134 | }
135 | }
136 | return $storeIds;
137 | }
138 |
139 | /**
140 | * Add customer data to collection
141 | *
142 | * @param Mage_Wishlist_Model_Resource_Wishlist_Collection $collection
143 | * @return Mage_Wishlist_Model_Resource_Wishlist_Collection
144 | */
145 | protected function addCustomerData($collection)
146 | {
147 | $customerTable = $collection->getTable('customer/entity');
148 | $select = $collection->getSelect();
149 | $select->joinLeft(
150 | array('customer' => $customerTable),
151 | 'main_table.customer_id = customer.entity_id',
152 | array(
153 | 'customer_email' => 'email',
154 | 'website_id' => 'website_id'
155 | )
156 | );
157 |
158 | return $collection;
159 | }
160 |
161 | /**
162 | * Retrieve full information about wishlist
163 | *
164 | * @param Mage_Wishlist_Model_Wishlist $wishlist
165 | * @return array
166 | */
167 | protected function info($wishlist)
168 | {
169 | $result = $wishlist->toArray();
170 | $result['items'] = array();
171 |
172 | // Load wishlist items data
173 | /** @var Mage_Wishlist_Model_Resource_Item_Collection $collection */
174 | $collection = Mage::getResourceModel('wishlist/item_collection')
175 | ->addWishlistFilter($wishlist)
176 | ->addStoreFilter($this->storeIds)
177 | ->setVisibilityFilter();
178 |
179 | /** @var Mage_Wishlist_Model_Item $item */
180 | foreach ($collection as $item) {
181 | $product = $item->getProduct();
182 | if ($product) {
183 | $item->setSku($product->getSku());
184 | $item->setProductName($product->getName());
185 | $item->setWebsiteId(Mage::app()->getStore($item->getStoreId())->getWebsiteId());
186 | }
187 | $wishlistItem = $item->toArray();
188 | unset($wishlistItem['product']);
189 | $result['items'][] = $wishlistItem;
190 | }
191 | return $result;
192 | }
193 |
194 | /**
195 | * Prepare store/website filters for wishlist
196 | *
197 | * Exclude store fields from complex filter for wishlist if exists
198 | * Save store filter data to storeIds - used for filter wishlist items
199 | * Save website filter data to websiteIds - used for filter wishlists by customer's website
200 | *
201 | * If website filter exists in the incoming filter (from integration) and customer accounts shared globally
202 | * ignore sent filters, set all stores where customer can be presented to storeIds
203 | *
204 | * Example if complex filter:
205 | * 'website_id',
206 | * [
207 | * 'key' => 'website_id',
208 | * 'value' => [
209 | * 'key' => 'eq',
210 | * 'value' => '1'
211 | * ]
212 | * ]
213 | * 'store_id',
214 | * [
215 | * 'key' => 'store_id',
216 | * 'value' => [
217 | * 'key' => 'in',
218 | * 'value' => [1,2]
219 | * ]
220 | * ]
221 | *
222 | * @param array $filters
223 | * @return array
224 | */
225 | protected function prepareFilters($filters)
226 | {
227 | if (Mage::getSingleton('customer/config_share')->isWebsiteScope()) {
228 | if (isset($filters['store_id'])) {
229 | $storeIds = $this->apiHelper->getDataFromFilterCondition($filters['store_id']);
230 | $this->storeIds = $storeIds;
231 | unset($filters['store_id']);
232 | }
233 | if (isset($filters['website_id'])) {
234 | $websiteIds = $this->apiHelper->getDataFromFilterCondition($filters['website_id']);
235 | if (!$this->storeIds) {
236 | foreach ($websiteIds as $websiteId) {
237 | $storeIds = $this->getStoreIds($websiteId);
238 | foreach ($storeIds as $id) {
239 | $this->storeIds[] = $id;
240 | }
241 | }
242 | }
243 | }
244 | } else {
245 | unset($filters['store_id']);
246 | unset($filters['website_id']);
247 | }
248 |
249 | if (!$this->storeIds) {
250 | $this->storeIds = $this->getStoreIds();
251 | }
252 |
253 | return $filters;
254 | }
255 | }
256 |
--------------------------------------------------------------------------------
/app/code/community/Oro/Api/Model/Wishlist/Api/V2.php:
--------------------------------------------------------------------------------
1 | parseFilters($filters);
32 | try {
33 | foreach ($filters as $field => $value) {
34 | $collection->addFieldToFilter($field, $value);
35 | }
36 | } catch (Mage_Core_Exception $e) {
37 | $this->_fault('filters_invalid', $e->getMessage());
38 | }
39 |
40 | $arr = $collection->toArray();
41 |
42 | return $arr['items'];
43 | }
44 | }
45 |
--------------------------------------------------------------------------------
/app/code/community/Oro/Api/Model/Wishlist/Item/Api/V2.php:
--------------------------------------------------------------------------------
1 | isModuleEnabled('Enterprise_Wishlist') &&
33 | Mage::helper('enterprise_wishlist')->isMultipleEnabled()) {
34 | /** @var Mage_Wishlist_Model_Wishlist $wishlist */
35 | $wishlist = $observer->getEvent()->getObject();
36 | $wishlistId = $wishlist->getId();
37 | if ($wishlistId) {
38 | try {
39 | $websiteId = $this->getWishlistOwnerWebsiteId($wishlist);
40 | /** @var Oro_Api_Model_Wishlist_Status $wishlistStatus */
41 | $wishlistStatus = Mage::getModel('oro_api/wishlist_status')
42 | ->setWishlistId($wishlistId)
43 | ->setWebsiteId($websiteId)
44 | ->setDeletedAt(Mage::getSingleton('core/date')->gmtDate());
45 | $wishlistStatus->save();
46 | } catch (Exception $e) {
47 | Mage::log($e->getMessage());
48 | }
49 | }
50 | }
51 |
52 | return $this;
53 | }
54 |
55 | /**
56 | * Retrieve wishlist owner website
57 | *
58 | * @param Mage_Wishlist_Model_Wishlist $wishlist
59 | * @return null
60 | */
61 | public function getWishlistOwnerWebsiteId($wishlist)
62 | {
63 | $customerId = $wishlist->getCustomerId();
64 | if ($customerId) {
65 | /** @var Mage_Customer_Model_Customer $owner */
66 | $owner = Mage::getModel("customer/customer");
67 | $owner->load($customerId);
68 | if ($owner->getId()) {
69 | return $owner->getWebsiteId();
70 | }
71 | }
72 |
73 | return null;
74 | }
75 | }
76 |
--------------------------------------------------------------------------------
/app/code/community/Oro/Api/Model/Wishlist/Status.php:
--------------------------------------------------------------------------------
1 | _init('oro_api/wishlist_status');
32 | }
33 |
34 | public function getLogCleanTime()
35 | {
36 | return Mage::getStoreConfig(self::XML_WISHLIST_STATUS_CLEAN_DAYS) * 60 * 60 * 24;
37 | }
38 |
39 | /**
40 | * Clean statuses
41 | *
42 | * @return Oro_Api_Model_Wishlist_Status
43 | */
44 | public function clean()
45 | {
46 | $this->getResource()->clean($this);
47 | return $this;
48 | }
49 | }
50 |
--------------------------------------------------------------------------------
/app/code/community/Oro/Api/Model/Wishlist/Status/Api.php:
--------------------------------------------------------------------------------
1 | apiHelper = Mage::helper('oro_api');
35 | }
36 |
37 | /**
38 | * Get wishlist status list
39 | *
40 | * @param array|object $filters
41 | * @param null|\stdClass $pager
42 | * @return array
43 | * @throws Mage_Api_Exception
44 | */
45 | public function items($filters, $pager = null)
46 | {
47 | /** @var Oro_Api_Model_Resource_Wishlist_Status_Collection $collection */
48 | $collection = Mage::getResourceModel('oro_api/wishlist_status_collection');
49 | $filters = $this->apiHelper->parseFilters($filters);
50 | try {
51 | foreach ($filters as $field => $value) {
52 | $collection->addFieldToFilter($field, $value);
53 | }
54 | } catch (Mage_Core_Exception $e) {
55 | $this->_fault('filters_invalid', $e->getMessage());
56 | }
57 |
58 | if ($pager && !$this->apiHelper->applyPager($collection, $pager)) {
59 | // there's no such page, so no results for it
60 | return array();
61 | }
62 |
63 | $result = array();
64 | /** @var Oro_Api_Model_Wishlist_Status $status */
65 | foreach ($collection as $status) {
66 | $result[] = $status->toArray();
67 | }
68 |
69 | return $result;
70 | }
71 | }
72 |
--------------------------------------------------------------------------------
/app/code/community/Oro/Api/Model/Wishlist/Status/Api/V2.php:
--------------------------------------------------------------------------------
1 | getRequest();
29 | $params = $request->getParams();
30 |
31 | if (isset($params['route'])) {
32 | $route = $params['route'];
33 | unset($params['route']);
34 | $params['is-oro-request'] = true;
35 |
36 | $url = $this->getUrl('adminhtml/' . $route, array('_query' => $params));
37 |
38 | $configFile = Mage::getConfig()->getModuleDir('etc',Mage::helper('oro_api')->getModuleName()) . DS . 'workflow.xml';
39 | /** @var Mage_Catalog_Model_Config $config */
40 | $config = Mage::getModel('core/config');
41 | $config->loadFile($configFile);
42 |
43 | $workFlow = $request->getParam('workflow');
44 |
45 | $endPoints = $config->getXpath("{$workFlow}/end_point_action");
46 | if (count($endPoints)) {
47 | $endPoint = (string)array_shift($endPoints);
48 |
49 | Mage::getSingleton('adminhtml/session')->setData('oro_end_point', $endPoint);
50 | Mage::getSingleton('adminhtml/session')->setData('oro_success_url', $request->getParam('success_url'));
51 | Mage::getSingleton('adminhtml/session')->setData('oro_error_url', $request->getParam('error_url'));
52 |
53 | $this->_redirectUrl($url);
54 |
55 | } else {
56 | $this->getResponse()->setBody($this->__('Endpoint not found.'));
57 | }
58 | } else {
59 | $this->getResponse()->setBody($this->__('Please specify route name.'));
60 | }
61 | }
62 |
63 | /**
64 | * Gateway error
65 | */
66 | public function errorAction()
67 | {
68 | $response = $this->getResponse();
69 |
70 | $response->setBody($this->__('Gateway error.'));
71 | $response->setHttpResponseCode(400);
72 | }
73 |
74 | /**
75 | * {@inheritdoc}
76 | */
77 | protected function _isAllowed()
78 | {
79 | return true;
80 | }
81 | }
82 |
--------------------------------------------------------------------------------
/app/code/community/Oro/Api/controllers/Adminhtml/Oro/SalesController.php:
--------------------------------------------------------------------------------
1 | clear();
26 |
27 | $quoteId = $this->getRequest()->getParam('quote');
28 | if (null !== $quoteId) {
29 | $quote = $this->_getQuoteById($quoteId);
30 | }
31 |
32 | $customerId = $this->getRequest()->getParam('customer');
33 | if (null !== $customerId && $this->_checkCustomer($customerId)) {
34 | $session->setQuoteId(null);
35 | $session->setCustomerId((int)$customerId);
36 | } elseif (false !== $quote) {
37 | $customerId = (int)$quote->getCustomerId();
38 |
39 | $session->setStoreId($quote->getStoreId());
40 | $session->setQuoteId($quote->getId());
41 | $session->setCustomerId($customerId);
42 | } else {
43 | return $this->_redirect('*/oro_gateway/error');
44 | }
45 |
46 | return $this->_redirect('*/checkout/index', array('customer' => $customerId));
47 | }
48 |
49 | public function newOrderAction()
50 | {
51 | $quote = false;
52 | $session = Mage::getSingleton('adminhtml/session_quote');
53 | $session->clear();
54 |
55 | $quoteId = $this->getRequest()->getParam('quote');
56 | if (null !== $quoteId) {
57 | $quote = $this->_getQuoteById($quoteId);
58 | }
59 |
60 | $customerId = $this->getRequest()->getParam('customer');
61 | if (null !== $customerId && $this->_checkCustomer($customerId)) {
62 | $session->setQuoteId(null);
63 | $session->setCustomerId((int)$customerId);
64 | } elseif (false !== $quote) {
65 | $customerId = (int)$quote->getCustomerId();
66 |
67 | $session->setStoreId($quote->getStoreId());
68 | $session->setQuoteId($quote->getId());
69 | $session->setCustomerId($customerId);
70 | } else {
71 | return $this->_redirect('*/oro_gateway/error');
72 | }
73 |
74 | return $this->_redirect('*/sales_order_create/index', array('customer_id' => $customerId));
75 | }
76 |
77 | /**
78 | * Load customer's frontend quote by given ID
79 | *
80 | * @param int $quoteId
81 | *
82 | * @return bool|Mage_Sales_Model_Quote
83 | */
84 | protected function _getQuoteById($quoteId)
85 | {
86 | /** @var Mage_Sales_Model_Quote $quote */
87 | $quote = Mage::getModel('sales/quote');
88 | $quote->loadByIdWithoutStore($quoteId);
89 |
90 | return $quote->getId() ? $quote : false;
91 | }
92 |
93 | /**
94 | * Checks whether customer exists
95 | *
96 | * @param int $customerId
97 | *
98 | * @return bool
99 | */
100 | private function _checkCustomer($customerId)
101 | {
102 | $customer = Mage::getModel('customer/customer')->load($customerId);
103 |
104 | return (bool)$customer->getId();
105 | }
106 |
107 | /**
108 | * {@inheritdoc}
109 | */
110 | protected function _isAllowed()
111 | {
112 | return true;
113 | }
114 | }
115 |
--------------------------------------------------------------------------------
/app/code/community/Oro/Api/etc/adminhtml.xml:
--------------------------------------------------------------------------------
1 |
2 |
20 |
41 |
45 |
53 |
57 | 100
66 | 101
70 |
80 |
84 | 100
103 | 101
107 | 102
111 | 103
115 |
125 |
129 | 102
138 | 103
142 |
152 |
156 |
164 |
168 |
176 |
180 | 100
184 |
194 |
198 | 100
202 |
212 |
216 |
224 |
228 | 100
248 | 101
252 | 102
256 | 103
260 | 104
264 | 105
268 | 106
272 | 107
276 |
286 |
290 |
298 |
302 |
353 |
355 |
391 |
393 | oro_wishlist_status
37 |
102 |
108 |