Skip to content

Commit 2fc52f6

Browse files
committed
u20230723
1 parent 56582c1 commit 2fc52f6

File tree

7 files changed

+177
-9
lines changed

7 files changed

+177
-9
lines changed

Controller/Adminhtml/Migration.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,9 +65,10 @@ protected function getMigrationApp()
6565
$config = array();
6666
$config['user_id'] = $user->getId();
6767
$config['upload_dir'] = $library_folder . '/files';
68-
$config['upload_location'] = ltrim($this->helper->getLibraryLocation()) . '/files';
68+
$config['upload_location'] = ltrim($this->helper->getLibraryLocation(), '/') . '/files';
6969
$config['log_dir'] = $library_folder . '/log';
7070
$app->setConfig($config);
71+
$app->setPluginManager($this->helper);
7172
$this->migrationApp = $app;
7273
return $this->migrationApp;
7374
}

Controller/Adminhtml/Migration/Process.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
namespace D2DSoft\DataMigration\Controller\Adminhtml\Migration;
2020

2121
use D2DSoft\DataMigration\Controller\Adminhtml\Migration;
22-
use Zend_Json_Encoder;
2322

2423
class Process extends Migration
2524
{
@@ -65,11 +64,16 @@ public function download(){
6564

6665
protected function responseJson($data)
6766
{
67+
if(class_exists('\Zend_Json_Encoder')){
68+
$json_data = \Zend_Json_Encoder::encode($data);
69+
} else {
70+
$json_data = \Laminas\Json\Json::encode($data);
71+
}
6872
$this->getResponse()
6973
->clearHeaders()
7074
->setHeader('Content-type', 'application/json' ,true);
7175
$this->getResponse()
72-
->setBody(Zend_Json_Encoder::encode($data));
76+
->setBody($json_data);
7377
return;
7478
}
7579
}

Controller/Adminhtml/Migration/Setup.php

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,14 +49,29 @@ protected function downloadAndExtraLibrary($license = '')
4949
$data = array(
5050
'license' => $license
5151
);
52-
$client = new \Zend_Http_Client();
52+
if(class_exists('\Zend_Http_Client')){
53+
$client = new \Zend_Http_Client();
54+
$method = \Zend_Http_Client::POST;
55+
} else {
56+
$client = new \Laminas\Http\Client();
57+
$method = \Laminas\Http\Request::METHOD_POST;
58+
}
59+
if(class_exists('\Zend_Json_Encoder')){
60+
$json_data = \Zend_Json_Encoder::encode($data);
61+
} else {
62+
$json_data = \Laminas\Json\Json::encode($data);
63+
}
5364
$client->setUri($url)
5465
->setStream($tmp_path)
55-
->setMethod(\Zend_Http_Client::POST)
56-
->setRawData(json_encode($data));
66+
->setMethod($method)
67+
->setRawData($json_data);
5768
try {
5869
$client->request()->getBody();
59-
$zip = new \Zend_Filter_Compress_Zip();
70+
if(class_exists('\Zend_Filter_Compress_Zip')){
71+
$zip = new \Zend_Filter_Compress_Zip();
72+
} else {
73+
$zip = new \Laminas\Filter\Compress\Zip();
74+
}
6075
$zip->setTarget($library_folder);
6176
$zip->decompress($tmp_path);
6277
@unlink($tmp_path);

Helper/Data.php

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020

2121
use Magento\Framework\App\Helper\AbstractHelper;
2222
use Magento\Framework\Filesystem\DirectoryList;
23+
use Magento\Framework\App\Filesystem\DirectoryList as AppDirectoryList;
2324
use Magento\Framework\App\Helper\Context;
2425

2526
class Data extends AbstractHelper
@@ -37,12 +38,14 @@ public function __construct(
3738
}
3839

3940
public function getLibraryLocation(){
40-
return '/d2dsoft/datamigration';
41+
$config = $this->directoryList->getDefaultConfig();
42+
$media_path = isset($config[AppDirectoryList::MEDIA]['path']) ? $config[AppDirectoryList::MEDIA]['path'] : 'pub/media';
43+
return '/' . $media_path . '/d2dsoft/datamigration';
4144
}
4245

4346
public function getLibraryFolder(){
4447
$location = $this->getLibraryLocation();
45-
$folder = $this->directoryList->getPath('media') . $location;
48+
$folder = rtrim($this->directoryList->getRoot(), '\\/') . $location;
4649
return $folder;
4750
}
4851

@@ -55,4 +58,13 @@ public function isInstallLibrary(){
5558
$init_file = $this->getInitLibrary();
5659
return file_exists($init_file);
5760
}
61+
62+
public function getPlugin($name){
63+
$class_name = '\D2DSoft\DataMigration\Plugin\\' . $name;
64+
if(!class_exists($class_name)){
65+
return false;
66+
}
67+
$class = new $class_name();
68+
return $class;
69+
}
5870
}

Plugin/Excel.php

Lines changed: 131 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,131 @@
1+
<?php
2+
3+
/**
4+
* D2dSoft
5+
*
6+
* NOTICE OF LICENSE
7+
*
8+
* This source file is subject to the Academic Free License (AFL v3.0) that is bundled with this package in the file LICENSE.txt.
9+
* It is also available through the world-wide-web at this URL: https://d2d-soft.com/license/AFL.txt
10+
*
11+
* DISCLAIMER
12+
* Do not edit or add to this file if you wish to upgrade this extension/plugin/module to newer version in the future.
13+
*
14+
* @author D2dSoft Developers <developer@d2d-soft.com>
15+
* @copyright Copyright (c) 2021 D2dSoft (https://d2d-soft.com)
16+
* @license https://d2d-soft.com/license/AFL.txt
17+
*/
18+
19+
namespace D2DSoft\DataMigration\Plugin;
20+
21+
class Excel
22+
{
23+
public function readFile($file_path, $start, $limit = 10, $total = false, $lower_key = false, $sheet_index = 0){
24+
if(!class_exists('\PhpOffice\PhpSpreadsheet\Spreadsheet')){
25+
return array(
26+
'status' => 'error',
27+
'message' => 'The Excel reader does not exist.'
28+
);
29+
}
30+
return $this->readFileBySpreadsheet($file_path, $start, $limit, $total, $lower_key, $sheet_index);
31+
}
32+
33+
public function readFileBySpreadsheet($file_path, $start, $limit = 10, $total = false, $lower_key = false, $sheet_index = 0){
34+
if(!is_file($file_path)){
35+
return array(
36+
'status' => 'error',
37+
'message' => 'The file is not exist'
38+
);
39+
}
40+
try {
41+
/* @var $excelReader \PhpOffice\PhpSpreadsheet\Reader\Xlsx */
42+
$excelReader = \PhpOffice\PhpSpreadsheet\IOFactory::createReaderForFile($file_path);
43+
$spreadsheet = $excelReader->load($file_path);
44+
/* @var $sheet \PhpOffice\PhpSpreadsheet\Worksheet\Worksheet */
45+
$sheet = $spreadsheet->getSheet($sheet_index);
46+
$highestRow = $sheet->getHighestRow();
47+
$highestColumn = $sheet->getHighestColumn();
48+
$finish = false;
49+
$count = 0;
50+
$end = $start + $limit;
51+
$headers = array();
52+
$data = array();
53+
for ($row = 1; $row <= $highestRow; $row++){
54+
if($total && $count > $total){
55+
$finish = true;
56+
break ;
57+
}
58+
if($count > $end){
59+
break ;
60+
}
61+
if ($count == 0 || ($start < $count && $count <= $end)) {
62+
$rowData = $sheet->rangeToArray('A' . $row . ':' . $highestColumn . $row,
63+
NULL,
64+
TRUE,
65+
FALSE);
66+
$rowData = $rowData[0];
67+
if($count == 0){
68+
$headers = $rowData;
69+
if($lower_key){
70+
$headers = array_map('strtolower', $headers);
71+
}
72+
} else {
73+
$data[] = $this->buildItem($headers, $rowData);
74+
}
75+
}
76+
$count++;
77+
}
78+
if(!$finish && ($count - 1) < $end){
79+
$finish = true;
80+
}
81+
return array(
82+
'status' => 'success',
83+
'headers' => $headers,
84+
'data' => $data,
85+
'count' => $end,
86+
'finish' => $finish
87+
);
88+
} catch (\Exception $e){
89+
return array(
90+
'status' => 'error',
91+
'message' => $e->getMessage()
92+
);
93+
}
94+
}
95+
96+
protected function buildColumnIndex($max_column){
97+
$start = 'A';
98+
$position = 0;
99+
$run = true;
100+
$data = array(
101+
$start => $position,
102+
);
103+
if($start == $max_column){
104+
return $data;
105+
}
106+
while($run){
107+
$start++;
108+
$position++;
109+
$data[$start] = $position;
110+
if($start == $max_column){
111+
$run = false;
112+
}
113+
}
114+
return $data;
115+
}
116+
117+
protected function buildItem($headers, $row){
118+
if(!$row){
119+
return array();
120+
}
121+
$row_value = array_filter($row);
122+
if(!$row_value || empty($row_value)){
123+
return array();
124+
}
125+
$data = array();
126+
foreach ($headers as $key => $title_name){
127+
$data[$title_name] = (isset($row[$key]))? $row[$key] : null;
128+
}
129+
return $data;
130+
}
131+
}

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
- [BigCommerce to Magento Migration](https://d2d-soft.com/magento-migration/415-1677-bigcommerce-to-magento-2-migration-extension.html#/72-entities-1000)
77
- [CS-Cart to Magento Migration](https://d2d-soft.com/magento-migration/326-1397-cs-cart-to-magento-2-migration-extension.html)
88
- [CubeCart to Magento Migration](https://d2d-soft.com/magento-migration/46-148-cubecart-to-magento-2-migration-extension.html)
9+
- [EKM Commerce to Magento Migration](https://d2d-soft.com/magento-migration/825-7800-ekm-to-magento-2-migration-extension.html#/72-entities-1000)
910
- [Drupal Commerce to Magento Migration](https://d2d-soft.com/magento-migration/360-drupal-commerce-to-magento-migration-service.html)
1011
- [HikaShop to Magento Migration](https://d2d-soft.com/magento-migration/450-1847-hikashop-to-magento-2-migration-extension.html#/72-entities-1000)
1112
- [J2Store to Magento Migration](https://d2d-soft.com/magento-migration/493-2042-j2store-to-magento-2-migration-extension.html#/72-entities-1000)
@@ -35,6 +36,7 @@
3536
- [CS-Cart](https://www.cs-cart.com/)
3637
- [CubeCart](https://www.cubecart.com/)
3738
- [Drupal Commerce](https://drupalcommerce.org/)
39+
- [EKM](https://www.ekm.com/)
3840
- [HikaShop](https://www.hikashop.com/)
3941
- [J2Store](https://www.j2store.org/)
4042
- JigoShop

composer.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@
1515
"role": "Developer"
1616
}
1717
],
18+
"require": {
19+
"phpoffice/phpspreadsheet": "*"
20+
},
1821
"autoload": {
1922
"files": ["registration.php"],
2023
"psr-4": {

0 commit comments

Comments
 (0)