Version Notes
Small fix to make invoice capture offline paramater optional
Download this release
Release Info
Developer | FarApp |
Extension | FarApp_Connector |
Version | 1.1.6 |
Comparing to | |
See all releases |
Version 1.1.6
- app/code/community/FarApp/Connector/Model/Export.php +93 -0
- app/code/community/FarApp/Connector/Model/Export/Adapter/Abstract.php +120 -0
- app/code/community/FarApp/Connector/Model/Export/Adapter/Array.php +16 -0
- app/code/community/FarApp/Connector/Model/Export/Entity/Order.php +79 -0
- app/code/community/FarApp/Connector/Model/Import.php +7 -0
- app/code/community/FarApp/Connector/Model/Import/Entity/Customer.php +126 -0
- app/code/community/FarApp/Connector/Model/Import/Entity/Order.php +661 -0
- app/code/community/FarApp/Connector/Model/Import/Entity/Product.php +185 -0
- app/code/community/FarApp/Connector/Model/Import/Entity/minVersion2.php +3144 -0
- app/code/community/FarApp/Connector/Model/Order/Invoice/Api.php +42 -0
- app/code/community/FarApp/Connector/controllers/ExportController.php +265 -0
- app/code/community/FarApp/Connector/controllers/ImportController.php +121 -0
- app/code/community/FarApp/Connector/controllers/IndexController.php +9 -0
- app/code/community/FarApp/Connector/etc/api.xml +16 -0
- app/code/community/FarApp/Connector/etc/config.xml +76 -0
- app/code/community/FarApp/Connector/etc/wsdl.xml +17 -0
- app/etc/modules/FarApp_Connector.xml +17 -0
- package.xml +18 -0
app/code/community/FarApp/Connector/Model/Export.php
ADDED
@@ -0,0 +1,93 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
class FarApp_Connector_Model_Export extends Mage_ImportExport_Model_Export
|
4 |
+
{
|
5 |
+
public function processProductExport($filter = null)
|
6 |
+
{
|
7 |
+
$this->setEntity(Mage_Catalog_Model_Product::ENTITY);
|
8 |
+
$this->_getEntityAdapter()->setParameters($this->getFilters());
|
9 |
+
return $this->export();
|
10 |
+
|
11 |
+
}
|
12 |
+
|
13 |
+
public function processCustomerExport($filter = null)
|
14 |
+
{
|
15 |
+
$this->setEntity('customer');
|
16 |
+
$this->_getEntityAdapter()->setParameters($this->getFilters());
|
17 |
+
return $this->export();
|
18 |
+
}
|
19 |
+
public function processOrderExport($filter = null)
|
20 |
+
{
|
21 |
+
$this->setEntity('order');
|
22 |
+
$entityAdapter = Mage::getModel('farapp_connector/export_entity_order');
|
23 |
+
$entityAdapter->setIncludePayment($this->getIncludePayment());
|
24 |
+
$entityAdapter->setIncludeItems($this->getIncludeItems());
|
25 |
+
$entityAdapter->setIncludeShipment($this->getIncludeShipment());
|
26 |
+
$entityAdapter->setIncludeAddresses($this->getIncludeAddresses());
|
27 |
+
$this->setEntityAdapter($entityAdapter);
|
28 |
+
return $this->export();
|
29 |
+
}
|
30 |
+
public function export()
|
31 |
+
{
|
32 |
+
$this->addLogComment(Mage::helper('importexport')->__('Begin export of %s', $this->getEntity()));
|
33 |
+
//var_dump(get_class($this->_getEntityAdapter()));
|
34 |
+
$result = $this->_getEntityAdapter()
|
35 |
+
->setWriter($this->_getWriter())
|
36 |
+
->export();
|
37 |
+
|
38 |
+
return $result;
|
39 |
+
}
|
40 |
+
|
41 |
+
public function getIncludeAddresses()
|
42 |
+
{
|
43 |
+
return $this->getData('include_addresses');
|
44 |
+
}
|
45 |
+
public function getIncludeShipment()
|
46 |
+
{
|
47 |
+
return $this->getData('include_shipment');
|
48 |
+
}
|
49 |
+
public function getIncludePayment()
|
50 |
+
{
|
51 |
+
return $this->getData('include_payment');
|
52 |
+
}
|
53 |
+
public function getFilters()
|
54 |
+
{
|
55 |
+
return (array)$this->getData('export_filter');
|
56 |
+
}
|
57 |
+
public function getIncludeItems()
|
58 |
+
{
|
59 |
+
return $this->getData('include_items');
|
60 |
+
}
|
61 |
+
|
62 |
+
protected function _getWriter()
|
63 |
+
{
|
64 |
+
|
65 |
+
if (!$this->_writer) {
|
66 |
+
$this->_writer = Mage::getModel('farapp_connector/export_adapter_array');
|
67 |
+
if (! $this->_writer instanceof FarApp_Connector_Model_Export_Adapter_Abstract) {
|
68 |
+
Mage::throwException(
|
69 |
+
Mage::helper('importexport')->__('Adapter object must be an instance of %s', 'FarApp_Connector_Model_Export_Adapter_Abstract')
|
70 |
+
);
|
71 |
+
}
|
72 |
+
}
|
73 |
+
return $this->_writer;
|
74 |
+
}
|
75 |
+
|
76 |
+
/**
|
77 |
+
* @param Mage_ImportExport_Model_Import_Entity_Abstract $entityAdapter
|
78 |
+
*
|
79 |
+
* @return void
|
80 |
+
*/
|
81 |
+
public function setEntityAdapter($entityAdapter)
|
82 |
+
{
|
83 |
+
$this->_entityAdapter = $entityAdapter;
|
84 |
+
}
|
85 |
+
|
86 |
+
/**
|
87 |
+
* @return Mage_ImportExport_Model_Import_Entity_Abstract
|
88 |
+
*/
|
89 |
+
public function getEntityAdapter()
|
90 |
+
{
|
91 |
+
return $this->_entityAdapter;
|
92 |
+
}
|
93 |
+
}
|
app/code/community/FarApp/Connector/Model/Export/Adapter/Abstract.php
ADDED
@@ -0,0 +1,120 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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@magentocommerce.com so we can send you a copy immediately.
|
14 |
+
*
|
15 |
+
* DISCLAIMER
|
16 |
+
*
|
17 |
+
* Do not edit or add to this file if you wish to upgrade Magento to newer
|
18 |
+
* versions in the future. If you wish to customize Magento for your
|
19 |
+
* needs please refer to http://www.magentocommerce.com for more information.
|
20 |
+
*
|
21 |
+
* @category Mage
|
22 |
+
* @package Mage_ImportExport
|
23 |
+
* @copyright Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
|
24 |
+
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
|
25 |
+
*/
|
26 |
+
|
27 |
+
abstract class FarApp_Connector_Model_Export_Adapter_Abstract
|
28 |
+
{
|
29 |
+
/**
|
30 |
+
* Destination file path.
|
31 |
+
*
|
32 |
+
* @var string
|
33 |
+
*/
|
34 |
+
protected $_destination;
|
35 |
+
|
36 |
+
/**
|
37 |
+
* Header columns names.
|
38 |
+
*
|
39 |
+
* @var array
|
40 |
+
*/
|
41 |
+
protected $_headerCols = null;
|
42 |
+
|
43 |
+
/**
|
44 |
+
* Adapter object constructor.
|
45 |
+
*
|
46 |
+
* @param string $destination OPTIONAL Destination file path.
|
47 |
+
* @throws Exception
|
48 |
+
* @return void
|
49 |
+
*/
|
50 |
+
final public function __construct($destination = null)
|
51 |
+
{
|
52 |
+
$this->_init();
|
53 |
+
}
|
54 |
+
|
55 |
+
/**
|
56 |
+
* Method called as last step of object instance creation. Can be overridden in child classes.
|
57 |
+
*
|
58 |
+
* @return Mage_ImportExport_Model_Export_Adapter_Abstract
|
59 |
+
*/
|
60 |
+
protected function _init()
|
61 |
+
{
|
62 |
+
return $this;
|
63 |
+
}
|
64 |
+
|
65 |
+
/**
|
66 |
+
* Get contents of export file.
|
67 |
+
*
|
68 |
+
* @return string
|
69 |
+
*/
|
70 |
+
abstract public function getContents();
|
71 |
+
|
72 |
+
/**
|
73 |
+
* MIME-type for 'Content-Type' header.
|
74 |
+
*
|
75 |
+
* @return string
|
76 |
+
*/
|
77 |
+
public function getContentType()
|
78 |
+
{
|
79 |
+
return 'application/octet-stream';
|
80 |
+
}
|
81 |
+
|
82 |
+
/**
|
83 |
+
* Return file extension for downloading.
|
84 |
+
*
|
85 |
+
* @return string
|
86 |
+
*/
|
87 |
+
public function getFileExtension()
|
88 |
+
{
|
89 |
+
return '';
|
90 |
+
}
|
91 |
+
|
92 |
+
/**
|
93 |
+
* Set column names.
|
94 |
+
*
|
95 |
+
* @param array $headerCols
|
96 |
+
* @throws Exception
|
97 |
+
* @return Mage_ImportExport_Model_Export_Adapter_Abstract
|
98 |
+
*/
|
99 |
+
public function setHeaderCols(array $headerCols)
|
100 |
+
{
|
101 |
+
if (null !== $this->_headerCols) {
|
102 |
+
Mage::throwException(Mage::helper('importexport')->__('Header column names already set'));
|
103 |
+
}
|
104 |
+
if ($headerCols) {
|
105 |
+
foreach ($headerCols as $colName) {
|
106 |
+
$this->_headerCols[$colName] = false;
|
107 |
+
}
|
108 |
+
fputcsv($this->_fileHandler, array_keys($this->_headerCols), $this->_delimiter, $this->_enclosure);
|
109 |
+
}
|
110 |
+
return $this;
|
111 |
+
}
|
112 |
+
|
113 |
+
/**
|
114 |
+
* Write row data to source file.
|
115 |
+
*
|
116 |
+
* @param array $rowData
|
117 |
+
* @return Mage_ImportExport_Model_Export_Adapter_Abstract
|
118 |
+
*/
|
119 |
+
abstract public function writeRow(array $rowData);
|
120 |
+
}
|
app/code/community/FarApp/Connector/Model/Export/Adapter/Array.php
ADDED
@@ -0,0 +1,16 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
|
4 |
+
class FarApp_Connector_Model_Export_Adapter_Array extends FarApp_Connector_Model_Export_Adapter_Abstract
|
5 |
+
{
|
6 |
+
protected $_content = array();
|
7 |
+
public function writeRow(array $rowData)
|
8 |
+
{
|
9 |
+
$this->_content[] = $rowData;
|
10 |
+
}
|
11 |
+
|
12 |
+
public function getContents()
|
13 |
+
{
|
14 |
+
return $this->_content;
|
15 |
+
}
|
16 |
+
}
|
app/code/community/FarApp/Connector/Model/Export/Entity/Order.php
ADDED
@@ -0,0 +1,79 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
class FarApp_Connector_Model_Export_Entity_Order extends Mage_ImportExport_Model_Export_Entity_Abstract
|
3 |
+
{
|
4 |
+
protected $_shipment = false;
|
5 |
+
protected $_items = false;
|
6 |
+
protected $_payment = false;
|
7 |
+
protected $_addresses = false;
|
8 |
+
/**
|
9 |
+
* Export process.
|
10 |
+
*
|
11 |
+
* @return string
|
12 |
+
*/
|
13 |
+
public function export()
|
14 |
+
{
|
15 |
+
|
16 |
+
$orders = Mage::getModel("sales/order")->getCollection();
|
17 |
+
|
18 |
+
foreach ($orders as $key => $order) {
|
19 |
+
$result[$key] = $order->getData();
|
20 |
+
if ($this->_addresses) {
|
21 |
+
if ($order->getShippingAddress() && !$order->getShippingAddress()->getData('same_as_billing')) {
|
22 |
+
$result[$key]['shipping_address'] = $order->getShippingAddress()->getData();
|
23 |
+
}
|
24 |
+
$result[$key]['billing_address'] = $order->getBillingAddress()->getData();
|
25 |
+
}
|
26 |
+
if ($this->_items) {
|
27 |
+
foreach ($order->getAllItems() as $item) {
|
28 |
+
$result[$key]['items'][] = $item->getData();
|
29 |
+
}
|
30 |
+
}
|
31 |
+
if ($this->_payment) {
|
32 |
+
$result[$key]['payment'] = $order->getPayment()->getData();
|
33 |
+
}
|
34 |
+
if ($this->_shipment) {
|
35 |
+
$result[$key]['shipments'] = $order->getShipmentsCollection()->getData();
|
36 |
+
}
|
37 |
+
}
|
38 |
+
return $result;
|
39 |
+
}
|
40 |
+
|
41 |
+
|
42 |
+
public function setIncludePayment($input = false)
|
43 |
+
{
|
44 |
+
$this->_payment = $input;
|
45 |
+
}
|
46 |
+
public function setIncludeAddresses($input = false)
|
47 |
+
{
|
48 |
+
$this->_addresses = $input;
|
49 |
+
}
|
50 |
+
|
51 |
+
public function setIncludeItems($input = false)
|
52 |
+
{
|
53 |
+
$this->_items = $input;
|
54 |
+
}
|
55 |
+
|
56 |
+
public function setIncludeShipment($input = false)
|
57 |
+
{
|
58 |
+
$this->_shipment = $input;
|
59 |
+
}
|
60 |
+
/**
|
61 |
+
* Entity attributes collection getter.
|
62 |
+
*
|
63 |
+
* @return Mage_Eav_Model_Resource_Entity_Attribute_Collection
|
64 |
+
*/
|
65 |
+
public function getAttributeCollection()
|
66 |
+
{
|
67 |
+
return Mage::getResourceModel('sales_order/attribute_collection');
|
68 |
+
}
|
69 |
+
|
70 |
+
/**
|
71 |
+
* EAV entity type code getter.
|
72 |
+
*
|
73 |
+
* @return string
|
74 |
+
*/
|
75 |
+
public function getEntityTypeCode()
|
76 |
+
{
|
77 |
+
return "order";
|
78 |
+
}
|
79 |
+
}
|
app/code/community/FarApp/Connector/Model/Import.php
ADDED
@@ -0,0 +1,7 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
*/
|
4 |
+
class FarApp_Connector_Model_Import extends Mage_ImportExport_Model_Import
|
5 |
+
{
|
6 |
+
}
|
7 |
+
|
app/code/community/FarApp/Connector/Model/Import/Entity/Customer.php
ADDED
@@ -0,0 +1,126 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
*/
|
4 |
+
class FarApp_Connector_Model_Import_Entity_Customer extends Mage_ImportExport_Model_Import_Entity_Customer
|
5 |
+
{
|
6 |
+
/**
|
7 |
+
* Constructor.
|
8 |
+
*
|
9 |
+
* @return void
|
10 |
+
*/
|
11 |
+
public function __construct()
|
12 |
+
{
|
13 |
+
parent::__construct();
|
14 |
+
$this->_errorsLimit = 1000000000;
|
15 |
+
}
|
16 |
+
|
17 |
+
public function setPoints($customer_id = false, $points = false, $comment = 'Adjustment', $action = 0) {
|
18 |
+
$customer = Mage::getModel('customer/customer')->load($customer_id);
|
19 |
+
|
20 |
+
$reward = Mage::getModel('enterprise_reward/reward');
|
21 |
+
|
22 |
+
if (!$customer || !$reward) {
|
23 |
+
return;
|
24 |
+
}
|
25 |
+
|
26 |
+
$reward->setCustomer($customer)
|
27 |
+
->setWebsiteId(Mage::app()->getWebsite()->getId())
|
28 |
+
->loadByCustomer();
|
29 |
+
|
30 |
+
$reward->setPointsBalance($points)
|
31 |
+
->setAction($action) // Enterprise_Reward_Model_Reward::REWARD_ACTION_ADMIN
|
32 |
+
->setComment($comment)
|
33 |
+
->updateRewardPoints();
|
34 |
+
|
35 |
+
$history = Mage::getModel('enterprise_reward/reward_history')
|
36 |
+
->setReward($reward)->prepareFromReward()->save();
|
37 |
+
}
|
38 |
+
|
39 |
+
protected function _saveCustomers() {
|
40 |
+
$resource = Mage::getModel('customer/customer');
|
41 |
+
$strftimeFormat = Varien_Date::convertZendToStrftime(Varien_Date::DATETIME_INTERNAL_FORMAT, true, true);
|
42 |
+
$table = $resource->getResource()->getEntityTable();
|
43 |
+
$nextEntityId = Mage::getResourceHelper('importexport')->getNextAutoincrement($table);
|
44 |
+
$passId = $resource->getAttribute('password_hash')->getId();
|
45 |
+
$passTable = $resource->getAttribute('password_hash')->getBackend()->getTable();
|
46 |
+
|
47 |
+
while ($bunch = $this->_dataSourceModel->getNextBunch()) {
|
48 |
+
$entityRowsIn = array();
|
49 |
+
$entityRowsUp = array();
|
50 |
+
$attributes = array();
|
51 |
+
$rewardPoints = array();
|
52 |
+
|
53 |
+
$oldCustomersToLower = array_change_key_case($this->_oldCustomers, CASE_LOWER);
|
54 |
+
|
55 |
+
foreach ($bunch as $rowNum => $rowData) {
|
56 |
+
if (!$this->validateRow($rowData, $rowNum)) {
|
57 |
+
continue;
|
58 |
+
}
|
59 |
+
if (self::SCOPE_DEFAULT == $this->getRowScope($rowData)) {
|
60 |
+
// entity table data
|
61 |
+
$entityRow = array(
|
62 |
+
'group_id' => empty($rowData['group_id']) ? self::DEFAULT_GROUP_ID : $rowData['group_id'],
|
63 |
+
'store_id' => empty($rowData[self::COL_STORE])
|
64 |
+
? 0 : $this->_storeCodeToId[$rowData[self::COL_STORE]],
|
65 |
+
'created_at' => empty($rowData['created_at'])
|
66 |
+
? now() : gmstrftime($strftimeFormat, strtotime($rowData['created_at'])),
|
67 |
+
'updated_at' => now()
|
68 |
+
);
|
69 |
+
|
70 |
+
$emailToLower = strtolower($rowData[self::COL_EMAIL]);
|
71 |
+
if (isset($oldCustomersToLower[$emailToLower][$rowData[self::COL_WEBSITE]])) { // edit
|
72 |
+
$entityId = $oldCustomersToLower[$emailToLower][$rowData[self::COL_WEBSITE]];
|
73 |
+
$entityRow['entity_id'] = $entityId;
|
74 |
+
$entityRowsUp[] = $entityRow;
|
75 |
+
} else { // create
|
76 |
+
$entityId = $nextEntityId++;
|
77 |
+
$entityRow['entity_id'] = $entityId;
|
78 |
+
$entityRow['entity_type_id'] = $this->_entityTypeId;
|
79 |
+
$entityRow['attribute_set_id'] = 0;
|
80 |
+
$entityRow['website_id'] = $this->_websiteCodeToId[$rowData[self::COL_WEBSITE]];
|
81 |
+
$entityRow['email'] = $rowData[self::COL_EMAIL];
|
82 |
+
$entityRow['is_active'] = 1;
|
83 |
+
$entityRowsIn[] = $entityRow;
|
84 |
+
|
85 |
+
$this->_newCustomers[$rowData[self::COL_EMAIL]][$rowData[self::COL_WEBSITE]] = $entityId;
|
86 |
+
}
|
87 |
+
// attribute values
|
88 |
+
foreach (array_intersect_key($rowData, $this->_attributes) as $attrCode => $value) {
|
89 |
+
if (!$this->_attributes[$attrCode]['is_static'] && strlen($value)) {
|
90 |
+
/** @var $attribute Mage_Customer_Model_Attribute */
|
91 |
+
$attribute = $resource->getAttribute($attrCode);
|
92 |
+
$backModel = $attribute->getBackendModel();
|
93 |
+
$attrParams = $this->_attributes[$attrCode];
|
94 |
+
|
95 |
+
if ('select' == $attrParams['type']) {
|
96 |
+
$value = $attrParams['options'][strtolower($value)];
|
97 |
+
} elseif ('datetime' == $attrParams['type']) {
|
98 |
+
$value = gmstrftime($strftimeFormat, strtotime($value));
|
99 |
+
} elseif ($backModel) {
|
100 |
+
$attribute->getBackend()->beforeSave($resource->setData($attrCode, $value));
|
101 |
+
$value = $resource->getData($attrCode);
|
102 |
+
}
|
103 |
+
$attributes[$attribute->getBackend()->getTable()][$entityId][$attrParams['id']] = $value;
|
104 |
+
|
105 |
+
// restore 'backend_model' to avoid default setting
|
106 |
+
$attribute->setBackendModel($backModel);
|
107 |
+
}
|
108 |
+
}
|
109 |
+
// password change/set
|
110 |
+
if (isset($rowData['password']) && strlen($rowData['password'])) {
|
111 |
+
$attributes[$passTable][$entityId][$passId] = $resource->hashPassword($rowData['password']);
|
112 |
+
}
|
113 |
+
// reward balance change/set
|
114 |
+
if (isset($rowData['reward_point_balance']) && strlen($rowData['reward_point_balance'])) {
|
115 |
+
$rewardPoints[$entityId] = $rowData['reward_point_balance'];
|
116 |
+
}
|
117 |
+
}
|
118 |
+
}
|
119 |
+
$this->_saveCustomerEntity($entityRowsIn, $entityRowsUp)->_saveCustomerAttributes($attributes);
|
120 |
+
foreach ($rewardPoints as $entityId => $rewardPointBalance) {
|
121 |
+
$this->setPoints($entityId, $rewardPointBalance);
|
122 |
+
}
|
123 |
+
}
|
124 |
+
return $this;
|
125 |
+
}
|
126 |
+
}
|
app/code/community/FarApp/Connector/Model/Import/Entity/Order.php
ADDED
@@ -0,0 +1,661 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* Import entity order model
|
4 |
+
*/
|
5 |
+
class FarApp_Connector_Model_Import_Entity_Order extends Mage_ImportExport_Model_Import_Entity_Abstract
|
6 |
+
{
|
7 |
+
/**
|
8 |
+
* Size of bunch - part of entities to save in one step.
|
9 |
+
*/
|
10 |
+
const BUNCH_SIZE = 20;
|
11 |
+
|
12 |
+
/**
|
13 |
+
* Data row scopes.
|
14 |
+
*/
|
15 |
+
const SCOPE_DEFAULT = 1;
|
16 |
+
const SCOPE_ADDRESS = -1;
|
17 |
+
|
18 |
+
/**
|
19 |
+
* Permanent column names.
|
20 |
+
*
|
21 |
+
* Names that begins with underscore is not an attribute. This name convention is for
|
22 |
+
* to avoid interference with same attribute name.
|
23 |
+
*/
|
24 |
+
const COL_EMAIL = 'customer_email';
|
25 |
+
const COL_STORE = 'store_id';
|
26 |
+
|
27 |
+
/**
|
28 |
+
* Error codes.
|
29 |
+
*/
|
30 |
+
const ERROR_INVALID_WEBSITE = 'invalidWebsite';
|
31 |
+
const ERROR_INVALID_EMAIL = 'invalidEmail';
|
32 |
+
const ERROR_DUPLICATE_EMAIL_SITE = 'duplicateEmailSite';
|
33 |
+
const ERROR_EMAIL_IS_EMPTY = 'emailIsEmpty';
|
34 |
+
const ERROR_ROW_IS_ORPHAN = 'rowIsOrphan';
|
35 |
+
const ERROR_VALUE_IS_REQUIRED = 'valueIsRequired';
|
36 |
+
const ERROR_INVALID_STORE = 'invalidStore';
|
37 |
+
const ERROR_EMAIL_SITE_NOT_FOUND = 'emailSiteNotFound';
|
38 |
+
const ERROR_PASSWORD_LENGTH = 'passwordLength';
|
39 |
+
|
40 |
+
/**
|
41 |
+
* Order constants
|
42 |
+
*
|
43 |
+
*/
|
44 |
+
const DEFAULT_GROUP_ID = 1;
|
45 |
+
const MAX_PASSWD_LENGTH = 6;
|
46 |
+
|
47 |
+
/**
|
48 |
+
* Order address import entity model.
|
49 |
+
*
|
50 |
+
* @var Mage_ImportExport_Model_Import_Entity_Order_Address
|
51 |
+
*/
|
52 |
+
protected $_addressEntity;
|
53 |
+
|
54 |
+
/**
|
55 |
+
* Order attributes parameters.
|
56 |
+
*
|
57 |
+
* [attr_code_1] => array(
|
58 |
+
* 'options' => array(),
|
59 |
+
* 'type' => 'text', 'price', 'textarea', 'select', etc.
|
60 |
+
* 'id' => ..
|
61 |
+
* ),
|
62 |
+
* ...
|
63 |
+
*
|
64 |
+
* @var array
|
65 |
+
*/
|
66 |
+
protected $_attributes = array();
|
67 |
+
|
68 |
+
/**
|
69 |
+
* Order account sharing. TRUE - is global, FALSE - is per website.
|
70 |
+
*
|
71 |
+
* @var boolean
|
72 |
+
*/
|
73 |
+
protected $_orderGlobal;
|
74 |
+
|
75 |
+
/**
|
76 |
+
* Order groups ID-to-name.
|
77 |
+
*
|
78 |
+
* @var array
|
79 |
+
*/
|
80 |
+
protected $_orderGroups = array();
|
81 |
+
|
82 |
+
/**
|
83 |
+
* Order entity DB table name.
|
84 |
+
*
|
85 |
+
* @var string
|
86 |
+
*/
|
87 |
+
protected $_entityTable;
|
88 |
+
|
89 |
+
/**
|
90 |
+
* Array of attribute codes which will be ignored in validation and import procedures.
|
91 |
+
* For example, when entity attribute has own validation and import procedures
|
92 |
+
* or just to deny this attribute processing.
|
93 |
+
*
|
94 |
+
* @var array
|
95 |
+
*/
|
96 |
+
protected $_ignoredAttributes = array('website_id', 'store_id', 'default_billing', 'default_shipping');
|
97 |
+
|
98 |
+
/**
|
99 |
+
* Attributes with index (not label) value.
|
100 |
+
*
|
101 |
+
* @var array
|
102 |
+
*/
|
103 |
+
protected $_indexValueAttributes = array('group_id');
|
104 |
+
|
105 |
+
/**
|
106 |
+
* Validation failure message template definitions
|
107 |
+
*
|
108 |
+
* @var array
|
109 |
+
*/
|
110 |
+
protected $_messageTemplates = array(
|
111 |
+
self::ERROR_INVALID_WEBSITE => 'Invalid value in Website column (website does not exists?)',
|
112 |
+
self::ERROR_INVALID_EMAIL => 'E-mail is invalid',
|
113 |
+
self::ERROR_DUPLICATE_EMAIL_SITE => 'E-mail is duplicated in import file',
|
114 |
+
self::ERROR_EMAIL_IS_EMPTY => 'E-mail is not specified',
|
115 |
+
self::ERROR_ROW_IS_ORPHAN => 'Orphan rows that will be skipped due default row errors',
|
116 |
+
self::ERROR_VALUE_IS_REQUIRED => "Required attribute '%s' has an empty value",
|
117 |
+
self::ERROR_INVALID_STORE => 'Invalid value in Store column (store does not exists?)',
|
118 |
+
self::ERROR_EMAIL_SITE_NOT_FOUND => 'E-mail and website combination is not found',
|
119 |
+
self::ERROR_PASSWORD_LENGTH => 'Invalid password length'
|
120 |
+
);
|
121 |
+
|
122 |
+
/**
|
123 |
+
* Dry-runned orders information from import file.
|
124 |
+
*
|
125 |
+
* @var array
|
126 |
+
*/
|
127 |
+
protected $_newOrders = array();
|
128 |
+
|
129 |
+
/**
|
130 |
+
* Existing orders information. In form of:
|
131 |
+
*
|
132 |
+
* [customer e-mail] => array(
|
133 |
+
* [website code 1] => customer_id 1,
|
134 |
+
* [website code 2] => customer_id 2,
|
135 |
+
* ... => ... ,
|
136 |
+
* [website code n] => customer_id n,
|
137 |
+
* )
|
138 |
+
*
|
139 |
+
* @var array
|
140 |
+
*/
|
141 |
+
protected $_oldOrders = array();
|
142 |
+
|
143 |
+
/**
|
144 |
+
* Column names that holds values with particular meaning.
|
145 |
+
*
|
146 |
+
* @var array
|
147 |
+
*/
|
148 |
+
protected $_particularAttributes = array(self::COL_STORE);
|
149 |
+
|
150 |
+
public function isAttributeParticular($attrCode)
|
151 |
+
{
|
152 |
+
if (parent::isAttributeParticular($attrCode)) {
|
153 |
+
return true;
|
154 |
+
}
|
155 |
+
else if (strpos($attrCode, '_shipping_address_') === 0 ||
|
156 |
+
strpos($attrCode, '_billing_address_') === 0 ||
|
157 |
+
strpos($attrCode, '_item_') === 0 ||
|
158 |
+
strpos($attrCode, '_payment_') === 0 ||
|
159 |
+
strpos($attrCode, '_shipment_') === 0) {
|
160 |
+
return true;
|
161 |
+
}
|
162 |
+
else {
|
163 |
+
return false;
|
164 |
+
}
|
165 |
+
}
|
166 |
+
|
167 |
+
/**
|
168 |
+
* Permanent entity columns.
|
169 |
+
*
|
170 |
+
* @var array
|
171 |
+
*/
|
172 |
+
protected $_permanentAttributes = array(self::COL_EMAIL);
|
173 |
+
|
174 |
+
/**
|
175 |
+
* All stores code-ID pairs.
|
176 |
+
*
|
177 |
+
* @var array
|
178 |
+
*/
|
179 |
+
protected $_storeCodeToId = array();
|
180 |
+
|
181 |
+
/**
|
182 |
+
* Website code-to-ID
|
183 |
+
*
|
184 |
+
* @var array
|
185 |
+
*/
|
186 |
+
protected $_websiteCodeToId = array();
|
187 |
+
|
188 |
+
/**
|
189 |
+
* Website ID-to-code
|
190 |
+
*
|
191 |
+
* @var array
|
192 |
+
*/
|
193 |
+
protected $_websiteIdToCode = array();
|
194 |
+
|
195 |
+
/**
|
196 |
+
* Constructor.
|
197 |
+
*
|
198 |
+
* @return void
|
199 |
+
*/
|
200 |
+
public function __construct()
|
201 |
+
{
|
202 |
+
parent::__construct();
|
203 |
+
}
|
204 |
+
|
205 |
+
/**
|
206 |
+
* Save order data to DB.
|
207 |
+
*
|
208 |
+
* @throws Exception
|
209 |
+
* @return bool Result of operation.
|
210 |
+
*/
|
211 |
+
protected function _importData()
|
212 |
+
{
|
213 |
+
if (Mage_ImportExport_Model_Import::BEHAVIOR_DELETE == $this->getBehavior()) {
|
214 |
+
$this->_deleteOrders();
|
215 |
+
} else {
|
216 |
+
$this->_saveOrders();
|
217 |
+
}
|
218 |
+
return true;
|
219 |
+
}
|
220 |
+
|
221 |
+
/**
|
222 |
+
* Initialize stores hash.
|
223 |
+
*
|
224 |
+
* @return Mage_ImportExport_Model_Import_Entity_Customer
|
225 |
+
*/
|
226 |
+
protected function _initStores()
|
227 |
+
{
|
228 |
+
foreach (Mage::app()->getStores(true) as $store) {
|
229 |
+
$this->_storeCodeToId[$store->getCode()] = $store->getId();
|
230 |
+
}
|
231 |
+
return $this;
|
232 |
+
}
|
233 |
+
|
234 |
+
/**
|
235 |
+
* Initialize website values.
|
236 |
+
*
|
237 |
+
* @return Mage_ImportExport_Model_Import_Entity_Customer
|
238 |
+
*/
|
239 |
+
protected function _initWebsites()
|
240 |
+
{
|
241 |
+
/** @var $website Mage_Core_Model_Website */
|
242 |
+
foreach (Mage::app()->getWebsites(true) as $website) {
|
243 |
+
$this->_websiteCodeToId[$website->getCode()] = $website->getId();
|
244 |
+
$this->_websiteIdToCode[$website->getId()] = $website->getCode();
|
245 |
+
}
|
246 |
+
return $this;
|
247 |
+
}
|
248 |
+
|
249 |
+
/**
|
250 |
+
* Gather and save information about order entities.
|
251 |
+
*
|
252 |
+
* @return Mage_ImportExport_Model_Import_Entity_Order
|
253 |
+
*/
|
254 |
+
protected function _saveOrders()
|
255 |
+
{
|
256 |
+
$orderData = null;
|
257 |
+
|
258 |
+
while ($bunch = $this->_dataSourceModel->getNextBunch()) {
|
259 |
+
|
260 |
+
foreach ($bunch as $rowNum => $rowData) {
|
261 |
+
if (!$this->validateRow($rowData, $rowNum)) {
|
262 |
+
continue;
|
263 |
+
}
|
264 |
+
if (self::SCOPE_DEFAULT == $this->getRowScope($rowData)) {
|
265 |
+
if ($orderData) {
|
266 |
+
$this->_saveOrder($rowNum - 1, $orderData, $haveShippingAddress, $haveBillingAddress, $havePayment);
|
267 |
+
}
|
268 |
+
|
269 |
+
$orderData = array(
|
270 |
+
'group_id' => empty($rowData['group_id']) ? self::DEFAULT_GROUP_ID : $rowData['group_id'],
|
271 |
+
'store_id' => empty($rowData[self::COL_STORE])
|
272 |
+
? 0 : $this->_storeCodeToId[$rowData[self::COL_STORE]],
|
273 |
+
'created_at' => empty($rowData['created_at'])
|
274 |
+
? now() : $rowData['created_at'], //gmstrftime($strftimeFormat, strtotime($rowData['created_at'])),
|
275 |
+
'updated_at' => now(),
|
276 |
+
'items' => array(array()),
|
277 |
+
'shipments' => array(array())
|
278 |
+
);
|
279 |
+
|
280 |
+
$haveShippingAddress = false;
|
281 |
+
$haveBillingAddress = false;
|
282 |
+
$havePayment = false;
|
283 |
+
|
284 |
+
foreach ($rowData as $col => $val) {
|
285 |
+
if (strpos($col, '_item_') === 0) {
|
286 |
+
$orderData['items'][0][$col] = $val;
|
287 |
+
}
|
288 |
+
else if (strpos($col, '_shipment_') === 0) {
|
289 |
+
$orderData['shipments'][0][$col] = $val;
|
290 |
+
}
|
291 |
+
else {
|
292 |
+
if (strpos($col, '_shipping_address_') === 0) {
|
293 |
+
$haveShippingAddress = true;
|
294 |
+
}
|
295 |
+
else if (strpos($col, '_billing_address_') === 0) {
|
296 |
+
$haveBillingAddress = true;
|
297 |
+
}
|
298 |
+
else if (strpos($col, '_payment_') === 0) {
|
299 |
+
$havePayment = true;
|
300 |
+
}
|
301 |
+
$orderData[$col] = $val;
|
302 |
+
}
|
303 |
+
}
|
304 |
+
}
|
305 |
+
else {
|
306 |
+
$foundItem = false;
|
307 |
+
$foundShipment = false;
|
308 |
+
foreach ($rowData as $col => $val) {
|
309 |
+
if (strpos($col, '_item_') === 0) {
|
310 |
+
if (!$foundItem) {
|
311 |
+
$orderData['items'][] = array();
|
312 |
+
$itemIdx = count($orderData['items']) - 1;
|
313 |
+
$foundItem = true;
|
314 |
+
}
|
315 |
+
$orderData['items'][$itemIdx][$col] = $val;
|
316 |
+
}
|
317 |
+
else if (strpos($col, '_shipment_') === 0) {
|
318 |
+
if (!$foundShipment) {
|
319 |
+
$orderData['shipments'][] = array();
|
320 |
+
$shipmentIdx = count($orderData['shipments']) - 1;
|
321 |
+
$foundShipment = true;
|
322 |
+
}
|
323 |
+
$orderData['shipments'][$shipmentIdx][$col] = $val;
|
324 |
+
}
|
325 |
+
}
|
326 |
+
}
|
327 |
+
}
|
328 |
+
}
|
329 |
+
|
330 |
+
if ($orderData) {
|
331 |
+
$this->_saveOrder($rowNum, $orderData, $haveShippingAddress, $haveBillingAddress, $havePayment);
|
332 |
+
}
|
333 |
+
return $this;
|
334 |
+
}
|
335 |
+
|
336 |
+
protected function _saveOrder($rowNum, $orderData, $haveShippingAddress, $haveBillingAddress, $havePayment)
|
337 |
+
{
|
338 |
+
$quote = Mage::getModel('sales/quote');
|
339 |
+
$customer = Mage::getModel('customer/customer');
|
340 |
+
$transaction = Mage::getModel('core/resource_transaction');
|
341 |
+
|
342 |
+
$storeId = $orderData['store_id'];
|
343 |
+
$state = empty($orderData['state']) ? 'complete' : $orderData['state'];
|
344 |
+
$holdBeforeState = empty($orderData['hold_before_state']) ? '' : $orderData['hold_before_state'];
|
345 |
+
$holdBeforeStatus = empty($orderData['hold_before_status']) ? '' : $orderData['hold_before_status'];
|
346 |
+
$isVirtual = empty($orderData['is_virtual']) ? '0' : $orderData['is_virtual'];
|
347 |
+
$globalCurrencyCode = empty($orderData['global_currency_code']) ? 'USD' : $orderData['global_currency_code'];
|
348 |
+
$baseCurrencyCode = empty($orderData['base_currency_code']) ? 'USD' : $orderData['base_currency_code'];
|
349 |
+
$storeCurrencyCode = empty($orderData['store_currency_code']) ? 'USD' : $orderData['store_currency_code'];
|
350 |
+
$orderCurrencyCode = empty($orderData['order_currency_code']) ? 'USD' : $orderData['order_currency_code'];
|
351 |
+
|
352 |
+
$reservedOrderId = empty($orderData['increment_id']) ? Mage::getSingleton('eav/config')->getEntityType('order')->fetchNewIncrementId('store_id') : $orderData['increment_id'];
|
353 |
+
|
354 |
+
$order = Mage::getModel('sales/order')->loadByIncrementId($reservedOrderId);
|
355 |
+
if ($order->getId()) {
|
356 |
+
$this->addRowError('Duplicate order increment id found', $rowNum);
|
357 |
+
return false;
|
358 |
+
}
|
359 |
+
|
360 |
+
$order = Mage::getModel('sales/order')
|
361 |
+
->setIncrementId($reservedOrderId)
|
362 |
+
->setStoreId($storeId)
|
363 |
+
->setHoldBeforeState($holdBeforeState)
|
364 |
+
->setHoldBeforeStatus($holdBeforeStatus)
|
365 |
+
->setIsVirtual($isVirtual)
|
366 |
+
->setGlobal_currency_code($globalCurrencyCode)
|
367 |
+
->setBase_currency_code($baseCurrencyCode)
|
368 |
+
->setStore_currency_code($storeCurrencyCode)
|
369 |
+
->setOrder_currency_code($orderCurrencyCode)
|
370 |
+
->setCreatedAt($orderData['created_at']);
|
371 |
+
|
372 |
+
$email = $orderData['customer_email'];
|
373 |
+
$emailToLower = strtolower($email);
|
374 |
+
$customer->setWebsiteId(Mage::getModel('core/store')->load($storeId)->getWebsiteId());
|
375 |
+
if ($customer->loadByEmail($emailToLower))
|
376 |
+
$customerData = $customer->getData();
|
377 |
+
else
|
378 |
+
$customerData = NULL;
|
379 |
+
if ($customerData) {
|
380 |
+
$customerFirstname = empty($orderData['customer_firstname']) ? $customer->getFirstname() : $orderData['customer_firstname'];
|
381 |
+
$customerLastname = empty($orderData['customer_lastname']) ? $customer->getLastname() : $orderData['customer_lastname'];
|
382 |
+
$customerGroupId = empty($orderData['customer_group_id']) ? $customer->getGroupId() : $orderData['customer_group_id'];
|
383 |
+
$customerIsGuest = empty($orderData['customer_is_guest']) ? 0 : $orderData['customer_is_guest'];
|
384 |
+
}
|
385 |
+
else {
|
386 |
+
$customerFirstname = $orderData['customer_firstname'];
|
387 |
+
$customerLastname = $orderData['customer_lastname'];
|
388 |
+
$customerGroupId = $orderData['customer_group_id'];
|
389 |
+
$customerIsGuest = 1;
|
390 |
+
}
|
391 |
+
|
392 |
+
// set Customer data
|
393 |
+
$order->setCustomerEmail($email)
|
394 |
+
->setCustomerFirstname($customerFirstname)
|
395 |
+
->setCustomerLastname($customerLastname)
|
396 |
+
->setCustomerGroupId($customerGroupId)
|
397 |
+
->setCustomerIsGuest($customerIsGuest);
|
398 |
+
if ($customerData)
|
399 |
+
$order->setCustomerId($customer->getId());
|
400 |
+
|
401 |
+
// set Billing Address
|
402 |
+
//var_dump($rowNum);
|
403 |
+
//var_dump($orderData);
|
404 |
+
//var_dump($haveBillingAddress);
|
405 |
+
$billingAddress = NULL;
|
406 |
+
if (!$haveBillingAddress) {
|
407 |
+
$billing = $customer->getDefaultBillingAddress();
|
408 |
+
if ($billing) {
|
409 |
+
$billingAddress = Mage::getModel('sales/order_address')
|
410 |
+
->setStoreId($storeId)
|
411 |
+
->setAddressType(Mage_Sales_Model_Quote_Address::TYPE_BILLING)
|
412 |
+
->setCustomerAddressId($billing->getEntityId())
|
413 |
+
->setPrefix($billing->getPrefix())
|
414 |
+
->setFirstname($billing->getFirstname())
|
415 |
+
->setMiddlename($billing->getMiddlename())
|
416 |
+
->setLastname($billing->getLastname())
|
417 |
+
->setSuffix($billing->getSuffix())
|
418 |
+
->setCompany($billing->getCompany())
|
419 |
+
->setStreet($billing->getStreet())
|
420 |
+
->setCity($billing->getCity())
|
421 |
+
->setCountryId($billing->getCountryId())
|
422 |
+
->setRegion($billing->getRegion())
|
423 |
+
->setPostcode($billing->getPostcode())
|
424 |
+
->setTelephone($billing->getTelephone())
|
425 |
+
->setFax($billing->getFax());
|
426 |
+
}
|
427 |
+
}
|
428 |
+
else {
|
429 |
+
$billingAddressPrefix = empty($orderData['_billing_address_prefix']) ? '' : $orderData['_billing_address_prefix'];
|
430 |
+
$billingAddressFirstname = empty($orderData['_billing_address_firstname']) ? '' : $orderData['_billing_address_firstname'];
|
431 |
+
$billingAddressMiddlename = empty($orderData['_billing_address_middlename']) ? '' : $orderData['_billing_address_middlename'];
|
432 |
+
$billingAddressLastname = empty($orderData['_billing_address_lastname']) ? '' : $orderData['_billing_address_lastname'];
|
433 |
+
$billingAddressSuffix = empty($orderData['_billing_address_suffix']) ? '' : $orderData['_billing_address_suffix'];
|
434 |
+
$billingAddressCompany = empty($orderData['_billing_address_company']) ? '' : $orderData['_billing_address_company'];
|
435 |
+
$billingAddressStreet = empty($orderData['_billing_address_street']) ? '' : $orderData['_billing_address_street'];
|
436 |
+
$billingAddressCity = empty($orderData['_billing_address_city']) ? '' : $orderData['_billing_address_city'];
|
437 |
+
$billingAddressCountryId = empty($orderData['_billing_address_country_id']) ? '' : $orderData['_billing_address_country_id'];
|
438 |
+
$billingAddressRegion = empty($orderData['_billing_address_region']) ? '' : $orderData['_billing_address_region'];
|
439 |
+
$billingAddressPostcode = empty($orderData['_billing_address_postcode']) ? '' : $orderData['_billing_address_postcode'];
|
440 |
+
$billingAddressTelephone = empty($orderData['_billing_address_telephone']) ? '' : $orderData['_billing_address_telephone'];
|
441 |
+
$billingAddressFax = empty($orderData['_billing_address_fax']) ? '' : $orderData['_billing_address_fax'];
|
442 |
+
$billingAddress = Mage::getModel('sales/order_address')
|
443 |
+
->setStoreId($storeId)
|
444 |
+
->setAddressType(Mage_Sales_Model_Quote_Address::TYPE_BILLING)
|
445 |
+
->setPrefix($billingAddressPrefix)
|
446 |
+
->setFirstname($billingAddressFirstname)
|
447 |
+
->setMiddlename($billingAddressMiddlename)
|
448 |
+
->setLastname($billingAddressLastname)
|
449 |
+
->setSuffix($billingAddressSuffix)
|
450 |
+
->setCompany($billingAddressCompany)
|
451 |
+
->setStreet($billingAddressStreet)
|
452 |
+
->setCity($billingAddressCity)
|
453 |
+
->setCountryId($billingAddressCountryId)
|
454 |
+
->setRegion($billingAddressRegion)
|
455 |
+
->setPostcode($billingAddressPostcode)
|
456 |
+
->setTelephone($billingAddressTelephone)
|
457 |
+
->setFax($billingAddressFax);
|
458 |
+
}
|
459 |
+
if ($billingAddress)
|
460 |
+
$order->setBillingAddress($billingAddress);
|
461 |
+
|
462 |
+
// set Shipping Address
|
463 |
+
$shippingAddress = NULL;
|
464 |
+
if (!$haveShippingAddress) {
|
465 |
+
$shipping = $customer->getDefaultShippingAddress();
|
466 |
+
if ($shipping) {
|
467 |
+
$shippingAddress = Mage::getModel('sales/order_address')
|
468 |
+
->setStoreId($storeId)
|
469 |
+
->setAddressType(Mage_Sales_Model_Quote_Address::TYPE_SHIPPING)
|
470 |
+
->setCustomerAddressId($shipping->getEntityId())
|
471 |
+
->setPrefix($shipping->getPrefix())
|
472 |
+
->setFirstname($shipping->getFirstname())
|
473 |
+
->setMiddlename($shipping->getMiddlename())
|
474 |
+
->setLastname($shipping->getLastname())
|
475 |
+
->setSuffix($shipping->getSuffix())
|
476 |
+
->setCompany($shipping->getCompany())
|
477 |
+
->setStreet($shipping->getStreet())
|
478 |
+
->setCity($shipping->getCity())
|
479 |
+
->setCountryId($shipping->getCountryId())
|
480 |
+
->setRegion($shipping->getRegion())
|
481 |
+
->setPostcode($shipping->getPostcode())
|
482 |
+
->setTelephone($shipping->getTelephone())
|
483 |
+
->setFax($shipping->getFax());
|
484 |
+
}
|
485 |
+
}
|
486 |
+
else {
|
487 |
+
$shippingAddressPrefix = empty($orderData['_shipping_address_prefix']) ? '' : $orderData['_shipping_address_prefix'];
|
488 |
+
$shippingAddressFirstname = empty($orderData['_shipping_address_firstname']) ? '' : $orderData['_shipping_address_firstname'];
|
489 |
+
$shippingAddressMiddlename = empty($orderData['_shipping_address_middlename']) ? '' : $orderData['_shipping_address_middlename'];
|
490 |
+
$shippingAddressLastname = empty($orderData['_shipping_address_lastname']) ? '' : $orderData['_shipping_address_lastname'];
|
491 |
+
$shippingAddressSuffix = empty($orderData['_shipping_address_suffix']) ? '' : $orderData['_shipping_address_suffix'];
|
492 |
+
$shippingAddressCompany = empty($orderData['_shipping_address_company']) ? '' : $orderData['_shipping_address_company'];
|
493 |
+
$shippingAddressStreet = empty($orderData['_shipping_address_street']) ? '' : $orderData['_shipping_address_street'];
|
494 |
+
$shippingAddressCity = empty($orderData['_shipping_address_city']) ? '' : $orderData['_shipping_address_city'];
|
495 |
+
$shippingAddressCountryId = empty($orderData['_shipping_address_country_id']) ? '' : $orderData['_shipping_address_country_id'];
|
496 |
+
$shippingAddressRegion = empty($orderData['_shipping_address_region']) ? '' : $orderData['_shipping_address_region'];
|
497 |
+
$shippingAddressPostcode = empty($orderData['_shipping_address_postcode']) ? '' : $orderData['_shipping_address_postcode'];
|
498 |
+
$shippingAddressTelephone = empty($orderData['_shipping_address_telephone']) ? '' : $orderData['_shipping_address_telephone'];
|
499 |
+
$shippingAddressFax = empty($orderData['_shipping_address_fax']) ? '' : $orderData['_shipping_address_fax'];
|
500 |
+
$shippingAddress = Mage::getModel('sales/order_address')
|
501 |
+
->setStoreId($storeId)
|
502 |
+
->setAddressType(Mage_Sales_Model_Quote_Address::TYPE_SHIPPING)
|
503 |
+
->setPrefix($shippingAddressPrefix)
|
504 |
+
->setFirstname($shippingAddressFirstname)
|
505 |
+
->setMiddlename($shippingAddressMiddlename)
|
506 |
+
->setLastname($shippingAddressLastname)
|
507 |
+
->setSuffix($shippingAddressSuffix)
|
508 |
+
->setCompany($shippingAddressCompany)
|
509 |
+
->setStreet($shippingAddressStreet)
|
510 |
+
->setCity($shippingAddressCity)
|
511 |
+
->setCountryId($shippingAddressCountryId)
|
512 |
+
->setRegion($shippingAddressRegion)
|
513 |
+
->setPostcode($shippingAddressPostcode)
|
514 |
+
->setTelephone($shippingAddressTelephone)
|
515 |
+
->setFax($shippingAddressFax);
|
516 |
+
}
|
517 |
+
if (!$isVirtual) {
|
518 |
+
if ($shippingAddress)
|
519 |
+
$order->setShippingAddress($shippingAddress);
|
520 |
+
$shippingMethod = empty($orderData['shipping_method']) ? 'flatrate_flatrate' : $orderData['shipping_method'];
|
521 |
+
$order->setShipping_method($shippingMethod)
|
522 |
+
->setShippingDescription($shippingMethod);
|
523 |
+
}
|
524 |
+
|
525 |
+
$orderPayment = Mage::getModel('sales/order_payment')
|
526 |
+
->setStoreId($storeId)
|
527 |
+
->setCustomerPaymentId(0)
|
528 |
+
->setMethod('checkmo')
|
529 |
+
->setPo_number(' - ');
|
530 |
+
$order->setPayment($orderPayment);
|
531 |
+
|
532 |
+
foreach ($orderData['items'] as $item) {
|
533 |
+
$orderItem = Mage::getModel('sales/order_item')
|
534 |
+
->setStoreId($storeId)
|
535 |
+
->setQuoteItemId(0)
|
536 |
+
->setQuoteParentItemId(NULL)
|
537 |
+
->setSku($item['_item_sku'])
|
538 |
+
->setProductType($item['_item_type'])
|
539 |
+
->setProductOptions(unserialize($item['_item_option']))
|
540 |
+
->setQtyBackordered(NULL)
|
541 |
+
->setTotalQtyOrdered($item['_item_qty_ordered'])
|
542 |
+
->setQtyOrdered($item['_item_qty_ordered'])
|
543 |
+
->setName($item['_item_name'])
|
544 |
+
->setPrice($item['_item_price'])
|
545 |
+
->setBasePrice($item['_item_base_price'])
|
546 |
+
->setOriginalPrice($item['_item_original_price'])
|
547 |
+
->setBaseOriginalPrice($item['_item_base_original_price'])
|
548 |
+
->setRowWeight($item['_item_row_weight'])
|
549 |
+
->setPriceInclTax($item['_item_price_incl_tax'])
|
550 |
+
->setBasePriceInclTax($item['_item_base_price_incl_tax'])
|
551 |
+
->setTaxAmount($item['_item_tax_amount'])
|
552 |
+
->setBaseTaxAmount($item['_item_base_tax_amount'])
|
553 |
+
->setTaxPercent($item['_item_tax_percent'])
|
554 |
+
->setDiscountAmount($item['_item_discount'])
|
555 |
+
->setBaseDiscountAmount($item['_item_base_discount'])
|
556 |
+
->setDiscountPercent($item['_item_discount_percent'])
|
557 |
+
->setRowTotal($item['_item_row_total'])
|
558 |
+
->setBaseRowTotal($item['_item_base_row_total']);
|
559 |
+
|
560 |
+
if ($item['_item_parent_item_id'])
|
561 |
+
$orderItem->setParentItemId($item['_item_parent_item_id']);
|
562 |
+
|
563 |
+
$order->addItem($orderItem);
|
564 |
+
}
|
565 |
+
|
566 |
+
$order->setShippingAmount($orderData['shipping_amount']);
|
567 |
+
$order->setBaseShippingAmount($orderData['base_shipping_amount']);
|
568 |
+
|
569 |
+
//Apply Discount
|
570 |
+
$order->setBaseDiscountAmount($orderData['base_discount_amount']);
|
571 |
+
$order->setDiscountAmount($orderData['discount_amount']);
|
572 |
+
|
573 |
+
//Apply Tax
|
574 |
+
$order->setBaseTaxAmount($orderData['base_tax_amount']);
|
575 |
+
$order->setTaxAmount($orderData['tax_amount']);
|
576 |
+
|
577 |
+
$order->setSubtotal($orderData['subtotal'])
|
578 |
+
->setBaseSubtotal($orderData['base_subtotal'])
|
579 |
+
->setGrandTotal($orderData['grand_total'])
|
580 |
+
->setBaseGrandTotal($orderData['base_grand_total'])
|
581 |
+
->setShippingTaxAmount($orderData['shipping_tax_amount'])
|
582 |
+
->setBaseShippingTaxAmount($orderData['base_shipping_tax_amount'])
|
583 |
+
->setBaseToGlobalRate($orderData['base_to_global_rate'])
|
584 |
+
->setBaseToOrderRate($orderData['base_to_order_rate'])
|
585 |
+
->setStoreToBaseRate($orderData['store_to_base_rate'])
|
586 |
+
->setStoreToOrderRate($orderData['store_to_order_rate'])
|
587 |
+
->setSubtotalInclTax($orderData['subtotal_incl_tax'])
|
588 |
+
->setBaseSubtotalInclTax($orderData['base_subtotal_incl_tax'])
|
589 |
+
->setCouponCode($orderData['coupon_code'])
|
590 |
+
->setDiscountDescription($orderData['coupon_code'])
|
591 |
+
->setShippingInclTax($orderData['shipping_incl_tax'])
|
592 |
+
->setBaseShippingInclTax($orderData['base_shipping_incl_tax'])
|
593 |
+
->setTotalQtyOrdered($orderData['total_qty_ordered'])
|
594 |
+
->setRemoteIp($orderData['remote_ip']);
|
595 |
+
|
596 |
+
$transaction->addObject($order);
|
597 |
+
$transaction->addCommitCallback(array($order, 'place'));
|
598 |
+
$transaction->addCommitCallback(array($order, 'save'));
|
599 |
+
|
600 |
+
if ($transaction->save()) {
|
601 |
+
$order->setData("state", $state);
|
602 |
+
$status = $order->getConfig()->getStateDefaultStatus($state);
|
603 |
+
$order->setStatus($status);
|
604 |
+
$history = $order->addStatusHistoryComment('', false);
|
605 |
+
$history->setIsCustomerNotified(null);
|
606 |
+
$order->save();
|
607 |
+
return true;
|
608 |
+
}
|
609 |
+
else {
|
610 |
+
return false;
|
611 |
+
}
|
612 |
+
}
|
613 |
+
|
614 |
+
/**
|
615 |
+
* EAV entity type code getter.
|
616 |
+
*
|
617 |
+
* @abstract
|
618 |
+
* @return string
|
619 |
+
*/
|
620 |
+
public function getEntityTypeCode()
|
621 |
+
{
|
622 |
+
return 'order';
|
623 |
+
}
|
624 |
+
|
625 |
+
/**
|
626 |
+
* Obtain scope of the row from row data.
|
627 |
+
*
|
628 |
+
* @param array $rowData
|
629 |
+
* @return int
|
630 |
+
*/
|
631 |
+
public function getRowScope(array $rowData)
|
632 |
+
{
|
633 |
+
return strlen(trim($rowData[self::COL_EMAIL])) ? self::SCOPE_DEFAULT : self::SCOPE_ADDRESS;
|
634 |
+
}
|
635 |
+
|
636 |
+
/**
|
637 |
+
* Validate data row.
|
638 |
+
*
|
639 |
+
* @param array $rowData
|
640 |
+
* @param int $rowNum
|
641 |
+
* @return boolean
|
642 |
+
*/
|
643 |
+
public function validateRow(array $rowData, $rowNum)
|
644 |
+
{
|
645 |
+
static $email = null; // e-mail is remembered through all customer rows
|
646 |
+
static $website = null; // website is remembered through all customer rows
|
647 |
+
|
648 |
+
if (isset($this->_validatedRows[$rowNum])) { // check that row is already validated
|
649 |
+
return !isset($this->_invalidRows[$rowNum]);
|
650 |
+
}
|
651 |
+
$this->_validatedRows[$rowNum] = true;
|
652 |
+
|
653 |
+
$rowScope = $this->getRowScope($rowData);
|
654 |
+
|
655 |
+
if (self::SCOPE_DEFAULT == $rowScope) {
|
656 |
+
$this->_processedEntitiesCount ++;
|
657 |
+
}
|
658 |
+
|
659 |
+
return !isset($this->_invalidRows[$rowNum]);
|
660 |
+
}
|
661 |
+
}
|
app/code/community/FarApp/Connector/Model/Import/Entity/Product.php
ADDED
@@ -0,0 +1,185 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
*/
|
4 |
+
class FarApp_Connector_Model_Import_Entity_Product extends Mage_ImportExport_Model_Import_Entity_Product
|
5 |
+
{
|
6 |
+
public function __construct()
|
7 |
+
{
|
8 |
+
parent::__construct();
|
9 |
+
$this->_errorsLimit = 1000000000;
|
10 |
+
}
|
11 |
+
|
12 |
+
protected function _createAttributeOption($attrType, $attrCode, array $rowData, $rowNum)
|
13 |
+
{
|
14 |
+
/** @var $attribute Mage_Eav_Model_Entity_Attribute */
|
15 |
+
$attribute = Mage::getSingleton('catalog/product')->getResource()->getAttribute($attrCode);
|
16 |
+
if (!is_object($attribute)) {
|
17 |
+
$this->addRowError(Mage::helper('importexport')->__('Attribute ' . $attrCode . ' not found.'), $rowNum);
|
18 |
+
return false;
|
19 |
+
}
|
20 |
+
if ($attrType == 'select' && $attribute->getSourceModel() != 'eav/entity_attribute_source_table') {
|
21 |
+
$this->addRowError(Mage::helper('importexport')->__('Attribute ' . $attrCode . ' is no dropdown attribute.'), $rowNum);
|
22 |
+
return false;
|
23 |
+
}
|
24 |
+
elseif ($attrType == 'multiselect' && $attribute->getBackendModel() != 'eav/entity_attribute_backend_array') {
|
25 |
+
$this->addRowError(Mage::helper('importexport')->__('Attribute ' . $attrCode . ' is no multiselect attribute.'), $rowNum);
|
26 |
+
return false;
|
27 |
+
}
|
28 |
+
|
29 |
+
$option = array(
|
30 |
+
'value' => array(
|
31 |
+
array('0' => $rowData[$attrCode])
|
32 |
+
),
|
33 |
+
'order' => array(0),
|
34 |
+
'delete' => array('')
|
35 |
+
);
|
36 |
+
|
37 |
+
$attribute->setOption($option);
|
38 |
+
$attribute->save();
|
39 |
+
|
40 |
+
$this->_initTypeModels();
|
41 |
+
|
42 |
+
return true;
|
43 |
+
}
|
44 |
+
|
45 |
+
public function isAttributeValid($attrCode, array $attrParams, array $rowData, $rowNum)
|
46 |
+
{
|
47 |
+
switch ($attrParams['type']) {
|
48 |
+
case 'select':
|
49 |
+
case 'multiselect':
|
50 |
+
$valid = isset($attrParams['options'][strtolower($rowData[$attrCode])]);
|
51 |
+
if (!$valid) {
|
52 |
+
$valid = $this->_createAttributeOption($attrParams['type'], $attrCode, $rowData, $rowNum);
|
53 |
+
if ($valid) {
|
54 |
+
$attrParams['options'][] = strtolower($rowData[$attrCode]);
|
55 |
+
}
|
56 |
+
} elseif (!empty($attrParams['is_unique'])) {
|
57 |
+
if (isset($this->_uniqueAttributes[$attrCode][$rowData[$attrCode]])) {
|
58 |
+
$this->addRowError(Mage::helper('importexport')->__("Duplicate Unique Attribute for '%s'"), $rowNum, $attrCode);
|
59 |
+
return false;
|
60 |
+
}
|
61 |
+
$this->_uniqueAttributes[$attrCode][$rowData[$attrCode]] = true;
|
62 |
+
}
|
63 |
+
break;
|
64 |
+
default:
|
65 |
+
$valid = parent::isAttributeValid($attrCode, $attrParams, $rowData, $rowNum);
|
66 |
+
break;
|
67 |
+
}
|
68 |
+
|
69 |
+
return (bool) $valid;
|
70 |
+
}
|
71 |
+
|
72 |
+
protected function _uploadMediaFiles($fileName)
|
73 |
+
{
|
74 |
+
$fullTempPath = $this->_getUploader()->getTmpDir() . DS . basename($fileName);
|
75 |
+
$fullDestPath = Mage_Core_Model_File_Uploader::getDispretionPath(basename($fileName)) . DS . basename($fileName);
|
76 |
+
if (!is_file($fullTempPath) && !is_file($fullDestPath)) {
|
77 |
+
if (strpos($fileName, 'http') === 0 && strpos($fileName, '://') !== false) {
|
78 |
+
try {
|
79 |
+
$dir = $this->_getUploader()->getTmpDir();
|
80 |
+
if (!is_dir($dir)) {
|
81 |
+
mkdir($dir);
|
82 |
+
}
|
83 |
+
$fileHandle = fopen($dir . DS . basename($fileName), 'w+');
|
84 |
+
$ch = curl_init($fileName);
|
85 |
+
curl_setopt($ch, CURLOPT_TIMEOUT, 50);
|
86 |
+
curl_setopt($ch, CURLOPT_FILE, $fileHandle);
|
87 |
+
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
|
88 |
+
curl_exec($ch);
|
89 |
+
curl_close($ch);
|
90 |
+
fclose($fileHandle);
|
91 |
+
} catch (Exception $e) {
|
92 |
+
return '';
|
93 |
+
}
|
94 |
+
}
|
95 |
+
return parent::_uploadMediaFiles(basename($fileName));
|
96 |
+
}
|
97 |
+
else {
|
98 |
+
return $fullDestPath;
|
99 |
+
}
|
100 |
+
}
|
101 |
+
|
102 |
+
protected function _saveStockItem()
|
103 |
+
{
|
104 |
+
$defaultStockData = array(
|
105 |
+
'manage_stock' => 1,
|
106 |
+
'use_config_manage_stock' => 1,
|
107 |
+
'qty' => 0,
|
108 |
+
'min_qty' => 0,
|
109 |
+
'use_config_min_qty' => 1,
|
110 |
+
'min_sale_qty' => 1,
|
111 |
+
'use_config_min_sale_qty' => 1,
|
112 |
+
'max_sale_qty' => 10000,
|
113 |
+
'use_config_max_sale_qty' => 1,
|
114 |
+
'is_qty_decimal' => 0,
|
115 |
+
'backorders' => 0,
|
116 |
+
'use_config_backorders' => 1,
|
117 |
+
'notify_stock_qty' => 1,
|
118 |
+
'use_config_notify_stock_qty' => 1,
|
119 |
+
'enable_qty_increments' => 0,
|
120 |
+
'use_config_enable_qty_inc' => 1,
|
121 |
+
'qty_increments' => 0,
|
122 |
+
'use_config_qty_increments' => 1,
|
123 |
+
'is_in_stock' => 0,
|
124 |
+
'low_stock_date' => null,
|
125 |
+
'stock_status_changed_auto' => 0,
|
126 |
+
'is_decimal_divided' => 0
|
127 |
+
);
|
128 |
+
|
129 |
+
$entityTable = Mage::getResourceModel('cataloginventory/stock_item')->getMainTable();
|
130 |
+
$helper = Mage::helper('catalogInventory');
|
131 |
+
|
132 |
+
while ($bunch = $this->_dataSourceModel->getNextBunch()) {
|
133 |
+
$stockData = array();
|
134 |
+
|
135 |
+
// Format bunch to stock data rows
|
136 |
+
foreach ($bunch as $rowNum => $rowData) {
|
137 |
+
if (!$this->isRowAllowedToImport($rowData, $rowNum)) {
|
138 |
+
continue;
|
139 |
+
}
|
140 |
+
// only SCOPE_DEFAULT can contain stock data
|
141 |
+
if (self::SCOPE_DEFAULT != $this->getRowScope($rowData)) {
|
142 |
+
continue;
|
143 |
+
}
|
144 |
+
|
145 |
+
$row = array();
|
146 |
+
|
147 |
+
$row['product_id'] = $this->_newSku[$rowData[self::COL_SKU]]['entity_id'];
|
148 |
+
$row['stock_id'] = 1;
|
149 |
+
|
150 |
+
/** @var $stockItem Mage_CatalogInventory_Model_Stock_Item */
|
151 |
+
$stockItem = Mage::getModel('cataloginventory/stock_item');
|
152 |
+
$stockItem->loadByProduct($row['product_id']);
|
153 |
+
$existStockData = $stockItem->getData();
|
154 |
+
|
155 |
+
$row = array_merge(
|
156 |
+
$defaultStockData,
|
157 |
+
array_intersect_key($existStockData, $defaultStockData),
|
158 |
+
array_intersect_key($rowData, $defaultStockData),
|
159 |
+
$row
|
160 |
+
);
|
161 |
+
|
162 |
+
$stockItem->setData($row);
|
163 |
+
|
164 |
+
if ($helper->isQty($this->_newSku[$rowData[self::COL_SKU]]['type_id'])) {
|
165 |
+
if ($stockItem->verifyNotification()) {
|
166 |
+
$stockItem->setLowStockDate(Mage::app()->getLocale()
|
167 |
+
->date(null, null, null, false)
|
168 |
+
->toString(Varien_Date::DATETIME_INTERNAL_FORMAT)
|
169 |
+
);
|
170 |
+
}
|
171 |
+
$stockItem->setStockStatusChangedAutomatically((int) !$stockItem->verifyStock());
|
172 |
+
} else {
|
173 |
+
$stockItem->setQty(0);
|
174 |
+
}
|
175 |
+
$stockData[] = $stockItem->unsetOldData()->getData();
|
176 |
+
}
|
177 |
+
|
178 |
+
// Insert rows
|
179 |
+
if ($stockData) {
|
180 |
+
$this->_connection->insertOnDuplicate($entityTable, $stockData);
|
181 |
+
}
|
182 |
+
}
|
183 |
+
return $this;
|
184 |
+
}
|
185 |
+
}
|
app/code/community/FarApp/Connector/Model/Import/Entity/minVersion2.php
ADDED
@@ -0,0 +1,3144 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|