Version Notes
3.0.4- Added Catalog Project, Sections and Data file support
Download this release
Release Info
Developer | Magento Core Team |
Extension | Mage_PDF_per_Product |
Version | 3.0.5 |
Comparing to | |
See all releases |
Code changes from version 3.0.4 to 3.0.5
- app/code/community/Mage/Codi/Helper/Createzip.php +86 -86
- app/code/community/Mage/Codi/Helper/Data.php +320 -320
- app/code/community/Mage/Codi/Model/Codi.php +1116 -1118
- app/code/community/Mage/Codi/controllers/SyncController.php +5 -4
- app/code/community/Mage/Codi/etc/config.xml +1 -1
- app/design/adminhtml/default/default/template/codi/index.phtml +1 -1
- app/design/frontend/default/default/template/catalog/product/view.phtml +5 -1
- package.xml +4 -4
app/code/community/Mage/Codi/Helper/Createzip.php
CHANGED
@@ -1,87 +1,87 @@
|
|
1 |
-
<?php
|
2 |
-
/* Create zip of the files */
|
3 |
-
|
4 |
-
class Mage_Codi_Helper_Createzip extends Mage_Core_Helper_Abstract
|
5 |
-
{
|
6 |
-
function get_files_from_folder($directory,$filename='',$put_into='') {
|
7 |
-
if ($handle = opendir($directory)) {
|
8 |
-
while (false !== ($file = readdir($handle))) {
|
9 |
-
if (is_file($directory.$file)) {
|
10 |
-
$fileContents = file_get_contents($directory.$file);
|
11 |
-
$this->addFile($fileContents, $put_into.$file);
|
12 |
-
} elseif ($file != '.' and $file != '..' and is_dir($directory.$file)) {
|
13 |
-
$this->addDirectory($put_into.$file.'/');
|
14 |
-
$this->get_files_from_folder($directory.$file.'/',$filename, $put_into.$file.'/');
|
15 |
-
}
|
16 |
-
}
|
17 |
-
$data = $this->getZippedfile();
|
18 |
-
$f = fopen($directory."/".$filename,"wb");
|
19 |
-
fwrite($f,$data);
|
20 |
-
fclose($f);
|
21 |
-
}
|
22 |
-
closedir($handle);
|
23 |
-
}
|
24 |
-
/* creates a compressed zip file */
|
25 |
-
function create_zip($files = array(),$destination = '',$overwrite = false,$strreplace='')
|
26 |
-
{
|
27 |
-
//if the zip file already exists and overwrite is false, return false
|
28 |
-
if(file_exists($destination) && !$overwrite) { return false; }
|
29 |
-
//vars
|
30 |
-
$valid_files = array();
|
31 |
-
//if files were passed in...
|
32 |
-
if(is_array($files)) {
|
33 |
-
//cycle through each file
|
34 |
-
foreach($files as $file) {
|
35 |
-
//make sure the file exists
|
36 |
-
if(file_exists($file)) {
|
37 |
-
$valid_files[] = $file;
|
38 |
-
}
|
39 |
-
}
|
40 |
-
}
|
41 |
-
//if we have good files...
|
42 |
-
if(count($valid_files)) {
|
43 |
-
//create the archive
|
44 |
-
$zip = new ZipArchive();
|
45 |
-
if($zip->open($destination,$overwrite ? ZIPARCHIVE::OVERWRITE : ZIPARCHIVE::CREATE) !== true) {
|
46 |
-
return false;
|
47 |
-
}
|
48 |
-
//add the files
|
49 |
-
foreach($valid_files as $file) {
|
50 |
-
$newfile=str_replace($strreplace,"",$file);
|
51 |
-
$zip->addFile($file,$newfile);
|
52 |
-
}
|
53 |
-
//debug
|
54 |
-
//echo 'The zip archive contains ',$zip->numFiles,' files with a status of ',$zip->status;
|
55 |
-
//close the zip -- done!
|
56 |
-
$zip->close();
|
57 |
-
//check to make sure the file exists
|
58 |
-
return file_exists($destination);
|
59 |
-
}
|
60 |
-
else
|
61 |
-
{
|
62 |
-
return false;
|
63 |
-
}
|
64 |
-
}
|
65 |
-
//Fuction to create zip for import the data
|
66 |
-
function createimportzip($filename){
|
67 |
-
$zipfilename=$filename.'.zip';
|
68 |
-
$DataFile = $filename.'.txt';
|
69 |
-
$catalogSection='CatalogSection.txt';
|
70 |
-
$catalogProject='CatalogProject.txt';
|
71 |
-
$helper=Mage::helper('codi');
|
72 |
-
//Change for zip
|
73 |
-
$files_to_zip = array($basePath.'CoDzip/CoDfiles/'.$filename.'.txt',
|
74 |
-
$basePath.'CoDzip/CoDfiles/CatalogSection.txt',
|
75 |
-
$basePath.'CoDzip/CoDfiles/CatalogProject.txt');
|
76 |
-
//if true, good; if false, zip creation failed
|
77 |
-
$result=$this->create_zip($files_to_zip,'CoDzip/'.$zipfilename,true,$basePath.'CoDzip/CoDfiles/');
|
78 |
-
|
79 |
-
if($result)
|
80 |
-
{
|
81 |
-
//Deleting files
|
82 |
-
if (copy($basePath.'CoDzip/CoDfiles/'.$zipfilename,$basePath.'CoDzip/'.$zipfilename)) {
|
83 |
-
unlink($basePath.'CoDzip/CoDfiles/'.$zipfilename);
|
84 |
-
}
|
85 |
-
}
|
86 |
-
}
|
87 |
}
|
1 |
+
<?php
|
2 |
+
/* Create zip of the files */
|
3 |
+
|
4 |
+
class Mage_Codi_Helper_Createzip extends Mage_Core_Helper_Abstract
|
5 |
+
{
|
6 |
+
function get_files_from_folder($directory,$filename='',$put_into='') {
|
7 |
+
if ($handle = opendir($directory)) {
|
8 |
+
while (false !== ($file = readdir($handle))) {
|
9 |
+
if (is_file($directory.$file)) {
|
10 |
+
$fileContents = file_get_contents($directory.$file);
|
11 |
+
$this->addFile($fileContents, $put_into.$file);
|
12 |
+
} elseif ($file != '.' and $file != '..' and is_dir($directory.$file)) {
|
13 |
+
$this->addDirectory($put_into.$file.'/');
|
14 |
+
$this->get_files_from_folder($directory.$file.'/',$filename, $put_into.$file.'/');
|
15 |
+
}
|
16 |
+
}
|
17 |
+
$data = $this->getZippedfile();
|
18 |
+
$f = fopen($directory."/".$filename,"wb");
|
19 |
+
fwrite($f,$data);
|
20 |
+
fclose($f);
|
21 |
+
}
|
22 |
+
closedir($handle);
|
23 |
+
}
|
24 |
+
/* creates a compressed zip file */
|
25 |
+
function create_zip($files = array(),$destination = '',$overwrite = false,$strreplace='')
|
26 |
+
{
|
27 |
+
//if the zip file already exists and overwrite is false, return false
|
28 |
+
if(file_exists($destination) && !$overwrite) { return false; }
|
29 |
+
//vars
|
30 |
+
$valid_files = array();
|
31 |
+
//if files were passed in...
|
32 |
+
if(is_array($files)) {
|
33 |
+
//cycle through each file
|
34 |
+
foreach($files as $file) {
|
35 |
+
//make sure the file exists
|
36 |
+
if(file_exists($file)) {
|
37 |
+
$valid_files[] = $file;
|
38 |
+
}
|
39 |
+
}
|
40 |
+
}
|
41 |
+
//if we have good files...
|
42 |
+
if(count($valid_files)) {
|
43 |
+
//create the archive
|
44 |
+
$zip = new ZipArchive();
|
45 |
+
if($zip->open($destination,$overwrite ? ZIPARCHIVE::OVERWRITE : ZIPARCHIVE::CREATE) !== true) {
|
46 |
+
return false;
|
47 |
+
}
|
48 |
+
//add the files
|
49 |
+
foreach($valid_files as $file) {
|
50 |
+
$newfile=str_replace($strreplace,"",$file);
|
51 |
+
$zip->addFile($file,$newfile);
|
52 |
+
}
|
53 |
+
//debug
|
54 |
+
//echo 'The zip archive contains ',$zip->numFiles,' files with a status of ',$zip->status;
|
55 |
+
//close the zip -- done!
|
56 |
+
$zip->close();
|
57 |
+
//check to make sure the file exists
|
58 |
+
return file_exists($destination);
|
59 |
+
}
|
60 |
+
else
|
61 |
+
{
|
62 |
+
return false;
|
63 |
+
}
|
64 |
+
}
|
65 |
+
//Fuction to create zip for import the data
|
66 |
+
function createimportzip($filename){
|
67 |
+
$zipfilename=$filename.'.zip';
|
68 |
+
$DataFile = $filename.'.txt';
|
69 |
+
$catalogSection='CatalogSection.txt';
|
70 |
+
$catalogProject='CatalogProject.txt';
|
71 |
+
$helper=Mage::helper('codi');
|
72 |
+
//Change for zip
|
73 |
+
$files_to_zip = array($basePath.'CoDzip/CoDfiles/'.$filename.'.txt',
|
74 |
+
$basePath.'CoDzip/CoDfiles/CatalogSection.txt',
|
75 |
+
$basePath.'CoDzip/CoDfiles/CatalogProject.txt');
|
76 |
+
//if true, good; if false, zip creation failed
|
77 |
+
$result=$this->create_zip($files_to_zip,'CoDzip/'.$zipfilename,true,$basePath.'CoDzip/CoDfiles/');
|
78 |
+
|
79 |
+
if($result)
|
80 |
+
{
|
81 |
+
//Deleting files
|
82 |
+
if (copy($basePath.'CoDzip/CoDfiles/'.$zipfilename,$basePath.'CoDzip/'.$zipfilename)) {
|
83 |
+
unlink($basePath.'CoDzip/CoDfiles/'.$zipfilename);
|
84 |
+
}
|
85 |
+
}
|
86 |
+
}
|
87 |
}
|
app/code/community/Mage/Codi/Helper/Data.php
CHANGED
@@ -1,320 +1,320 @@
|
|
1 |
-
<?php
|
2 |
-
class Mage_Codi_Helper_Data extends Mage_Core_Helper_Abstract
|
3 |
-
{
|
4 |
-
function output_file($file, $name, $mime_type='')
|
5 |
-
{
|
6 |
-
/*
|
7 |
-
This function takes a path to a file to output ($file),
|
8 |
-
the filename that the browser will see ($name) and
|
9 |
-
the MIME type of the file ($mime_type, optional).
|
10 |
-
|
11 |
-
*/
|
12 |
-
if(!is_readable($file)) die('File not found or inaccessible!');
|
13 |
-
|
14 |
-
$size = filesize($file);
|
15 |
-
$name = rawurldecode($name);
|
16 |
-
|
17 |
-
/* Figure out the MIME type (if not specified) */
|
18 |
-
$known_mime_types=array(
|
19 |
-
"pdf" => "application/pdf",
|
20 |
-
"txt" => "text/plain",
|
21 |
-
"html" => "text/html",
|
22 |
-
"htm" => "text/html",
|
23 |
-
"exe" => "application/octet-stream",
|
24 |
-
"zip" => "application/zip",
|
25 |
-
"doc" => "application/msword",
|
26 |
-
"xls" => "application/vnd.ms-excel",
|
27 |
-
"ppt" => "application/vnd.ms-powerpoint",
|
28 |
-
"gif" => "image/gif",
|
29 |
-
"png" => "image/png",
|
30 |
-
"jpeg"=> "image/jpg",
|
31 |
-
"jpg" => "image/jpg",
|
32 |
-
"php" => "text/plain"
|
33 |
-
);
|
34 |
-
|
35 |
-
if($mime_type==''){
|
36 |
-
$file_extension = strtolower(substr(strrchr($file,"."),1));
|
37 |
-
if(array_key_exists($file_extension, $known_mime_types)){
|
38 |
-
$mime_type=$known_mime_types[$file_extension];
|
39 |
-
} else {
|
40 |
-
$mime_type="application/force-download";
|
41 |
-
};
|
42 |
-
};
|
43 |
-
|
44 |
-
@ob_end_clean(); //turn off output buffering to decrease cpu usage
|
45 |
-
|
46 |
-
// required for IE, otherwise Content-Disposition may be ignored
|
47 |
-
if(ini_get('zlib.output_compression'))
|
48 |
-
ini_set('zlib.output_compression', 'Off');
|
49 |
-
|
50 |
-
header('Content-Type: ' . $mime_type);
|
51 |
-
header('Content-Disposition: attachment; filename="'.$name.'"');
|
52 |
-
header("Content-Transfer-Encoding: binary");
|
53 |
-
header('Accept-Ranges: bytes');
|
54 |
-
|
55 |
-
/* The three lines below basically make the
|
56 |
-
download non-cacheable */
|
57 |
-
header("Cache-control: private");
|
58 |
-
header('Pragma: private');
|
59 |
-
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
|
60 |
-
|
61 |
-
// multipart-download and download resuming support
|
62 |
-
if(isset($_SERVER['HTTP_RANGE']))
|
63 |
-
{
|
64 |
-
list($a, $range) = explode("=",$_SERVER['HTTP_RANGE'],2);
|
65 |
-
list($range) = explode(",",$range,2);
|
66 |
-
list($range, $range_end) = explode("-", $range);
|
67 |
-
$range=intval($range);
|
68 |
-
if(!$range_end) {
|
69 |
-
$range_end=$size-1;
|
70 |
-
} else {
|
71 |
-
$range_end=intval($range_end);
|
72 |
-
}
|
73 |
-
|
74 |
-
$new_length = $range_end-$range+1;
|
75 |
-
header("HTTP/1.1 206 Partial Content");
|
76 |
-
header("Content-Length: $new_length");
|
77 |
-
header("Content-Range: bytes $range-$range_end/$size");
|
78 |
-
} else {
|
79 |
-
$new_length=$size;
|
80 |
-
header("Content-Length: ".$size);
|
81 |
-
}
|
82 |
-
|
83 |
-
/* output the file itself */
|
84 |
-
$chunksize = 1*(1024*1024); //you may want to change this
|
85 |
-
$bytes_send = 0;
|
86 |
-
if ($file = fopen($file, 'r'))
|
87 |
-
{
|
88 |
-
if(isset($_SERVER['HTTP_RANGE']))
|
89 |
-
fseek($file, $range);
|
90 |
-
|
91 |
-
while(!feof($file) &&
|
92 |
-
(!connection_aborted()) &&
|
93 |
-
($bytes_send<$new_length)
|
94 |
-
)
|
95 |
-
{
|
96 |
-
$buffer = fread($file, $chunksize);
|
97 |
-
print($buffer); //echo($buffer); // is also possible
|
98 |
-
flush();
|
99 |
-
$bytes_send += strlen($buffer);
|
100 |
-
}
|
101 |
-
fclose($file);
|
102 |
-
} else die('Error - can not open file.');
|
103 |
-
|
104 |
-
die();
|
105 |
-
}
|
106 |
-
|
107 |
-
function deleteFile($basePath='',$filename='')
|
108 |
-
{
|
109 |
-
@unlink($basePath.$filename);
|
110 |
-
//remove text files
|
111 |
-
$filesn = glob($basePath."CoDzip/CoDfiles/*.txt");
|
112 |
-
foreach($filesn as $filen)
|
113 |
-
{
|
114 |
-
unlink($filen);
|
115 |
-
}
|
116 |
-
}
|
117 |
-
//function for get the theme
|
118 |
-
function getTheme()
|
119 |
-
{
|
120 |
-
foreach (Mage::app()->getWebsites() as $website)
|
121 |
-
{
|
122 |
-
$defaultGroup = $website->getDefaultGroup();
|
123 |
-
$StoreId = $defaultGroup->getDefaultStoreId();
|
124 |
-
}
|
125 |
-
|
126 |
-
$design = Mage::getSingleton('core/design')->loadChange($StoreId);
|
127 |
-
|
128 |
-
$package = $design->getPackage();
|
129 |
-
$default_theme = $design->getTheme();
|
130 |
-
|
131 |
-
if ( $package == "" && $default_theme == "" ){
|
132 |
-
|
133 |
-
$package = Mage::getStoreConfig('design/package/name', $StoreId);
|
134 |
-
$default_theme = Mage::getStoreConfig('design/theme/default', $StoreId);
|
135 |
-
}
|
136 |
-
|
137 |
-
if ( $package == "" ) $package = "default";
|
138 |
-
if ( $default_theme == "" ) $default_theme = "default";
|
139 |
-
|
140 |
-
return $package.'/'.$default_theme;
|
141 |
-
|
142 |
-
|
143 |
-
|
144 |
-
}
|
145 |
-
function array2json($arr) {
|
146 |
-
|
147 |
-
if(function_exists('json_encode')) return json_encode($arr); //Lastest versions of PHP already has this functionality.
|
148 |
-
$parts = array();
|
149 |
-
$is_list = false;
|
150 |
-
|
151 |
-
//Find out if the given array is a numerical array
|
152 |
-
$keys = array_keys($arr);
|
153 |
-
$max_length = count($arr)-1;
|
154 |
-
if(($keys[0] == 0) and ($keys[$max_length] == $max_length)) {//See if the first key is 0 and last key is length - 1
|
155 |
-
$is_list = true;
|
156 |
-
for($i=0; $i<count($keys); $i++) { //See if each key correspondes to its position
|
157 |
-
if($i != $keys[$i]) { //A key fails at position check.
|
158 |
-
$is_list = false; //It is an associative array.
|
159 |
-
break;
|
160 |
-
}
|
161 |
-
}
|
162 |
-
}
|
163 |
-
|
164 |
-
foreach($arr as $key=>$value) {
|
165 |
-
if(is_array($value)) { //Custom handling for arrays
|
166 |
-
if($is_list) $parts[] = array2json($value); /* :RECURSION: */
|
167 |
-
else $parts[] = '"' . $key . '":' . array2json($value); /* :RECURSION: */
|
168 |
-
} else {
|
169 |
-
$str = '';
|
170 |
-
if(!$is_list) $str = '"' . $key . '":';
|
171 |
-
|
172 |
-
//Custom handling for multiple data types
|
173 |
-
if(is_numeric($value)) $str .= $value; //Numbers
|
174 |
-
elseif($value === false) $str .= 'false'; //The booleans
|
175 |
-
elseif($value === true) $str .= 'true';
|
176 |
-
else $str .= '"' . addslashes($value) . '"'; //All other things
|
177 |
-
// :TODO: Is there any more datatype we should be in the lookout for? (Object?)
|
178 |
-
|
179 |
-
$parts[] = $str;
|
180 |
-
}
|
181 |
-
}
|
182 |
-
$json = implode(',',$parts);
|
183 |
-
|
184 |
-
if($is_list) return '[' . $json . ']';//Return numerical JSON
|
185 |
-
return '{' . $json . '}';//Return associative JSON
|
186 |
-
}
|
187 |
-
|
188 |
-
|
189 |
-
function geTierprice($product)
|
190 |
-
{
|
191 |
-
|
192 |
-
if (is_null($product)) {
|
193 |
-
return array();
|
194 |
-
}
|
195 |
-
$res='';
|
196 |
-
$codquantity=Mage::getStoreConfig('codi/codi/codquantity');
|
197 |
-
$codprice=Mage::getStoreConfig('codi/codi/codprice');
|
198 |
-
$codsavings=Mage::getStoreConfig('codi/codi/codsavings');
|
199 |
-
|
200 |
-
//[tier qty 1]#$#[tier price 1]#$#[(product price-tier price 1)/product price%]#$$#
|
201 |
-
|
202 |
-
$prices = $product->getFormatedTierPrice();
|
203 |
-
|
204 |
-
$rightstr = '';
|
205 |
-
if (is_array($prices)) {
|
206 |
-
|
207 |
-
$i='1';
|
208 |
-
$count=count($prices);
|
209 |
-
if($count>0)
|
210 |
-
$res='[TierPriceTable]#$$#'.$codquantity.'#$#'.$codprice.'#$#'.$codsavings."=";
|
211 |
-
|
212 |
-
foreach ($prices as $price) {
|
213 |
-
$price['price_qty'] = $price['price_qty']*1;
|
214 |
-
$rightstr.=$price['price_qty'].'#$#';
|
215 |
-
if ($product->getPrice() != $product->getFinalPrice()) {
|
216 |
-
if ($price['price']<$product->getFinalPrice()) {
|
217 |
-
|
218 |
-
$rightstr.=Mage::helper('tax')->getPrice($product, $price['website_price'], true).'#$#';
|
219 |
-
|
220 |
-
if($i==$count)
|
221 |
-
{
|
222 |
-
$rightstr.=ceil(100 - (( 100/$product->getFinalPrice() ) * $price['price'] )).'%';
|
223 |
-
}
|
224 |
-
else
|
225 |
-
{
|
226 |
-
$rightstr.=ceil(100 - (( 100/$product->getFinalPrice() ) * $price['price'] )).'%#$$#';
|
227 |
-
}
|
228 |
-
|
229 |
-
}
|
230 |
-
} else {
|
231 |
-
if ($price['price']<$product->getPrice()) {
|
232 |
-
$rightstr.=Mage::helper('tax')->getPrice($product, $price['website_price'], true).'#$#';
|
233 |
-
|
234 |
-
if($i==$count)
|
235 |
-
$rightstr.= ceil(100 - (( 100/$product->getPrice() ) * $price['price'] )).'%';
|
236 |
-
else
|
237 |
-
$rightstr.= ceil(100 - (( 100/$product->getPrice() ) * $price['price'] )).'%#$$#';
|
238 |
-
}
|
239 |
-
}
|
240 |
-
$i++;
|
241 |
-
}
|
242 |
-
}
|
243 |
-
|
244 |
-
return $res.$rightstr;
|
245 |
-
|
246 |
-
}
|
247 |
-
//Code for Catalog section code
|
248 |
-
function drawItem($category, $level=0,$name='',$i=1,$j=1,$path='')
|
249 |
-
{
|
250 |
-
$html='';
|
251 |
-
|
252 |
-
$catalogSectionModel=Mage::getModel('codi/codi');
|
253 |
-
//Get Category child
|
254 |
-
$childrennew=$category->getChildrenCategories();
|
255 |
-
|
256 |
-
$id=$category->getId();
|
257 |
-
if($level!=1)
|
258 |
-
{
|
259 |
-
$path.='-'.$j;
|
260 |
-
$name=$name.'#$#'.$category->getName();//.' '.$i.$path;
|
261 |
-
$sec_path.=str_replace("-",",",$path);
|
262 |
-
$seq=$i.$sec_path;
|
263 |
-
}
|
264 |
-
else
|
265 |
-
{
|
266 |
-
$name=$category->getName();//.' '.$i;
|
267 |
-
$seq=$i;
|
268 |
-
}
|
269 |
-
|
270 |
-
$catalogSectionModel->addCatalogSection($id,$name);
|
271 |
-
$html= "
|
272 |
-
|
273 |
-
if(count($childrennew))
|
274 |
-
{
|
275 |
-
$j = 1;
|
276 |
-
foreach ($childrennew as $cat)
|
277 |
-
{
|
278 |
-
//$cat=$this->createCategoryObj($child->getID());
|
279 |
-
if($cat!=false)
|
280 |
-
$htmlChildren.= $this->drawItem($cat, $level+1,$name,$i,$j,$path);
|
281 |
-
$j++;
|
282 |
-
}
|
283 |
-
}
|
284 |
-
return $html.= $htmlChildren;
|
285 |
-
}
|
286 |
-
//Create category object
|
287 |
-
function createCategoryObj($cid)
|
288 |
-
{
|
289 |
-
$collection = Mage::getModel('catalog/category')->getCollection()
|
290 |
-
->setStoreId('1')
|
291 |
-
->addAttributeToSelect('name')
|
292 |
-
->addAttributeToSelect('is_active')
|
293 |
-
->addAttributeToFilter('entity_id', array('eq' => $cid));
|
294 |
-
foreach($collection as $category)
|
295 |
-
{
|
296 |
-
if($category)
|
297 |
-
return $category;
|
298 |
-
else
|
299 |
-
return false;
|
300 |
-
}
|
301 |
-
}
|
302 |
-
//get product Postion
|
303 |
-
function productPostion($category_id,$productId)
|
304 |
-
{
|
305 |
-
|
306 |
-
$category = Mage::getModel('catalog/category')
|
307 |
-
->setStoreId(1)
|
308 |
-
->load($category_id);
|
309 |
-
$positions = $category->getProductsPosition();
|
310 |
-
if(count($positions)>0)
|
311 |
-
$position=$positions[$productId];
|
312 |
-
else
|
313 |
-
$position='';
|
314 |
-
|
315 |
-
return $position;
|
316 |
-
|
317 |
-
}
|
318 |
-
|
319 |
-
}
|
320 |
-
?>
|
1 |
+
<?php
|
2 |
+
class Mage_Codi_Helper_Data extends Mage_Core_Helper_Abstract
|
3 |
+
{
|
4 |
+
function output_file($file, $name, $mime_type='')
|
5 |
+
{
|
6 |
+
/*
|
7 |
+
This function takes a path to a file to output ($file),
|
8 |
+
the filename that the browser will see ($name) and
|
9 |
+
the MIME type of the file ($mime_type, optional).
|
10 |
+
|
11 |
+
*/
|
12 |
+
if(!is_readable($file)) die('File not found or inaccessible!');
|
13 |
+
|
14 |
+
$size = filesize($file);
|
15 |
+
$name = rawurldecode($name);
|
16 |
+
|
17 |
+
/* Figure out the MIME type (if not specified) */
|
18 |
+
$known_mime_types=array(
|
19 |
+
"pdf" => "application/pdf",
|
20 |
+
"txt" => "text/plain",
|
21 |
+
"html" => "text/html",
|
22 |
+
"htm" => "text/html",
|
23 |
+
"exe" => "application/octet-stream",
|
24 |
+
"zip" => "application/zip",
|
25 |
+
"doc" => "application/msword",
|
26 |
+
"xls" => "application/vnd.ms-excel",
|
27 |
+
"ppt" => "application/vnd.ms-powerpoint",
|
28 |
+
"gif" => "image/gif",
|
29 |
+
"png" => "image/png",
|
30 |
+
"jpeg"=> "image/jpg",
|
31 |
+
"jpg" => "image/jpg",
|
32 |
+
"php" => "text/plain"
|
33 |
+
);
|
34 |
+
|
35 |
+
if($mime_type==''){
|
36 |
+
$file_extension = strtolower(substr(strrchr($file,"."),1));
|
37 |
+
if(array_key_exists($file_extension, $known_mime_types)){
|
38 |
+
$mime_type=$known_mime_types[$file_extension];
|
39 |
+
} else {
|
40 |
+
$mime_type="application/force-download";
|
41 |
+
};
|
42 |
+
};
|
43 |
+
|
44 |
+
@ob_end_clean(); //turn off output buffering to decrease cpu usage
|
45 |
+
|
46 |
+
// required for IE, otherwise Content-Disposition may be ignored
|
47 |
+
if(ini_get('zlib.output_compression'))
|
48 |
+
ini_set('zlib.output_compression', 'Off');
|
49 |
+
|
50 |
+
header('Content-Type: ' . $mime_type);
|
51 |
+
header('Content-Disposition: attachment; filename="'.$name.'"');
|
52 |
+
header("Content-Transfer-Encoding: binary");
|
53 |
+
header('Accept-Ranges: bytes');
|
54 |
+
|
55 |
+
/* The three lines below basically make the
|
56 |
+
download non-cacheable */
|
57 |
+
header("Cache-control: private");
|
58 |
+
header('Pragma: private');
|
59 |
+
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
|
60 |
+
|
61 |
+
// multipart-download and download resuming support
|
62 |
+
if(isset($_SERVER['HTTP_RANGE']))
|
63 |
+
{
|
64 |
+
list($a, $range) = explode("=",$_SERVER['HTTP_RANGE'],2);
|
65 |
+
list($range) = explode(",",$range,2);
|
66 |
+
list($range, $range_end) = explode("-", $range);
|
67 |
+
$range=intval($range);
|
68 |
+
if(!$range_end) {
|
69 |
+
$range_end=$size-1;
|
70 |
+
} else {
|
71 |
+
$range_end=intval($range_end);
|
72 |
+
}
|
73 |
+
|
74 |
+
$new_length = $range_end-$range+1;
|
75 |
+
header("HTTP/1.1 206 Partial Content");
|
76 |
+
header("Content-Length: $new_length");
|
77 |
+
header("Content-Range: bytes $range-$range_end/$size");
|
78 |
+
} else {
|
79 |
+
$new_length=$size;
|
80 |
+
header("Content-Length: ".$size);
|
81 |
+
}
|
82 |
+
|
83 |
+
/* output the file itself */
|
84 |
+
$chunksize = 1*(1024*1024); //you may want to change this
|
85 |
+
$bytes_send = 0;
|
86 |
+
if ($file = fopen($file, 'r'))
|
87 |
+
{
|
88 |
+
if(isset($_SERVER['HTTP_RANGE']))
|
89 |
+
fseek($file, $range);
|
90 |
+
|
91 |
+
while(!feof($file) &&
|
92 |
+
(!connection_aborted()) &&
|
93 |
+
($bytes_send<$new_length)
|
94 |
+
)
|
95 |
+
{
|
96 |
+
$buffer = fread($file, $chunksize);
|
97 |
+
print($buffer); //echo($buffer); // is also possible
|
98 |
+
flush();
|
99 |
+
$bytes_send += strlen($buffer);
|
100 |
+
}
|
101 |
+
fclose($file);
|
102 |
+
} else die('Error - can not open file.');
|
103 |
+
|
104 |
+
die();
|
105 |
+
}
|
106 |
+
|
107 |
+
function deleteFile($basePath='',$filename='')
|
108 |
+
{
|
109 |
+
@unlink($basePath.$filename);
|
110 |
+
//remove text files
|
111 |
+
$filesn = glob($basePath."CoDzip/CoDfiles/*.txt");
|
112 |
+
foreach($filesn as $filen)
|
113 |
+
{
|
114 |
+
unlink($filen);
|
115 |
+
}
|
116 |
+
}
|
117 |
+
//function for get the theme
|
118 |
+
function getTheme()
|
119 |
+
{
|
120 |
+
foreach (Mage::app()->getWebsites() as $website)
|
121 |
+
{
|
122 |
+
$defaultGroup = $website->getDefaultGroup();
|
123 |
+
$StoreId = $defaultGroup->getDefaultStoreId();
|
124 |
+
}
|
125 |
+
|
126 |
+
$design = Mage::getSingleton('core/design')->loadChange($StoreId);
|
127 |
+
|
128 |
+
$package = $design->getPackage();
|
129 |
+
$default_theme = $design->getTheme();
|
130 |
+
|
131 |
+
if ( $package == "" && $default_theme == "" ){
|
132 |
+
|
133 |
+
$package = Mage::getStoreConfig('design/package/name', $StoreId);
|
134 |
+
$default_theme = Mage::getStoreConfig('design/theme/default', $StoreId);
|
135 |
+
}
|
136 |
+
|
137 |
+
if ( $package == "" ) $package = "default";
|
138 |
+
if ( $default_theme == "" ) $default_theme = "default";
|
139 |
+
|
140 |
+
return $package.'/'.$default_theme;
|
141 |
+
|
142 |
+
|
143 |
+
|
144 |
+
}
|
145 |
+
function array2json($arr) {
|
146 |
+
|
147 |
+
if(function_exists('json_encode')) return json_encode($arr); //Lastest versions of PHP already has this functionality.
|
148 |
+
$parts = array();
|
149 |
+
$is_list = false;
|
150 |
+
|
151 |
+
//Find out if the given array is a numerical array
|
152 |
+
$keys = array_keys($arr);
|
153 |
+
$max_length = count($arr)-1;
|
154 |
+
if(($keys[0] == 0) and ($keys[$max_length] == $max_length)) {//See if the first key is 0 and last key is length - 1
|
155 |
+
$is_list = true;
|
156 |
+
for($i=0; $i<count($keys); $i++) { //See if each key correspondes to its position
|
157 |
+
if($i != $keys[$i]) { //A key fails at position check.
|
158 |
+
$is_list = false; //It is an associative array.
|
159 |
+
break;
|
160 |
+
}
|
161 |
+
}
|
162 |
+
}
|
163 |
+
|
164 |
+
foreach($arr as $key=>$value) {
|
165 |
+
if(is_array($value)) { //Custom handling for arrays
|
166 |
+
if($is_list) $parts[] = array2json($value); /* :RECURSION: */
|
167 |
+
else $parts[] = '"' . $key . '":' . array2json($value); /* :RECURSION: */
|
168 |
+
} else {
|
169 |
+
$str = '';
|
170 |
+
if(!$is_list) $str = '"' . $key . '":';
|
171 |
+
|
172 |
+
//Custom handling for multiple data types
|
173 |
+
if(is_numeric($value)) $str .= $value; //Numbers
|
174 |
+
elseif($value === false) $str .= 'false'; //The booleans
|
175 |
+
elseif($value === true) $str .= 'true';
|
176 |
+
else $str .= '"' . addslashes($value) . '"'; //All other things
|
177 |
+
// :TODO: Is there any more datatype we should be in the lookout for? (Object?)
|
178 |
+
|
179 |
+
$parts[] = $str;
|
180 |
+
}
|
181 |
+
}
|
182 |
+
$json = implode(',',$parts);
|
183 |
+
|
184 |
+
if($is_list) return '[' . $json . ']';//Return numerical JSON
|
185 |
+
return '{' . $json . '}';//Return associative JSON
|
186 |
+
}
|
187 |
+
|
188 |
+
|
189 |
+
function geTierprice($product)
|
190 |
+
{
|
191 |
+
|
192 |
+
if (is_null($product)) {
|
193 |
+
return array();
|
194 |
+
}
|
195 |
+
$res='';
|
196 |
+
$codquantity=Mage::getStoreConfig('codi/codi/codquantity');
|
197 |
+
$codprice=Mage::getStoreConfig('codi/codi/codprice');
|
198 |
+
$codsavings=Mage::getStoreConfig('codi/codi/codsavings');
|
199 |
+
|
200 |
+
//[tier qty 1]#$#[tier price 1]#$#[(product price-tier price 1)/product price%]#$$#
|
201 |
+
|
202 |
+
$prices = $product->getFormatedTierPrice();
|
203 |
+
|
204 |
+
$rightstr = '';
|
205 |
+
if (is_array($prices)) {
|
206 |
+
|
207 |
+
$i='1';
|
208 |
+
$count=count($prices);
|
209 |
+
if($count>0)
|
210 |
+
$res='[TierPriceTable]#$$#'.$codquantity.'#$#'.$codprice.'#$#'.$codsavings."=";
|
211 |
+
|
212 |
+
foreach ($prices as $price) {
|
213 |
+
$price['price_qty'] = $price['price_qty']*1;
|
214 |
+
$rightstr.=$price['price_qty'].'#$#';
|
215 |
+
if ($product->getPrice() != $product->getFinalPrice()) {
|
216 |
+
if ($price['price']<$product->getFinalPrice()) {
|
217 |
+
|
218 |
+
$rightstr.=Mage::helper('tax')->getPrice($product, $price['website_price'], true).'#$#';
|
219 |
+
|
220 |
+
if($i==$count)
|
221 |
+
{
|
222 |
+
$rightstr.=ceil(100 - (( 100/$product->getFinalPrice() ) * $price['price'] )).'%';
|
223 |
+
}
|
224 |
+
else
|
225 |
+
{
|
226 |
+
$rightstr.=ceil(100 - (( 100/$product->getFinalPrice() ) * $price['price'] )).'%#$$#';
|
227 |
+
}
|
228 |
+
|
229 |
+
}
|
230 |
+
} else {
|
231 |
+
if ($price['price']<$product->getPrice()) {
|
232 |
+
$rightstr.=Mage::helper('tax')->getPrice($product, $price['website_price'], true).'#$#';
|
233 |
+
|
234 |
+
if($i==$count)
|
235 |
+
$rightstr.= ceil(100 - (( 100/$product->getPrice() ) * $price['price'] )).'%';
|
236 |
+
else
|
237 |
+
$rightstr.= ceil(100 - (( 100/$product->getPrice() ) * $price['price'] )).'%#$$#';
|
238 |
+
}
|
239 |
+
}
|
240 |
+
$i++;
|
241 |
+
}
|
242 |
+
}
|
243 |
+
|
244 |
+
return $res.$rightstr;
|
245 |
+
|
246 |
+
}
|
247 |
+
//Code for Catalog section code
|
248 |
+
function drawItem($category, $level=0,$name='',$i=1,$j=1,$path='')
|
249 |
+
{
|
250 |
+
$html='';
|
251 |
+
|
252 |
+
$catalogSectionModel=Mage::getModel('codi/codi');
|
253 |
+
//Get Category child
|
254 |
+
$childrennew=$category->getChildrenCategories();
|
255 |
+
|
256 |
+
$id=$category->getId();
|
257 |
+
if($level!=1)
|
258 |
+
{
|
259 |
+
$path.='-'.$j;
|
260 |
+
$name=$name.'#$#'.$category->getName();//.' '.$i.$path;
|
261 |
+
$sec_path.=str_replace("-",",",$path);
|
262 |
+
$seq=$i.$sec_path;
|
263 |
+
}
|
264 |
+
else
|
265 |
+
{
|
266 |
+
$name=$category->getName();//.' '.$i;
|
267 |
+
$seq=$i;
|
268 |
+
}
|
269 |
+
|
270 |
+
$catalogSectionModel->addCatalogSection($id,$name);
|
271 |
+
$html= "General\t".$seq."\t".$name."\t". $sec_Flag . "\n";
|
272 |
+
|
273 |
+
if(count($childrennew))
|
274 |
+
{
|
275 |
+
$j = 1;
|
276 |
+
foreach ($childrennew as $cat)
|
277 |
+
{
|
278 |
+
//$cat=$this->createCategoryObj($child->getID());
|
279 |
+
if($cat!=false)
|
280 |
+
$htmlChildren.= $this->drawItem($cat, $level+1,$name,$i,$j,$path);
|
281 |
+
$j++;
|
282 |
+
}
|
283 |
+
}
|
284 |
+
return $html.= $htmlChildren;
|
285 |
+
}
|
286 |
+
//Create category object
|
287 |
+
function createCategoryObj($cid)
|
288 |
+
{
|
289 |
+
$collection = Mage::getModel('catalog/category')->getCollection()
|
290 |
+
->setStoreId('1')
|
291 |
+
->addAttributeToSelect('name')
|
292 |
+
->addAttributeToSelect('is_active')
|
293 |
+
->addAttributeToFilter('entity_id', array('eq' => $cid));
|
294 |
+
foreach($collection as $category)
|
295 |
+
{
|
296 |
+
if($category)
|
297 |
+
return $category;
|
298 |
+
else
|
299 |
+
return false;
|
300 |
+
}
|
301 |
+
}
|
302 |
+
//get product Postion
|
303 |
+
function productPostion($category_id,$productId)
|
304 |
+
{
|
305 |
+
|
306 |
+
$category = Mage::getModel('catalog/category')
|
307 |
+
->setStoreId(1)
|
308 |
+
->load($category_id);
|
309 |
+
$positions = $category->getProductsPosition();
|
310 |
+
if(count($positions)>0)
|
311 |
+
$position=$positions[$productId];
|
312 |
+
else
|
313 |
+
$position='';
|
314 |
+
|
315 |
+
return $position;
|
316 |
+
|
317 |
+
}
|
318 |
+
|
319 |
+
}
|
320 |
+
?>
|
app/code/community/Mage/Codi/Model/Codi.php
CHANGED
@@ -1,1118 +1,1116 @@
|
|
1 |
-
<?php
|
2 |
-
|
3 |
-
class Mage_Codi_Model_Codi extends Mage_Core_Model_Abstract
|
4 |
-
{
|
5 |
-
public $target ;
|
6 |
-
public $codigrid ; //this flag is to know whether we are displaying our grid or a general grid
|
7 |
-
public $userid ;
|
8 |
-
public $password ;
|
9 |
-
public $disableextension ;
|
10 |
-
public $version = "3.0.4";
|
11 |
-
|
12 |
-
public $customerid ;
|
13 |
-
public $customerdatasourceid ;
|
14 |
-
public $validateuser ;
|
15 |
-
public $extensionName='Mage_PDF_per_Product';
|
16 |
-
public $StoreId ;
|
17 |
-
public $reviewsModel ;
|
18 |
-
public $ratingModel ;
|
19 |
-
public $enablereviews ;
|
20 |
-
public $mediaurl ;
|
21 |
-
|
22 |
-
public function _construct()
|
23 |
-
{
|
24 |
-
parent::_construct();
|
25 |
-
$this->_init('codi/codi');
|
26 |
-
$this->_logFile = "Catalog-on-demand-items.log";
|
27 |
-
|
28 |
-
$this->enablereviews = Mage::getStoreConfig('codi/codi/codenablereviews');
|
29 |
-
|
30 |
-
// Get StoreID -Start
|
31 |
-
foreach (Mage::app()->getWebsites() as $website)
|
32 |
-
{
|
33 |
-
$defaultGroup = $website->getDefaultGroup();
|
34 |
-
$StoreId = $defaultGroup->getDefaultStoreId();
|
35 |
-
}
|
36 |
-
|
37 |
-
$this->StoreId = $StoreId ;
|
38 |
-
// Get StoreID -End
|
39 |
-
|
40 |
-
$this->reviewsModel = Mage::getModel('review/review') ;
|
41 |
-
$this->ratingModel = Mage::getModel('rating/rating_option_vote') ;
|
42 |
-
$this->mediaurl = Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_MEDIA);
|
43 |
-
}
|
44 |
-
|
45 |
-
public function setStoreConfig( $myarray )
|
46 |
-
{
|
47 |
-
$section = 'codi' ;
|
48 |
-
$website = '' ;
|
49 |
-
$store = '';
|
50 |
-
|
51 |
-
$groups =
|
52 |
-
array(
|
53 |
-
'codi' =>
|
54 |
-
array(
|
55 |
-
'fields' => $myarray
|
56 |
-
));
|
57 |
-
Mage::getModel('adminhtml/config_data')
|
58 |
-
->setSection($section)
|
59 |
-
->setWebsite($website)
|
60 |
-
->setStore($store)
|
61 |
-
->setGroups($groups)
|
62 |
-
->save();
|
63 |
-
}
|
64 |
-
|
65 |
-
public function adminstart()
|
66 |
-
{
|
67 |
-
Mage::log("Notice : Admin Start", null, $this->_logFile);
|
68 |
-
|
69 |
-
$AdminNotified = Mage::getSingleton('core/session')->getAdminNotified();
|
70 |
-
if (!$AdminNotified)
|
71 |
-
{
|
72 |
-
Mage::getSingleton('core/session')->setAdminNotified(true);
|
73 |
-
try
|
74 |
-
{
|
75 |
-
$codimodel = Mage::getSingleton('codi/codi');
|
76 |
-
//Get Application Parameters Response (Notification)
|
77 |
-
$url = "https://webservices.catalog-on-demand.com/smanager/api.do?Operation=GetApplicationParameters&Application=CoDExtensionForMagento" ;
|
78 |
-
$paramsarray = array('UserID' => Mage::getStoreConfig('codi/codi/codusername'),
|
79 |
-
'Password' => Mage::getStoreConfig('codi/codi/codpassword') );
|
80 |
-
$Responsemsg = $this->Call( $url, $paramsarray );
|
81 |
-
if ( $Responsemsg )
|
82 |
-
{
|
83 |
-
if (!$Responsemsg->Errors)
|
84 |
-
{
|
85 |
-
foreach ($Responsemsg->GetApplicationParametersResponse->ApplicationParameter as $ApplicationParameter)
|
86 |
-
{
|
87 |
-
//Get Version
|
88 |
-
if ((string)$ApplicationParameter->Name == "Version")
|
89 |
-
$Version = (string)$ApplicationParameter->Value;
|
90 |
-
//Get Release Notes Link
|
91 |
-
if ((string)$ApplicationParameter->Name == "ReleaseNotesLink")
|
92 |
-
$ReleaseNotesLink = (string)$ApplicationParameter->Value;
|
93 |
-
//Get the Notification Message
|
94 |
-
if ((string)$ApplicationParameter->Name == "NotificationMessage")
|
95 |
-
$NotificationMessage = (string)$ApplicationParameter->Value;
|
96 |
-
}
|
97 |
-
|
98 |
-
$title = "Catalog-On-Demand version " . $Version . " now available";
|
99 |
-
|
100 |
-
$feedData[] = array(
|
101 |
-
'severity' => 2,
|
102 |
-
'date_added' => NOW(),
|
103 |
-
'title' => (string)$title,
|
104 |
-
'description' => (string)$NotificationMessage,
|
105 |
-
'url' => (string)$ReleaseNotesLink,
|
106 |
-
);
|
107 |
-
|
108 |
-
if ( version_compare($Version, $codimodel->version) == 1) {
|
109 |
-
Mage::getModel('adminnotification/inbox')->parse(array_reverse($feedData)); }
|
110 |
-
}
|
111 |
-
}
|
112 |
-
}
|
113 |
-
catch(Exception $e){}
|
114 |
-
}
|
115 |
-
}
|
116 |
-
|
117 |
-
public function InitImportStatuses(){
|
118 |
-
|
119 |
-
$write = Mage::getSingleton('core/resource')->getConnection('core_write');
|
120 |
-
|
121 |
-
$write->query("DROP TABLE IF EXISTS codi_import_status");
|
122 |
-
$write->query("CREATE TABLE codi_import_status(
|
123 |
-
id int(11) NOT NULL auto_increment PRIMARY KEY,
|
124 |
-
message varchar(50),
|
125 |
-
finished int(1) default 0)"
|
126 |
-
);
|
127 |
-
}
|
128 |
-
|
129 |
-
public function existTable(){
|
130 |
-
|
131 |
-
$write = Mage::getSingleton('core/resource')->getConnection('core_write');
|
132 |
-
|
133 |
-
$write->query("CREATE TABLE IF NOT EXISTS codi_import_status(
|
134 |
-
id int(11) NOT NULL auto_increment PRIMARY KEY,
|
135 |
-
message varchar(50),
|
136 |
-
finished int(1) default 0)"
|
137 |
-
);
|
138 |
-
|
139 |
-
}
|
140 |
-
|
141 |
-
public function addImportStatus( $message, $finished = 0 ){
|
142 |
-
|
143 |
-
$this->existTable();
|
144 |
-
|
145 |
-
$write = Mage::getSingleton('core/resource')->getConnection('core_write');
|
146 |
-
$query = "insert into codi_import_status (message, finished) values('".$message."', $finished)";
|
147 |
-
$write->query($query);
|
148 |
-
}
|
149 |
-
|
150 |
-
public function getImportStatuses(){
|
151 |
-
|
152 |
-
$this->existTable();
|
153 |
-
|
154 |
-
$read= Mage::getSingleton('core/resource')->getConnection('core_read');
|
155 |
-
|
156 |
-
$query = "select id, message, finished from codi_import_status order by id desc limit 1";
|
157 |
-
|
158 |
-
$messages = null;
|
159 |
-
|
160 |
-
$result = $read->query($query);
|
161 |
-
|
162 |
-
if($row = $result->fetch() ){
|
163 |
-
$messages = array('message'=>$row['message'], 'id'=>$row['id'], 'finished'=>$row['finished']);
|
164 |
-
}
|
165 |
-
|
166 |
-
return $messages;
|
167 |
-
}
|
168 |
-
|
169 |
-
public function deleteTable(){
|
170 |
-
|
171 |
-
$this->existTable();
|
172 |
-
|
173 |
-
$write = Mage::getSingleton('core/resource')->getConnection('core_write');
|
174 |
-
$query = "delete from codi_import_status";
|
175 |
-
$write->query($query);
|
176 |
-
}
|
177 |
-
|
178 |
-
public function isStart(){
|
179 |
-
|
180 |
-
$this->existTable();
|
181 |
-
|
182 |
-
$read= Mage::getSingleton('core/resource')->getConnection('core_read');
|
183 |
-
|
184 |
-
$query = "select id, message, finished from codi_import_status where message = 'start' order by id desc limit 1";
|
185 |
-
|
186 |
-
$result = $read->query($query);
|
187 |
-
|
188 |
-
if($row = $result->fetch() ){
|
189 |
-
return true;
|
190 |
-
}
|
191 |
-
|
192 |
-
return false;
|
193 |
-
}
|
194 |
-
//Changed in 3.0.3
|
195 |
-
public function createFile($basePath){
|
196 |
-
|
197 |
-
$fh = fopen($basePath.'CoDzip/CoDfiles/temp.txt', 'w');
|
198 |
-
|
199 |
-
if ( !$fh )
|
200 |
-
{
|
201 |
-
return false;
|
202 |
-
}
|
203 |
-
|
204 |
-
fclose($fh);
|
205 |
-
|
206 |
-
//unlink($basePath.'CoDzip/CoDfiles/temp.txt');
|
207 |
-
return true;
|
208 |
-
}
|
209 |
-
|
210 |
-
public function run_codi_import_manually($basepath){
|
211 |
-
|
212 |
-
$this->run_codi_import($basepath);
|
213 |
-
}
|
214 |
-
|
215 |
-
public function run_codi_import($basePath)
|
216 |
-
{
|
217 |
-
Mage::log("Notice : Codi Import Start", null, $this->_logFile);
|
218 |
-
|
219 |
-
ini_set('memory_limit','1024M');
|
220 |
-
|
221 |
-
$this->InitImportStatuses();
|
222 |
-
|
223 |
-
$fh = fopen($basePath.'CoDzip/CoDfiles/temp.txt', 'w');
|
224 |
-
|
225 |
-
if ( !$fh )
|
226 |
-
{
|
227 |
-
Mage::log("ERROR : Cann't open file for building data file:".$basePath, null, $this->_logFile);
|
228 |
-
$this->addImportStatus("fileerror", 1);
|
229 |
-
return;
|
230 |
-
}
|
231 |
-
|
232 |
-
fwrite($fh, "itemNumber\titemQty\titemUom\titemPrice\titemDescription\titemLink\titemAttributes\titemGraphic\tproductName\tproductMfg\tproductDescription\tproductGraphic\tproductLink\tproductAttributes\tCategory\tReviews\tSupplementalInfo");
|
233 |
-
|
234 |
-
$products = Mage::getModel('catalog/product')->getCollection();
|
235 |
-
$products->addAttributeToFilter('status', 1);//enabled
|
236 |
-
$products->addAttributeToFilter('visibility', 4);//catalog, search
|
237 |
-
$products->addAttributeToSelect('*');
|
238 |
-
$prodIds = $products->getAllIds();
|
239 |
-
|
240 |
-
$this->addImportStatus("start");
|
241 |
-
|
242 |
-
$status = "end";
|
243 |
-
foreach($prodIds as $productId) {
|
244 |
-
|
245 |
-
set_time_limit(0);
|
246 |
-
|
247 |
-
$message = $this->getImportStatuses();
|
248 |
-
if ( isset($message) && $message['message'] == "cancel") {
|
249 |
-
$status = "cancel";
|
250 |
-
break;
|
251 |
-
}
|
252 |
-
|
253 |
-
$product = Mage::getModel('catalog/product');
|
254 |
-
$product->load($productId);
|
255 |
-
|
256 |
-
fwrite($fh, $this->ProducttoString($product, "product"));
|
257 |
-
}
|
258 |
-
|
259 |
-
fclose($fh);
|
260 |
-
Mage::log("Notice : Codi Import End : ".$status, null, $this->_logFile);
|
261 |
-
//Clean up
|
262 |
-
unset($products);
|
263 |
-
unset($product);
|
264 |
-
|
265 |
-
if ( $status == "end" )
|
266 |
-
$this->addImportStatus($status, 1);
|
267 |
-
}
|
268 |
-
|
269 |
-
public function ProducttoString( $product , $from )
|
270 |
-
{
|
271 |
-
|
272 |
-
if( $product->isConfigurable() )
|
273 |
-
{
|
274 |
-
return $this->ProducttoStringConfigurable( $product , $from ) ;
|
275 |
-
}
|
276 |
-
else
|
277 |
-
{
|
278 |
-
return $this->ProducttoStringSimple( $product , $from ) ;
|
279 |
-
}
|
280 |
-
}
|
281 |
-
|
282 |
-
public function ProducttoStringConfigurable( $product , $from )
|
283 |
-
{
|
284 |
-
$ProducttoString = '' ;
|
285 |
-
$UsedProductIds = Mage::getModel('catalog/product_type_configurable')->getUsedProductIds($product);
|
286 |
-
|
287 |
-
$ProductDescription = '';
|
288 |
-
if(Mage::getStoreConfig('codi/codi/codincludeshortdescription')=="checked")
|
289 |
-
{
|
290 |
-
$ProductDescription .= $product->getShortDescription();
|
291 |
-
}
|
292 |
-
$ProductDescription .= $product->getDescription() ;
|
293 |
-
//Get Product Attributes Start
|
294 |
-
//$excludeAttr = array() ;
|
295 |
-
$attributes = $product->getAttributes();
|
296 |
-
|
297 |
-
$ProductAttributes = "" ;
|
298 |
-
foreach ($attributes as $attribute) {
|
299 |
-
if ($attribute->getIsVisibleOnFront() && !in_array($attribute->getAttributeCode(), array() )) {
|
300 |
-
$value = $attribute->getFrontend()->getValue($product);
|
301 |
-
if (is_string($value))
|
302 |
-
{
|
303 |
-
if (strlen($value) && $product->hasData($attribute->getAttributeCode()))
|
304 |
-
{
|
305 |
-
$ProductAttributes .= $attribute->getFrontend()->getLabel() . "=" . $value . "|" ;
|
306 |
-
}
|
307 |
-
}
|
308 |
-
}
|
309 |
-
}
|
310 |
-
$ProductAttributes = substr($ProductAttributes, 0, strlen($ProductAttributes)-1 ) ;
|
311 |
-
//Get Product Attributes End
|
312 |
-
|
313 |
-
//******************** Get Tier Price option *********************//
|
314 |
-
|
315 |
-
if(Mage::getStoreConfig('codi/codi/codpublishtieredpricing')=='checked')
|
316 |
-
{
|
317 |
-
$TierPriceAttributes =Mage::helper('codi')->geTierprice($product);
|
318 |
-
$sp="|";
|
319 |
-
if(($ProductAttributes=='') || ($TierPriceAttributes==''))
|
320 |
-
$sp='';
|
321 |
-
|
322 |
-
if($ProductAttributes=='')
|
323 |
-
|
324 |
-
|
325 |
-
$ProductAttributes.= $sp.$TierPriceAttributes;
|
326 |
-
}
|
327 |
-
//************End Tier Price option *************//
|
328 |
-
//************************* Get Categories names Start ***************************
|
329 |
-
//Changed in 3.0.3 removed the category names
|
330 |
-
$CategoriesString = "" ;
|
331 |
-
|
332 |
-
//************************* Get Categories names End ***************************
|
333 |
-
|
334 |
-
foreach($UsedProductIds as $UsedProductid)
|
335 |
-
{
|
336 |
-
$UsedProduct = Mage::getModel('catalog/product')->load($UsedProductid);
|
337 |
-
if( Mage::getStoreConfig('codi/codi/fromchild') )
|
338 |
-
$UsedProductPrice = $UsedProduct->getFinalPrice() ;
|
339 |
-
else
|
340 |
-
$UsedProductPrice = $product->getFinalPrice() ; //default behavior
|
341 |
-
//************************ Get Attributes Start *******************************
|
342 |
-
|
343 |
-
//Extract Attributes
|
344 |
-
|
345 |
-
$ImageURL = $this->mediaurl . "catalog/product" . $product->getImage();
|
346 |
-
|
347 |
-
//Get Item Attributes Start
|
348 |
-
|
349 |
-
$attributes = $UsedProduct->getAttributes();
|
350 |
-
|
351 |
-
$ItemitemAttributes = "" ;
|
352 |
-
$AllowAttributes = $product->getTypeInstance(true)->getConfigurableAttributes($product);
|
353 |
-
foreach ($AllowAttributes as $attribute)
|
354 |
-
{
|
355 |
-
$AttributeCode = $attribute->getProductAttribute()->getAttributeCode() ;
|
356 |
-
$AttributeLabel = $attribute->getProductAttribute()->getFrontend()->getLabel() ;
|
357 |
-
$AttribId = $UsedProduct->getData($AttributeCode) ;
|
358 |
-
|
359 |
-
$AttributeValue = "" ;
|
360 |
-
foreach ( $attribute->getProductAttribute()->getSource()->getAllOptions() as $option )
|
361 |
-
{
|
362 |
-
if( $option['value'] == $AttribId )
|
363 |
-
{
|
364 |
-
$AttributeValue = $option['label'];
|
365 |
-
}
|
366 |
-
}
|
367 |
-
|
368 |
-
$ItemitemAttributes .= $AttributeLabel . "=" . $AttributeValue . "|" ;
|
369 |
-
|
370 |
-
//Get Delta Price Start
|
371 |
-
foreach( $attribute->getPrices() as $addedPrice )
|
372 |
-
{
|
373 |
-
if ( $AttributeValue == $addedPrice['label'])
|
374 |
-
{
|
375 |
-
if( $addedPrice['is_percent'] )
|
376 |
-
$UsedProductPrice += $UsedProductPrice * $addedPrice['pricing_value'] / 100;
|
377 |
-
else
|
378 |
-
$UsedProductPrice += $addedPrice['pricing_value'] ;
|
379 |
-
}
|
380 |
-
}
|
381 |
-
//Get Delta Price End
|
382 |
-
}
|
383 |
-
|
384 |
-
$ItemitemAttributes = substr($ItemitemAttributes, 0, strlen($ItemitemAttributes)-1 );
|
385 |
-
|
386 |
-
|
387 |
-
|
388 |
-
//Get Item Attributes End
|
389 |
-
//************************ Get Attributes End ************************************
|
390 |
-
//************************* Get Reviews Start ***********************
|
391 |
-
//$enablereviews = Mage::getStoreConfig('codi/codi/codenablereviews') ;
|
392 |
-
$Reviews = $this->enablereviews ? $this->getReviews($product->getId()) : '' ;
|
393 |
-
//************************* Get Reviews End *************************
|
394 |
-
|
395 |
-
//************************* Concatenate Product Info Start ***********************
|
396 |
-
$ProducttoString .= "\r\n" . $this->cleanStr( $UsedProduct->getSku() ) ; //ItemID
|
397 |
-
$ProducttoString .= "\t" . "" ; //ItemQty
|
398 |
-
$ProducttoString .= "\t" . "" ; //ItemUom
|
399 |
-
// $ProducttoString .= "\t" . $this->cleanStr( $product->getPrice() ) ; //ItemPrice
|
400 |
-
$ProducttoString .= "\t" . $this->cleanStr( $UsedProductPrice ) ; //ItemPrice
|
401 |
-
$ProducttoString .= "\t" . ""; //ItemDescription
|
402 |
-
$ProducttoString .= "\t" . $this->cleanStr( $product->getProductUrl() ); //ItemLink
|
403 |
-
$ProducttoString .= "\t" . $this->cleanStr( $ItemitemAttributes ) ; //ItemitemAttributes
|
404 |
-
$ProducttoString .= "\t" . ""; //ItemitemGraphic
|
405 |
-
$ProducttoString .= "\t" . $product->getId().'#$#'.$this->cleanStr( $product->getName() ); //ProductName
|
406 |
-
$ProducttoString .= "\t" . "" ; //ProductMfg
|
407 |
-
$ProducttoString .= "\t" . $this->cleanStr( $ProductDescription ) ; //ProductDescription
|
408 |
-
$ProducttoString .= "\t" . $this->cleanStr( $ImageURL ); //ProductGraphic
|
409 |
-
$ProducttoString .= "\t" . $this->cleanStr( $product->getProductUrl() ) ; //ProductLink
|
410 |
-
$ProducttoString .= "\t" . $this->cleanStr( $ProductAttributes ) ; //ProductAttributes
|
411 |
-
$ProducttoString .= "\t" . $this->cleanStr( $CategoriesString ); //Category
|
412 |
-
$ProducttoString .= "\t" . $this->cleanStr( $Reviews ); //Reviews
|
413 |
-
$ProducttoString .= "\t" . $this->cleanStr( $product->getShortDescription() ); //ShortDescription (Quick Overview)
|
414 |
-
//************************* Concatenate Product Info End ************************* cleanStr
|
415 |
-
}
|
416 |
-
unset($ProductDescription);
|
417 |
-
unset($ImageURL);
|
418 |
-
unset($product);
|
419 |
-
unset($ItemitemAttributes);
|
420 |
-
unset($CategoriesString);
|
421 |
-
unset($Reviews);
|
422 |
-
|
423 |
-
|
424 |
-
return $ProducttoString ;
|
425 |
-
}
|
426 |
-
/////////////////////////////////////////// Simple Products ///////////////////////////////////////////////////////////////////
|
427 |
-
public function ProducttoStringSimple( $product , $from )
|
428 |
-
{
|
429 |
-
$ProducttoString = '' ;
|
430 |
-
//Change for short description
|
431 |
-
//$ProductDescription = $product->getDescription() ;
|
432 |
-
$ProductDescription = '';
|
433 |
-
if(Mage::getStoreConfig('codi/codi/codincludeshortdescription')=="checked")
|
434 |
-
{
|
435 |
-
$ProductDescription .= $product->getShortDescription();
|
436 |
-
}
|
437 |
-
$ProductDescription .= $product->getDescription() ;
|
438 |
-
//************************ Get Attributes Start *******************************
|
439 |
-
//Extract Attributes
|
440 |
-
|
441 |
-
$ImageURL = $this->mediaurl . "catalog/product" . $product->getImage();
|
442 |
-
|
443 |
-
//$excludeAttr = array() ;
|
444 |
-
$attributes = $product->getAttributes();
|
445 |
-
$ItemitemAttributes = "" ;
|
446 |
-
foreach ($attributes as $attribute) {
|
447 |
-
if ($attribute->getIsVisibleOnFront() && !in_array($attribute->getAttributeCode(), array() )) {
|
448 |
-
$value = $attribute->getFrontend()->getValue($product);
|
449 |
-
if (is_string($value))
|
450 |
-
{
|
451 |
-
if (strlen($value) && $product->hasData($attribute->getAttributeCode()))
|
452 |
-
{
|
453 |
-
$ItemitemAttributes .= $attribute->getFrontend()->getLabel() . "=" . $value . "|" ;
|
454 |
-
}
|
455 |
-
}
|
456 |
-
}
|
457 |
-
}
|
458 |
-
$ItemitemAttributes = substr($ItemitemAttributes, 0, strlen($ItemitemAttributes)-1 ) ;
|
459 |
-
//************************ Get Attributes End ************************************
|
460 |
-
//******************** Get Tier Price option *********************//
|
461 |
-
|
462 |
-
if(Mage::getStoreConfig('codi/codi/codpublishtieredpricing')=='checked')
|
463 |
-
{
|
464 |
-
$TierPriceAttributes =Mage::helper('codi')->geTierprice($product);
|
465 |
-
$sp="|";
|
466 |
-
if(($ItemitemAttributes=='') || ($TierPriceAttributes==''))
|
467 |
-
$sp='';
|
468 |
-
|
469 |
-
$ItemitemAttributes.= $sp.$TierPriceAttributes;
|
470 |
-
}
|
471 |
-
//************End Tier Price option *************//
|
472 |
-
|
473 |
-
|
474 |
-
|
475 |
-
//************************* Get Categories names Start ***************************
|
476 |
-
//Changed into 3.0.3 removed the category name
|
477 |
-
|
478 |
-
$CategoriesString = "" ;
|
479 |
-
|
480 |
-
//************************* Get Categories names End ***************************
|
481 |
-
|
482 |
-
//************************* Get Reviews Start ***********************
|
483 |
-
$Reviews = $this->enablereviews ? $this->getReviews($product->getId()) : '' ;
|
484 |
-
//************************* Get Reviews End *************************
|
485 |
-
|
486 |
-
//************************* Concatenate Product Info Start ***********************
|
487 |
-
|
488 |
-
$ProducttoString .= "\r\n" . $this->cleanStr( $product->getSku() ) ; //ItemID
|
489 |
-
$ProducttoString .= "\t" . "" ; //ItemQty
|
490 |
-
$ProducttoString .= "\t" . "" ; //ItemUom
|
491 |
-
$ProducttoString .= "\t" . $this->cleanStr( $product->getFinalPrice() ) ; //ItemPrice
|
492 |
-
$ProducttoString .= "\t" . ""; //ItemDescription
|
493 |
-
$ProducttoString .= "\t" . $this->cleanStr( $product->getProductUrl() ); //ItemLink
|
494 |
-
$ProducttoString .= "\t" . ""; //ItemitemAttributes
|
495 |
-
$ProducttoString .= "\t" . ""; //ItemitemGraphic
|
496 |
-
$ProducttoString .= "\t" . $product->getId().'#$#'.$this->cleanStr( $product->getName() ); //ProductName
|
497 |
-
$ProducttoString .= "\t" . "" ; //ProductMfg
|
498 |
-
$ProducttoString .= "\t" . $this->cleanStr( $ProductDescription ) ; //ProductDescription
|
499 |
-
$ProducttoString .= "\t" . $this->cleanStr( $ImageURL ); //ProductGraphic
|
500 |
-
$ProducttoString .= "\t" . $this->cleanStr( $product->getProductUrl() ) ; //ProductLink
|
501 |
-
$ProducttoString .= "\t" . $this->cleanStr( $ItemitemAttributes ) ; //ProductAttributes
|
502 |
-
$ProducttoString .= "\t" . $this->cleanStr( $CategoriesString ); //Category
|
503 |
-
$ProducttoString .= "\t" . $this->cleanStr( $Reviews ); //Reviews
|
504 |
-
$ProducttoString .= "\t" . $this->cleanStr( $product->getShortDescription() ); //ShortDescription (Quick Overview)
|
505 |
-
//************************* Concatenate Product Info End ************************* cleanStr
|
506 |
-
|
507 |
-
unset($ProductDescription);
|
508 |
-
unset($ImageURL);
|
509 |
-
unset($product);
|
510 |
-
unset($ItemitemAttributes);
|
511 |
-
unset($CategoriesString);
|
512 |
-
unset($Reviews);
|
513 |
-
|
514 |
-
return $ProducttoString ;
|
515 |
-
}
|
516 |
-
|
517 |
-
public function cleanStr($localstr)
|
518 |
-
{
|
519 |
-
//$specialChar=array(''=>'',''=>'');
|
520 |
-
|
521 |
-
$localstr = str_replace("\t","", $localstr ) ;
|
522 |
-
$localstr = str_replace("\r\n","<br>", $localstr ) ;
|
523 |
-
$localstr = str_replace("\r","<br>", $localstr ) ;
|
524 |
-
$localstr = str_replace("\n","<br>", $localstr ) ;
|
525 |
-
$localstr = str_replace("","",$localstr) ;
|
526 |
-
//Changed for special character
|
527 |
-
|
528 |
-
|
529 |
-
|
530 |
-
return $localstr ;
|
531 |
-
}
|
532 |
-
|
533 |
-
public function getReviews( $productid )
|
534 |
-
{
|
535 |
-
$reviewsCollection = $this->reviewsModel->getCollection()
|
536 |
-
->addStoreFilter($this->StoreId)
|
537 |
-
->addStatusFilter('approved')
|
538 |
-
->addEntityFilter('product', $productid)
|
539 |
-
->setDateOrder();
|
540 |
-
|
541 |
-
$Reviews = "" ;
|
542 |
-
foreach($reviewsCollection as $review)
|
543 |
-
{
|
544 |
-
$ratingCollection = $this->ratingModel
|
545 |
-
->getResourceCollection()
|
546 |
-
->setReviewFilter($review->getReviewId())
|
547 |
-
->setStoreFilter($this->StoreId)
|
548 |
-
->addRatingInfo($this->StoreId)
|
549 |
-
->load();
|
550 |
-
$Reviews .= "<p><b>".$review->getTitle()."(". $review->getNickname() .")</b><br>".$review->getDetail()."</p>" ;
|
551 |
-
}
|
552 |
-
return $Reviews ;
|
553 |
-
}
|
554 |
-
|
555 |
-
public function checkvalidity()
|
556 |
-
{
|
557 |
-
$userid = Mage::getStoreConfig('codi/codi/codusername') ;
|
558 |
-
$password = Mage::getStoreConfig('codi/codi/codpassword') ;
|
559 |
-
$url = "https://webservices.catalog-on-demand.com/smanager/api.do?Operation=ValidateUser&ResponseGroups=All&FunctionGroups=All" ;
|
560 |
-
$paramsarray = array('UserID' => $userid ,
|
561 |
-
'Password' => $password );
|
562 |
-
$Responsemsg = $this->Call( $url, $paramsarray );
|
563 |
-
if( $Responsemsg )
|
564 |
-
return $Responsemsg->Message=="OK" ? true : false ;
|
565 |
-
else
|
566 |
-
return false ;
|
567 |
-
}
|
568 |
-
|
569 |
-
//////////////////////////////////// Calling Start /////////////////////////////////////////////////////
|
570 |
-
public function CallusingZend( $url, $paramsarray )
|
571 |
-
{
|
572 |
-
$client = new Zend_Http_Client();
|
573 |
-
$client->setUri($url);
|
574 |
-
$client->setParameterPost('UserID', $this->userid);
|
575 |
-
$client->setParameterPost('Password', $this->password);
|
576 |
-
|
577 |
-
$mystr = '';
|
578 |
-
foreach($paramsarray as $key=>$value)
|
579 |
-
{
|
580 |
-
$client->setParameterPost($key, $value);
|
581 |
-
$mystr .= $key . $value ;
|
582 |
-
}
|
583 |
-
|
584 |
-
$response = $client->request('POST');
|
585 |
-
$result = $response->getBody() ;
|
586 |
-
return $result;
|
587 |
-
}
|
588 |
-
|
589 |
-
public function CallusingCurl( $url, $paramsarray )
|
590 |
-
{
|
591 |
-
$poststr = '';
|
592 |
-
foreach($paramsarray as $key=>$value)
|
593 |
-
{
|
594 |
-
$poststr .= $key ."=". urlencode($value) ."&";
|
595 |
-
}
|
596 |
-
|
597 |
-
$ch = curl_init();
|
598 |
-
curl_setopt($ch, CURLOPT_URL,$url);
|
599 |
-
curl_setopt($ch, CURLOPT_FAILONERROR, 1);
|
600 |
-
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
|
601 |
-
curl_setopt($ch, CURLOPT_POST,1);
|
602 |
-
curl_setopt($ch, CURLOPT_POSTFIELDS, $poststr);
|
603 |
-
$result = curl_exec($ch);
|
604 |
-
curl_close($ch);
|
605 |
-
|
606 |
-
return $result;
|
607 |
-
}
|
608 |
-
|
609 |
-
public function Call( $url, $paramsarray )
|
610 |
-
{
|
611 |
-
$result = "" ;
|
612 |
-
try
|
613 |
-
{
|
614 |
-
$result = $this->CallusingZend( $url, $paramsarray );
|
615 |
-
}
|
616 |
-
catch(Exception $e)
|
617 |
-
{
|
618 |
-
try
|
619 |
-
{
|
620 |
-
$result = $this->CallusingCurl( $url, $paramsarray );
|
621 |
-
}
|
622 |
-
catch(Exception $e){}
|
623 |
-
}
|
624 |
-
|
625 |
-
$Responsemsg = false ;
|
626 |
-
|
627 |
-
return $result ;
|
628 |
-
}
|
629 |
-
//////////////////////////////////// Calling End /////////////////////////////////////////////////////
|
630 |
-
public function getComment($datetime='')
|
631 |
-
{
|
632 |
-
$Comment = "";
|
633 |
-
////////////////////////////////////////////////////////////
|
634 |
-
$extension_version = $this->version;//(string) Mage::getConfig()->getNode()->modules->Mage_Codi->version;
|
635 |
-
$app_version = Mage::getVersion();
|
636 |
-
$php_version = phpversion();
|
637 |
-
|
638 |
-
foreach (Mage::app()->getWebsites() as $website)
|
639 |
-
{
|
640 |
-
$defaultGroup = $website->getDefaultGroup();
|
641 |
-
$StoreId = $defaultGroup->getDefaultStoreId();
|
642 |
-
}
|
643 |
-
|
644 |
-
$design = Mage::getSingleton('core/design')->loadChange($StoreId);
|
645 |
-
$package = $design->getPackage();
|
646 |
-
$default_theme = $design->getTheme();
|
647 |
-
|
648 |
-
if ( $package == "" && $default_theme == "" ){
|
649 |
-
|
650 |
-
$package = Mage::getStoreConfig('design/package/name', $StoreId);
|
651 |
-
$default_theme = Mage::getStoreConfig('design/theme/default', $StoreId);
|
652 |
-
}
|
653 |
-
|
654 |
-
if ( $package == "" ) $package = "default";
|
655 |
-
if ( $default_theme == "" ) $default_theme = "default";
|
656 |
-
|
657 |
-
$theme = "default";
|
658 |
-
if ( $package != "default" || $default_theme != "default" )
|
659 |
-
$theme = $package."/".$default_theme;
|
660 |
-
|
661 |
-
$codbgcheck = ( Mage::getStoreConfig('codi/codi/codbgcheck') == '1' )?'Yes':'No' ;
|
662 |
-
|
663 |
-
$enablefreshflyers = ( Mage::getStoreConfig('codi/codi/enablefreshflyers') == 'checked' )?'Yes':'No' ;
|
664 |
-
$enablereviews = ( Mage::getStoreConfig('codi/codi/codenablereviews') == 'checked' )?'Yes':'No' ;
|
665 |
-
$fromchild = ( Mage::getStoreConfig('codi/codi/fromchild') == 'checked' )?'Yes':'No' ;
|
666 |
-
|
667 |
-
$codflyerlinkimgurl = Mage::getStoreConfig('codi/codi/codflyerlinkimgurl') ;
|
668 |
-
$codflyerlinkimg = ( Mage::getStoreConfig('codi/codi/codflyerlinkimg') == 'Custom' )? $codflyerlinkimgurl:'Default';
|
669 |
-
$codflyerlinkimgalt = Mage::getStoreConfig('codi/codi/codflyerlinkimgalt') ;
|
670 |
-
|
671 |
-
$codbeforename = ( Mage::getStoreConfig('codi/codi/codbeforename') == 'checked' )?'Yes':'No' ;
|
672 |
-
$codaftername = ( Mage::getStoreConfig('codi/codi/codaftername') == 'checked' )?'Yes':'No' ;
|
673 |
-
$codbeforeemailto = ( Mage::getStoreConfig('codi/codi/codbeforeemailto') == 'checked' )?'Yes':'No' ;
|
674 |
-
$codafteremailto = ( Mage::getStoreConfig('codi/codi/codafteremailto') == 'checked' )?'Yes':'No' ;
|
675 |
-
$codbeforeOR = ( Mage::getStoreConfig('codi/codi/codbeforeOR') == 'checked' )?'Yes':'No' ;
|
676 |
-
$codafterOR = ( Mage::getStoreConfig('codi/codi/codafterOR') == 'checked' )?'Yes':'No' ;
|
677 |
-
$codbeforeoverview = ( Mage::getStoreConfig('codi/codi/codbeforeoverview') == 'checked' ) ?'Yes':'No';
|
678 |
-
$codafteroverview = ( Mage::getStoreConfig('codi/codi/codafteroverview') == 'checked' )?'Yes':'No';
|
679 |
-
//Changed for include short description
|
680 |
-
$includeshortdescription = (Mage::getStoreConfig('codi/codi/codincludeshortdescription')== 'checked' )?'Yes':'No';
|
681 |
-
|
682 |
-
$Comment = "App extension version: ".$extension_version." \r\n";
|
683 |
-
$Comment .= "Magento version: ".$app_version." \r\n";
|
684 |
-
$Comment .= "PHP: ".$php_version." \r\n";
|
685 |
-
$Comment .= "Theme: ".$theme." \r\n";
|
686 |
-
$Comment .= "Create data file using background process: ".$codbgcheck." \r\n";
|
687 |
-
$Comment .= "Enable Always Fresh Flyers: ".$enablefreshflyers." \r\n";
|
688 |
-
$Comment .= "Include Short Description: ".$includeshortdescription." \r\n";
|
689 |
-
$Comment .= "Enable Reviews: ".$enablereviews." \r\n";
|
690 |
-
$Comment .= "Get price from associated products: ".$fromchild." \r\n";
|
691 |
-
$Comment .= "Image to be used for flyer link: ".$codflyerlinkimg." \r\n";
|
692 |
-
$Comment .= "Alt text for flyer link image: ".$codflyerlinkimgalt." \r\n";
|
693 |
-
$Comment .= "Display options: \r\n";
|
694 |
-
$Comment .= " Display before product name: ".$codbeforename." \r\n";
|
695 |
-
$Comment .= " Display after product name: ".$codaftername." \r\n";
|
696 |
-
$Comment .= " Display before Email to a friend: ".$codbeforeemailto." \r\n";
|
697 |
-
$Comment .= " Display after Email to a friend: ".$codafteremailto." \r\n";
|
698 |
-
$Comment .= " Display before OR: ".$codbeforeOR." \r\n";
|
699 |
-
$Comment .= " Display after OR: ".$codafterOR." \r\n";
|
700 |
-
$Comment .= " Display before Quick Overview: ".$codbeforeoverview." \r\n";
|
701 |
-
$Comment .= " Display after Quick Overview: ".$codafteroverview." \r\n";
|
702 |
-
|
703 |
-
//Change for site url
|
704 |
-
$siteurl = Mage::getUrl('/');
|
705 |
-
$Comment .="Site Url: ".$siteurl."\r\n";
|
706 |
-
$datafilelaunch = Mage::getStoreConfig('codi/codi/coddatafilelaunch');
|
707 |
-
if($datafilelaunch=='magento')
|
708 |
-
{
|
709 |
-
$datafilelaunch='cronjob';
|
710 |
-
|
711 |
-
}
|
712 |
-
|
713 |
-
//code for version 2.2.16
|
714 |
-
|
715 |
-
$Comment .="Data File Launch Mode: ".$datafilelaunch."\r\n";
|
716 |
-
|
717 |
-
$url = Mage::getUrl('codi/nsync') ;
|
718 |
-
$pos = strrpos ($url , 'key') ;
|
719 |
-
if ( $pos != 0 )
|
720 |
-
$cronjoburl = substr( $url , 0 , $pos ) ;
|
721 |
-
else
|
722 |
-
$cronjoburl = $url;
|
723 |
-
|
724 |
-
if(($datafilelaunch=='cronjob') || ($datafilelaunch=='manual'))
|
725 |
-
{
|
726 |
-
$Comment .="Cron job command: wget ".$cronjoburl."\r\n";
|
727 |
-
}
|
728 |
-
else{
|
729 |
-
$waitforminute=Mage::getStoreConfig('codi/codi/codwaitforminute')/60;
|
730 |
-
$Comment .="WaitFor: ".number_format($waitforminute,2,'.','')."\r\n";
|
731 |
-
|
732 |
-
}
|
733 |
-
|
734 |
-
$Comment .="Extension Name: ".$this->extensionName."\r\n";
|
735 |
-
$Comment .="Date and time of most recent data file: ".$datetime."\r\n";
|
736 |
-
//Changed for Tier Price options
|
737 |
-
|
738 |
-
$publishtieredpricing=Mage::getStoreConfig('codi/codi/codpublishtieredpricing');
|
739 |
-
if($publishtieredpricing=='checked')
|
740 |
-
{
|
741 |
-
$codquantity=Mage::getStoreConfig('codi/codi/codquantity');
|
742 |
-
$codprice=Mage::getStoreConfig('codi/codi/codprice');
|
743 |
-
$codsavings=Mage::getStoreConfig('codi/codi/codsavings');
|
744 |
-
$publish=($publishtieredpricing == 'checked' )?'Yes':'No';
|
745 |
-
$Comment .= "Tiered Pricing Options: \r\n";
|
746 |
-
$Comment .= " Publish tiered pricing: ".$publish." \r\n";
|
747 |
-
$Comment .= " Label for quantity column: ".$codquantity." \r\n";
|
748 |
-
$Comment .= " Label for price column: ".$codprice." \r\n";
|
749 |
-
$Comment .= " Label for savings: ".$codsavings." \r\n";
|
750 |
-
|
751 |
-
}
|
752 |
-
|
753 |
-
|
754 |
-
return $Comment;
|
755 |
-
////////////////////////////////////////////////////////////
|
756 |
-
}
|
757 |
-
//code for version 2.2.16
|
758 |
-
public function new_run_codi_import($basePath)
|
759 |
-
{
|
760 |
-
|
761 |
-
Mage::log("Notice : Codi Import Start", null, $this->_logFile);
|
762 |
-
|
763 |
-
ini_set('memory_limit','1024M');
|
764 |
-
|
765 |
-
$this->InitImportStatuses();
|
766 |
-
|
767 |
-
$fh = fopen($basePath.'CoDzip/CoDfiles/temp.txt', 'w');
|
768 |
-
|
769 |
-
if ( !$fh )
|
770 |
-
{
|
771 |
-
Mage::log("ERROR : Cann't open file for building data file:".$basePath, null, $this->_logFile);
|
772 |
-
$this->addImportStatus("fileerror", 1);
|
773 |
-
return;
|
774 |
-
}
|
775 |
-
|
776 |
-
fwrite($fh, "itemNumber\titemQty\titemUom\titemPrice\titemDescription\titemLink\titemAttributes\titemGraphic\tproductName\tproductMfg\tproductDescription\tproductGraphic\tproductLink\tproductAttributes\tCategory\tReviews\tSupplementalInfo");
|
777 |
-
|
778 |
-
$products = Mage::getModel('catalog/product')->getCollection();
|
779 |
-
$products->addAttributeToFilter('status', 1);//enabled
|
780 |
-
$products->addAttributeToFilter('visibility', 4);//catalog, search
|
781 |
-
$products->addAttributeToSelect('*');
|
782 |
-
|
783 |
-
$prodIds = $products->getAllIds();
|
784 |
-
|
785 |
-
$this->addImportStatus("start");
|
786 |
-
|
787 |
-
$status = "end";
|
788 |
-
$i='0';
|
789 |
-
try{
|
790 |
-
foreach($prodIds as $productId)
|
791 |
-
{
|
792 |
-
set_time_limit(20);
|
793 |
-
$message = $this->getImportStatuses();
|
794 |
-
if ( isset($message) && $message['message'] == "cancel") {
|
795 |
-
$status = "cancel";
|
796 |
-
break;
|
797 |
-
}
|
798 |
-
$product = Mage::getModel('catalog/product');
|
799 |
-
$product->load($productId);
|
800 |
-
Mage::log("Notice : Codi Import Products :".$i, null, $this->_logFile);
|
801 |
-
fwrite($fh, $this->ProducttoString($product, "product"));
|
802 |
-
$i++;
|
803 |
-
}
|
804 |
-
}
|
805 |
-
catch (Exception $e)
|
806 |
-
{
|
807 |
-
Mage::log("Notice : Codi Import Products Exception :".$e->getMessage(), null, $this->_logFile);
|
808 |
-
}
|
809 |
-
//clean up the memory
|
810 |
-
unset($product);
|
811 |
-
unset($prodIds);
|
812 |
-
unset($products);
|
813 |
-
|
814 |
-
fclose($fh);
|
815 |
-
Mage::log("Notice : Codi Import End : ".$status, null, $this->_logFile);
|
816 |
-
|
817 |
-
if ( $status == "end" )
|
818 |
-
$this->addImportStatus($status, 1);
|
819 |
-
|
820 |
-
}
|
821 |
-
//code for create CatalogSection.txt
|
822 |
-
public function createCatalogSection()
|
823 |
-
{
|
824 |
-
Mage::log("Notice : Create Catalog Section Start: ", null, $this->_logFile);
|
825 |
-
|
826 |
-
$helper=Mage::helper('codi');
|
827 |
-
$dir = dirname(__FILE__);
|
828 |
-
$_baseDirArray = explode("app", $dir);
|
829 |
-
$basePath = $_baseDirArray[0];
|
830 |
-
$progress=100;
|
831 |
-
/*
|
832 |
-
//Create object for Codi Model
|
833 |
-
//Create table Codi Catalog Section for insert category hirarchy path
|
834 |
-
*/
|
835 |
-
$catalogSectionModel=Mage::getModel('codi/codi');
|
836 |
-
$catalogSectionModel->InitCatalogSectionTable();
|
837 |
-
|
838 |
-
$collection = Mage::getModel('catalog/category')->getCollection()
|
839 |
-
->setStoreId('1')
|
840 |
-
->addAttributeToSelect('name')
|
841 |
-
->addAttributeToSelect('is_active')
|
842 |
-
->addAttributeToFilter('level', array('eq' => 2))
|
843 |
-
->addAttributeToFilter('is_active', array('eq' => 1))
|
844 |
-
->addAttributeToSort('position', 'asc');
|
845 |
-
//echo $collection->getSelect();
|
846 |
-
|
847 |
-
|
848 |
-
$i=1;
|
849 |
-
$count=count($collection);
|
850 |
-
if($count>0)
|
851 |
-
{
|
852 |
-
|
853 |
-
foreach($collection as $category)
|
854 |
-
{
|
855 |
-
$name=$category->getName();
|
856 |
-
$id=$category->getId();
|
857 |
-
$file = $basePath.'/CoDzip/CoDfiles/CatalogSection.txt';
|
858 |
-
file_put_contents($file,"sec_Project\tsec_Sequence\tsec_HierarchyPath\tsec_Flag\n");
|
859 |
-
$stringe.=$helper->drawItem($category,1,$name,$i);
|
860 |
-
file_put_contents($file,$stringe,FILE_APPEND);
|
861 |
-
$i++;
|
862 |
-
}
|
863 |
-
}
|
864 |
-
if($count==0)
|
865 |
-
{
|
866 |
-
$progress=0;
|
867 |
-
}
|
868 |
-
|
869 |
-
//clean up the memory
|
870 |
-
unset($catalogSectionModel);
|
871 |
-
unset($collection);
|
872 |
-
unset($stringe);
|
873 |
-
|
874 |
-
Mage::log("Notice : Create Catalog Section End: ", null, $this->_logFile);
|
875 |
-
return $progress;
|
876 |
-
}
|
877 |
-
//code for create Catalog Project
|
878 |
-
public function createCatalogProject($fromcron=0)
|
879 |
-
{
|
880 |
-
$dir = dirname(__FILE__);
|
881 |
-
$_baseDirArray = explode("app", $dir);
|
882 |
-
$basePath = $_baseDirArray[0];
|
883 |
-
Mage::log("Notice : Create Catalog Project Start", null, $this->_logFile);
|
884 |
-
|
885 |
-
ini_set('memory_limit','1024M');
|
886 |
-
|
887 |
-
$this->InitImportStatuses();
|
888 |
-
|
889 |
-
$fh = fopen($basePath.'CoDzip/CoDfiles/CatalogProject.txt', 'w');
|
890 |
-
|
891 |
-
if ( !$fh )
|
892 |
-
{
|
893 |
-
Mage::log("ERROR : Cann't open file for building data file:".$basePath, null, $this->_logFile);
|
894 |
-
return;
|
895 |
-
}
|
896 |
-
|
897 |
-
fwrite($fh, "proj_Key\tproj_ProdName\tproj_Sequence\tproj_Name\tproj_HierarchyPath\tproj_Flag\tproj_ProdLayout");
|
898 |
-
|
899 |
-
$products = Mage::getModel('catalog/product')->getCollection();
|
900 |
-
$products->addAttributeToFilter('status', 1);//enabled
|
901 |
-
$products->addAttributeToFilter('visibility', 4);//catalog, search
|
902 |
-
$products->addAttributeToSelect('*');
|
903 |
-
|
904 |
-
$prodIds = $products->getAllIds();
|
905 |
-
$totalproduct=count($prodIds);
|
906 |
-
$this->addImportStatus("start");
|
907 |
-
|
908 |
-
$status = "end";
|
909 |
-
$i='0';
|
910 |
-
|
911 |
-
try{
|
912 |
-
|
913 |
-
foreach($prodIds as $productId)
|
914 |
-
{
|
915 |
-
set_time_limit(20);
|
916 |
-
$message = $this->getImportStatuses();
|
917 |
-
if ( isset($message) && $message['message'] == "cancel") {
|
918 |
-
$status = "cancel";
|
919 |
-
break;
|
920 |
-
}
|
921 |
-
$product = Mage::getModel('catalog/product');
|
922 |
-
$product->load($productId);
|
923 |
-
Mage::log("Notice : Codi Import Products :".$i, null, $this->_logFile);
|
924 |
-
fwrite($fh, $this->CatalogProjucttoString($product, "product"));
|
925 |
-
$i++;
|
926 |
-
|
927 |
-
}
|
928 |
-
//Change for zip code if not call from cronjob
|
929 |
-
if($fromcron==0)
|
930 |
-
{
|
931 |
-
$DataFile = 'CoDMagento';
|
932 |
-
Mage::helper('codi/createzip')->createimportzip($DataFile);
|
933 |
-
}
|
934 |
-
}
|
935 |
-
catch (Exception $e)
|
936 |
-
{
|
937 |
-
return 'error';
|
938 |
-
Mage::log("Notice : Codi Catalog Project Exception :".$e->getMessage(), null, $this->_logFile);
|
939 |
-
}
|
940 |
-
//clean up the memory
|
941 |
-
unset($products);
|
942 |
-
unset($prodIds);
|
943 |
-
unset($product);
|
944 |
-
fclose($fh);
|
945 |
-
$progress='10';
|
946 |
-
Mage::log("Notice :Codi Catalog Project End : ".$status, null, $this->_logFile);
|
947 |
-
|
948 |
-
return $progress;
|
949 |
-
}
|
950 |
-
//Code for Catalog projuct section
|
951 |
-
public function CatalogProjucttoString( $product , $from )
|
952 |
-
{
|
953 |
-
|
954 |
-
if( $product->isConfigurable() )
|
955 |
-
{
|
956 |
-
return $this->ProjucttoStringConfigurable( $product , $from ) ;
|
957 |
-
}
|
958 |
-
else
|
959 |
-
{
|
960 |
-
return $this->ProjucttoStringSimple( $product , $from ) ;
|
961 |
-
}
|
962 |
-
}
|
963 |
-
|
964 |
-
public function ProjucttoStringConfigurable( $product , $from )
|
965 |
-
{
|
966 |
-
//get All associated products
|
967 |
-
$UsedProductIds = Mage::getModel('catalog/product_type_configurable')->getUsedProductIds($product);
|
968 |
-
$countUsedProductIds=count($UsedProductIds);
|
969 |
-
if($countUsedProductIds>0)
|
970 |
-
{
|
971 |
-
ini_set('memory_limit','1024M');
|
972 |
-
$ProducttoString = '' ;
|
973 |
-
//************************* Get Categories names Start ***************************
|
974 |
-
$categories = $product->getCategoryIds();
|
975 |
-
$CategoriesString = "" ;
|
976 |
-
$helper=Mage::helper('codi');
|
977 |
-
$catelogSectionModel=Mage::getModel('codi/codi');
|
978 |
-
foreach($categories as $k => $_category_id){
|
979 |
-
set_time_limit(20);
|
980 |
-
$_cat = Mage::getModel('catalog/category')->load($_category_id);
|
981 |
-
if(($_cat->getName() != '') && ($_cat->getIsActive() == 1) && ($_cat->getName() != 'Root Catalog') && ((string)$_cat->getLevel() != '1') && ($_cat->getParentId() > 1 ) )
|
982 |
-
{
|
983 |
-
$data=$catelogSectionModel->isCatalogSectionStart($_category_id);
|
984 |
-
$CategoriesString=$data['category_hirarchy_path'];
|
985 |
-
//code for product position
|
986 |
-
$position=$helper->productPostion($_category_id,$product->getId());
|
987 |
-
if ($CategoriesString==false) $CategoriesString = 'Uncategorized' ;
|
988 |
-
//************************* Concatenate Product Info Start ***********************
|
989 |
-
$ProducttoString .= "\r\n" . $product->getId().'#$#'. $this->cleanStr( $product->getName()); //ProductKey
|
990 |
-
$ProducttoString .= "\t" . $product->getId().'#$#'.$this->cleanStr( $product->getName()); //Product Name
|
991 |
-
$ProducttoString .= "\t" . $this->cleanStr( $position ) ; //Prod Sequence
|
992 |
-
$ProducttoString .= "\t" . $this->cleanStr('
|
993 |
-
$ProducttoString .= "\t" . $this->cleanStr( $CategoriesString ); //Hirarachi Path
|
994 |
-
$ProducttoString .= "\t" . $this->cleanStr('');//Proj Flag
|
995 |
-
$ProducttoString .= "\t" . $this->cleanStr(''); //Proj Prod layout
|
996 |
-
//************************* Concatenate Product Info End ************************* cleanStr
|
997 |
-
|
998 |
-
}
|
999 |
-
}
|
1000 |
-
//Clean up
|
1001 |
-
unset($categories);
|
1002 |
-
unset($catelogSectionModel);
|
1003 |
-
unset($CategoriesString);
|
1004 |
-
unset($position);
|
1005 |
-
unset($product);
|
1006 |
-
}
|
1007 |
-
else
|
1008 |
-
{
|
1009 |
-
$ProducttoString='';
|
1010 |
-
}
|
1011 |
-
|
1012 |
-
|
1013 |
-
return $ProducttoString ;
|
1014 |
-
}
|
1015 |
-
|
1016 |
-
/////////////////////////////////////////// Simple Products ///////////////////////////////////////////////////////////////////
|
1017 |
-
public function ProjucttoStringSimple( $product , $from )
|
1018 |
-
{
|
1019 |
-
ini_set('memory_limit','1024M');
|
1020 |
-
$ProducttoString = '' ;
|
1021 |
-
//************************* Get Categories names Start ***************************
|
1022 |
-
$categories = $product->getCategoryIds();
|
1023 |
-
$CategoriesString = "" ;
|
1024 |
-
$catelogSectionModel=Mage::getModel('codi/codi');
|
1025 |
-
$helper=Mage::helper('codi');
|
1026 |
-
foreach($categories as $k => $_category_id){
|
1027 |
-
set_time_limit(20);
|
1028 |
-
//Code for add category hirarchi_path
|
1029 |
-
$_cat = Mage::getModel('catalog/category')->load($_category_id);
|
1030 |
-
if(($_cat->getName() != '') && ($_cat->getIsActive() == 1) && ($_cat->getName() != 'Root Catalog') && ((string)$_cat->getLevel() != '1') && ($_cat->getParentId() > 1 ) )
|
1031 |
-
{
|
1032 |
-
$data=$catelogSectionModel->isCatalogSectionStart($_category_id);
|
1033 |
-
$CategoriesString=$data['category_hirarchy_path'];
|
1034 |
-
//code for product position
|
1035 |
-
$position=$helper->productPostion($_category_id,$product->getId());
|
1036 |
-
|
1037 |
-
if ($CategoriesString == false ) $CategoriesString = 'Uncategorized' ;
|
1038 |
-
//************************* Concatenate Product Info Start ***********************
|
1039 |
-
$ProducttoString .= "\r\n" . $product->getId().'#$#'.$this->cleanStr( $product->getName()); //ProductKey
|
1040 |
-
$ProducttoString .= "\t" . $product->getId().'#$#'.$this->cleanStr( $product->getName()); //Product Name
|
1041 |
-
$ProducttoString .= "\t" . $this->cleanStr($position) ; //Prod Sequence
|
1042 |
-
$ProducttoString .= "\t" . $this->cleanStr('
|
1043 |
-
$ProducttoString .= "\t" . $this->cleanStr( $CategoriesString ); //Hirarachi Path
|
1044 |
-
$ProducttoString .= "\t" . $this->cleanStr('');//Proj Flag
|
1045 |
-
$ProducttoString .= "\t" . $this->cleanStr(''); //Proj Prod layout
|
1046 |
-
//************************* Concatenate Product Info End ************************* cleanStr
|
1047 |
-
}
|
1048 |
-
}
|
1049 |
-
//Clean up
|
1050 |
-
unset($categories);
|
1051 |
-
unset($catelogSectionModel);
|
1052 |
-
unset($CategoriesString);
|
1053 |
-
unset($position);
|
1054 |
-
unset($product);
|
1055 |
-
|
1056 |
-
return $ProducttoString ;
|
1057 |
-
}
|
1058 |
-
//Functions for Codi CatalogSection Table
|
1059 |
-
public function InitCatalogSectionTable(){
|
1060 |
-
|
1061 |
-
$write = Mage::getSingleton('core/resource')->getConnection('core_write');
|
1062 |
-
|
1063 |
-
$write->query("DROP TABLE IF EXISTS codi_catalog_section");
|
1064 |
-
$write->query("CREATE TABLE codi_catalog_section(
|
1065 |
-
category_id int(11) NOT NULL PRIMARY KEY,
|
1066 |
-
category_hirarchy_path text)"
|
1067 |
-
);
|
1068 |
-
}
|
1069 |
-
|
1070 |
-
public function existCatalogSectionTable(){
|
1071 |
-
|
1072 |
-
$write = Mage::getSingleton('core/resource')->getConnection('core_write');
|
1073 |
-
|
1074 |
-
$write->query("CREATE TABLE IF NOT EXISTS codi_catalog_section(
|
1075 |
-
category_id int(11) NOT NULL PRIMARY KEY,
|
1076 |
-
category_hirarchy_path text)"
|
1077 |
-
);
|
1078 |
-
|
1079 |
-
}
|
1080 |
-
|
1081 |
-
public function addCatalogSection( $category_id=1, $category_hirarchy_path = 'uncategorized' ){
|
1082 |
-
|
1083 |
-
$this->existCatalogSectionTable();
|
1084 |
-
|
1085 |
-
$write = Mage::getSingleton('core/resource')->getConnection('core_write');
|
1086 |
-
$query = "insert into codi_catalog_section (category_id, category_hirarchy_path) values('".$category_id."', '".$category_hirarchy_path."')";
|
1087 |
-
$write->query($query);
|
1088 |
-
}
|
1089 |
-
public function deleteCatalogSectionTable(){
|
1090 |
-
|
1091 |
-
$this->existCatalogSectionTable();
|
1092 |
-
|
1093 |
-
$write = Mage::getSingleton('core/resource')->getConnection('core_write');
|
1094 |
-
$query = "delete from codi_catalog_section";
|
1095 |
-
$write->query($query);
|
1096 |
-
}
|
1097 |
-
|
1098 |
-
public function isCatalogSectionStart($category_id=1){
|
1099 |
-
|
1100 |
-
$this->existCatalogSectionTable();
|
1101 |
-
|
1102 |
-
$read= Mage::getSingleton('core/resource')->getConnection('core_read');
|
1103 |
-
|
1104 |
-
$query = "select category_hirarchy_path from codi_catalog_section where category_id = '".$category_id."' order by category_id desc limit 1";
|
1105 |
-
|
1106 |
-
$result = $read->query($query);
|
1107 |
-
|
1108 |
-
if($row = $result->fetch() ){
|
1109 |
-
|
1110 |
-
return $row;
|
1111 |
-
}
|
1112 |
-
|
1113 |
-
return false;
|
1114 |
-
}
|
1115 |
-
|
1116 |
-
|
1117 |
-
|
1118 |
-
}
|
1 |
+
<?php
|
2 |
+
|
3 |
+
class Mage_Codi_Model_Codi extends Mage_Core_Model_Abstract
|
4 |
+
{
|
5 |
+
public $target ;
|
6 |
+
public $codigrid ; //this flag is to know whether we are displaying our grid or a general grid
|
7 |
+
public $userid ;
|
8 |
+
public $password ;
|
9 |
+
public $disableextension ;
|
10 |
+
public $version = "3.0.4";
|
11 |
+
|
12 |
+
public $customerid ;
|
13 |
+
public $customerdatasourceid ;
|
14 |
+
public $validateuser ;
|
15 |
+
public $extensionName='Mage_PDF_per_Product';
|
16 |
+
public $StoreId ;
|
17 |
+
public $reviewsModel ;
|
18 |
+
public $ratingModel ;
|
19 |
+
public $enablereviews ;
|
20 |
+
public $mediaurl ;
|
21 |
+
|
22 |
+
public function _construct()
|
23 |
+
{
|
24 |
+
parent::_construct();
|
25 |
+
$this->_init('codi/codi');
|
26 |
+
$this->_logFile = "Catalog-on-demand-items.log";
|
27 |
+
|
28 |
+
$this->enablereviews = Mage::getStoreConfig('codi/codi/codenablereviews');
|
29 |
+
|
30 |
+
// Get StoreID -Start
|
31 |
+
foreach (Mage::app()->getWebsites() as $website)
|
32 |
+
{
|
33 |
+
$defaultGroup = $website->getDefaultGroup();
|
34 |
+
$StoreId = $defaultGroup->getDefaultStoreId();
|
35 |
+
}
|
36 |
+
|
37 |
+
$this->StoreId = $StoreId ;
|
38 |
+
// Get StoreID -End
|
39 |
+
|
40 |
+
$this->reviewsModel = Mage::getModel('review/review') ;
|
41 |
+
$this->ratingModel = Mage::getModel('rating/rating_option_vote') ;
|
42 |
+
$this->mediaurl = Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_MEDIA);
|
43 |
+
}
|
44 |
+
|
45 |
+
public function setStoreConfig( $myarray )
|
46 |
+
{
|
47 |
+
$section = 'codi' ;
|
48 |
+
$website = '' ;
|
49 |
+
$store = '';
|
50 |
+
|
51 |
+
$groups =
|
52 |
+
array(
|
53 |
+
'codi' =>
|
54 |
+
array(
|
55 |
+
'fields' => $myarray
|
56 |
+
));
|
57 |
+
Mage::getModel('adminhtml/config_data')
|
58 |
+
->setSection($section)
|
59 |
+
->setWebsite($website)
|
60 |
+
->setStore($store)
|
61 |
+
->setGroups($groups)
|
62 |
+
->save();
|
63 |
+
}
|
64 |
+
|
65 |
+
public function adminstart()
|
66 |
+
{
|
67 |
+
Mage::log("Notice : Admin Start", null, $this->_logFile);
|
68 |
+
|
69 |
+
$AdminNotified = Mage::getSingleton('core/session')->getAdminNotified();
|
70 |
+
if (!$AdminNotified)
|
71 |
+
{
|
72 |
+
Mage::getSingleton('core/session')->setAdminNotified(true);
|
73 |
+
try
|
74 |
+
{
|
75 |
+
$codimodel = Mage::getSingleton('codi/codi');
|
76 |
+
//Get Application Parameters Response (Notification)
|
77 |
+
$url = "https://webservices.catalog-on-demand.com/smanager/api.do?Operation=GetApplicationParameters&Application=CoDExtensionForMagento" ;
|
78 |
+
$paramsarray = array('UserID' => Mage::getStoreConfig('codi/codi/codusername'),
|
79 |
+
'Password' => Mage::getStoreConfig('codi/codi/codpassword') );
|
80 |
+
$Responsemsg = $this->Call( $url, $paramsarray );
|
81 |
+
if ( $Responsemsg )
|
82 |
+
{
|
83 |
+
if (!$Responsemsg->Errors)
|
84 |
+
{
|
85 |
+
foreach ($Responsemsg->GetApplicationParametersResponse->ApplicationParameter as $ApplicationParameter)
|
86 |
+
{
|
87 |
+
//Get Version
|
88 |
+
if ((string)$ApplicationParameter->Name == "Version")
|
89 |
+
$Version = (string)$ApplicationParameter->Value;
|
90 |
+
//Get Release Notes Link
|
91 |
+
if ((string)$ApplicationParameter->Name == "ReleaseNotesLink")
|
92 |
+
$ReleaseNotesLink = (string)$ApplicationParameter->Value;
|
93 |
+
//Get the Notification Message
|
94 |
+
if ((string)$ApplicationParameter->Name == "NotificationMessage")
|
95 |
+
$NotificationMessage = (string)$ApplicationParameter->Value;
|
96 |
+
}
|
97 |
+
|
98 |
+
$title = "Catalog-On-Demand version " . $Version . " now available";
|
99 |
+
|
100 |
+
$feedData[] = array(
|
101 |
+
'severity' => 2,
|
102 |
+
'date_added' => NOW(),
|
103 |
+
'title' => (string)$title,
|
104 |
+
'description' => (string)$NotificationMessage,
|
105 |
+
'url' => (string)$ReleaseNotesLink,
|
106 |
+
);
|
107 |
+
|
108 |
+
if ( version_compare($Version, $codimodel->version) == 1) {
|
109 |
+
Mage::getModel('adminnotification/inbox')->parse(array_reverse($feedData)); }
|
110 |
+
}
|
111 |
+
}
|
112 |
+
}
|
113 |
+
catch(Exception $e){}
|
114 |
+
}
|
115 |
+
}
|
116 |
+
|
117 |
+
public function InitImportStatuses(){
|
118 |
+
|
119 |
+
$write = Mage::getSingleton('core/resource')->getConnection('core_write');
|
120 |
+
|
121 |
+
$write->query("DROP TABLE IF EXISTS codi_import_status");
|
122 |
+
$write->query("CREATE TABLE codi_import_status(
|
123 |
+
id int(11) NOT NULL auto_increment PRIMARY KEY,
|
124 |
+
message varchar(50),
|
125 |
+
finished int(1) default 0)"
|
126 |
+
);
|
127 |
+
}
|
128 |
+
|
129 |
+
public function existTable(){
|
130 |
+
|
131 |
+
$write = Mage::getSingleton('core/resource')->getConnection('core_write');
|
132 |
+
|
133 |
+
$write->query("CREATE TABLE IF NOT EXISTS codi_import_status(
|
134 |
+
id int(11) NOT NULL auto_increment PRIMARY KEY,
|
135 |
+
message varchar(50),
|
136 |
+
finished int(1) default 0)"
|
137 |
+
);
|
138 |
+
|
139 |
+
}
|
140 |
+
|
141 |
+
public function addImportStatus( $message, $finished = 0 ){
|
142 |
+
|
143 |
+
$this->existTable();
|
144 |
+
|
145 |
+
$write = Mage::getSingleton('core/resource')->getConnection('core_write');
|
146 |
+
$query = "insert into codi_import_status (message, finished) values('".$message."', $finished)";
|
147 |
+
$write->query($query);
|
148 |
+
}
|
149 |
+
|
150 |
+
public function getImportStatuses(){
|
151 |
+
|
152 |
+
$this->existTable();
|
153 |
+
|
154 |
+
$read= Mage::getSingleton('core/resource')->getConnection('core_read');
|
155 |
+
|
156 |
+
$query = "select id, message, finished from codi_import_status order by id desc limit 1";
|
157 |
+
|
158 |
+
$messages = null;
|
159 |
+
|
160 |
+
$result = $read->query($query);
|
161 |
+
|
162 |
+
if($row = $result->fetch() ){
|
163 |
+
$messages = array('message'=>$row['message'], 'id'=>$row['id'], 'finished'=>$row['finished']);
|
164 |
+
}
|
165 |
+
|
166 |
+
return $messages;
|
167 |
+
}
|
168 |
+
|
169 |
+
public function deleteTable(){
|
170 |
+
|
171 |
+
$this->existTable();
|
172 |
+
|
173 |
+
$write = Mage::getSingleton('core/resource')->getConnection('core_write');
|
174 |
+
$query = "delete from codi_import_status";
|
175 |
+
$write->query($query);
|
176 |
+
}
|
177 |
+
|
178 |
+
public function isStart(){
|
179 |
+
|
180 |
+
$this->existTable();
|
181 |
+
|
182 |
+
$read= Mage::getSingleton('core/resource')->getConnection('core_read');
|
183 |
+
|
184 |
+
$query = "select id, message, finished from codi_import_status where message = 'start' order by id desc limit 1";
|
185 |
+
|
186 |
+
$result = $read->query($query);
|
187 |
+
|
188 |
+
if($row = $result->fetch() ){
|
189 |
+
return true;
|
190 |
+
}
|
191 |
+
|
192 |
+
return false;
|
193 |
+
}
|
194 |
+
//Changed in 3.0.3
|
195 |
+
public function createFile($basePath){
|
196 |
+
|
197 |
+
$fh = fopen($basePath.'CoDzip/CoDfiles/temp.txt', 'w');
|
198 |
+
|
199 |
+
if ( !$fh )
|
200 |
+
{
|
201 |
+
return false;
|
202 |
+
}
|
203 |
+
|
204 |
+
fclose($fh);
|
205 |
+
|
206 |
+
//unlink($basePath.'CoDzip/CoDfiles/temp.txt');
|
207 |
+
return true;
|
208 |
+
}
|
209 |
+
|
210 |
+
public function run_codi_import_manually($basepath){
|
211 |
+
|
212 |
+
$this->run_codi_import($basepath);
|
213 |
+
}
|
214 |
+
|
215 |
+
public function run_codi_import($basePath)
|
216 |
+
{
|
217 |
+
Mage::log("Notice : Codi Import Start", null, $this->_logFile);
|
218 |
+
|
219 |
+
ini_set('memory_limit','1024M');
|
220 |
+
|
221 |
+
$this->InitImportStatuses();
|
222 |
+
|
223 |
+
$fh = fopen($basePath.'CoDzip/CoDfiles/temp.txt', 'w');
|
224 |
+
|
225 |
+
if ( !$fh )
|
226 |
+
{
|
227 |
+
Mage::log("ERROR : Cann't open file for building data file:".$basePath, null, $this->_logFile);
|
228 |
+
$this->addImportStatus("fileerror", 1);
|
229 |
+
return;
|
230 |
+
}
|
231 |
+
|
232 |
+
fwrite($fh, "itemNumber\titemQty\titemUom\titemPrice\titemDescription\titemLink\titemAttributes\titemGraphic\tproductName\tproductMfg\tproductDescription\tproductGraphic\tproductLink\tproductAttributes\tCategory\tReviews\tSupplementalInfo");
|
233 |
+
|
234 |
+
$products = Mage::getModel('catalog/product')->getCollection();
|
235 |
+
$products->addAttributeToFilter('status', 1);//enabled
|
236 |
+
$products->addAttributeToFilter('visibility', 4);//catalog, search
|
237 |
+
$products->addAttributeToSelect('*');
|
238 |
+
$prodIds = $products->getAllIds();
|
239 |
+
|
240 |
+
$this->addImportStatus("start");
|
241 |
+
|
242 |
+
$status = "end";
|
243 |
+
foreach($prodIds as $productId) {
|
244 |
+
|
245 |
+
set_time_limit(0);
|
246 |
+
|
247 |
+
$message = $this->getImportStatuses();
|
248 |
+
if ( isset($message) && $message['message'] == "cancel") {
|
249 |
+
$status = "cancel";
|
250 |
+
break;
|
251 |
+
}
|
252 |
+
|
253 |
+
$product = Mage::getModel('catalog/product');
|
254 |
+
$product->load($productId);
|
255 |
+
|
256 |
+
fwrite($fh, $this->ProducttoString($product, "product"));
|
257 |
+
}
|
258 |
+
|
259 |
+
fclose($fh);
|
260 |
+
Mage::log("Notice : Codi Import End : ".$status, null, $this->_logFile);
|
261 |
+
//Clean up
|
262 |
+
unset($products);
|
263 |
+
unset($product);
|
264 |
+
|
265 |
+
if ( $status == "end" )
|
266 |
+
$this->addImportStatus($status, 1);
|
267 |
+
}
|
268 |
+
|
269 |
+
public function ProducttoString( $product , $from )
|
270 |
+
{
|
271 |
+
|
272 |
+
if( $product->isConfigurable() )
|
273 |
+
{
|
274 |
+
return $this->ProducttoStringConfigurable( $product , $from ) ;
|
275 |
+
}
|
276 |
+
else
|
277 |
+
{
|
278 |
+
return $this->ProducttoStringSimple( $product , $from ) ;
|
279 |
+
}
|
280 |
+
}
|
281 |
+
|
282 |
+
public function ProducttoStringConfigurable( $product , $from )
|
283 |
+
{
|
284 |
+
$ProducttoString = '' ;
|
285 |
+
$UsedProductIds = Mage::getModel('catalog/product_type_configurable')->getUsedProductIds($product);
|
286 |
+
|
287 |
+
$ProductDescription = '';
|
288 |
+
if(Mage::getStoreConfig('codi/codi/codincludeshortdescription')=="checked")
|
289 |
+
{
|
290 |
+
$ProductDescription .= $product->getShortDescription();
|
291 |
+
}
|
292 |
+
$ProductDescription .= $product->getDescription() ;
|
293 |
+
//Get Product Attributes Start
|
294 |
+
//$excludeAttr = array() ;
|
295 |
+
$attributes = $product->getAttributes();
|
296 |
+
|
297 |
+
$ProductAttributes = "" ;
|
298 |
+
foreach ($attributes as $attribute) {
|
299 |
+
if ($attribute->getIsVisibleOnFront() && !in_array($attribute->getAttributeCode(), array() )) {
|
300 |
+
$value = $attribute->getFrontend()->getValue($product);
|
301 |
+
if (is_string($value))
|
302 |
+
{
|
303 |
+
if (strlen($value) && $product->hasData($attribute->getAttributeCode()))
|
304 |
+
{
|
305 |
+
$ProductAttributes .= $attribute->getFrontend()->getLabel() . "=" . $value . "|" ;
|
306 |
+
}
|
307 |
+
}
|
308 |
+
}
|
309 |
+
}
|
310 |
+
$ProductAttributes = substr($ProductAttributes, 0, strlen($ProductAttributes)-1 ) ;
|
311 |
+
//Get Product Attributes End
|
312 |
+
|
313 |
+
//******************** Get Tier Price option *********************//
|
314 |
+
|
315 |
+
if(Mage::getStoreConfig('codi/codi/codpublishtieredpricing')=='checked')
|
316 |
+
{
|
317 |
+
$TierPriceAttributes =Mage::helper('codi')->geTierprice($product);
|
318 |
+
$sp="|";
|
319 |
+
if(($ProductAttributes=='') || ($TierPriceAttributes==''))
|
320 |
+
$sp='';
|
321 |
+
|
322 |
+
if($ProductAttributes=='')
|
323 |
+
|
324 |
+
|
325 |
+
$ProductAttributes.= $sp.$TierPriceAttributes;
|
326 |
+
}
|
327 |
+
//************End Tier Price option *************//
|
328 |
+
//************************* Get Categories names Start ***************************
|
329 |
+
//Changed in 3.0.3 removed the category names
|
330 |
+
$CategoriesString = "" ;
|
331 |
+
|
332 |
+
//************************* Get Categories names End ***************************
|
333 |
+
|
334 |
+
foreach($UsedProductIds as $UsedProductid)
|
335 |
+
{
|
336 |
+
$UsedProduct = Mage::getModel('catalog/product')->load($UsedProductid);
|
337 |
+
if( Mage::getStoreConfig('codi/codi/fromchild') )
|
338 |
+
$UsedProductPrice = $UsedProduct->getFinalPrice() ;
|
339 |
+
else
|
340 |
+
$UsedProductPrice = $product->getFinalPrice() ; //default behavior
|
341 |
+
//************************ Get Attributes Start *******************************
|
342 |
+
|
343 |
+
//Extract Attributes
|
344 |
+
|
345 |
+
$ImageURL = $this->mediaurl . "catalog/product" . $product->getImage();
|
346 |
+
|
347 |
+
//Get Item Attributes Start
|
348 |
+
|
349 |
+
$attributes = $UsedProduct->getAttributes();
|
350 |
+
|
351 |
+
$ItemitemAttributes = "" ;
|
352 |
+
$AllowAttributes = $product->getTypeInstance(true)->getConfigurableAttributes($product);
|
353 |
+
foreach ($AllowAttributes as $attribute)
|
354 |
+
{
|
355 |
+
$AttributeCode = $attribute->getProductAttribute()->getAttributeCode() ;
|
356 |
+
$AttributeLabel = $attribute->getProductAttribute()->getFrontend()->getLabel() ;
|
357 |
+
$AttribId = $UsedProduct->getData($AttributeCode) ;
|
358 |
+
|
359 |
+
$AttributeValue = "" ;
|
360 |
+
foreach ( $attribute->getProductAttribute()->getSource()->getAllOptions() as $option )
|
361 |
+
{
|
362 |
+
if( $option['value'] == $AttribId )
|
363 |
+
{
|
364 |
+
$AttributeValue = $option['label'];
|
365 |
+
}
|
366 |
+
}
|
367 |
+
|
368 |
+
$ItemitemAttributes .= $AttributeLabel . "=" . $AttributeValue . "|" ;
|
369 |
+
|
370 |
+
//Get Delta Price Start
|
371 |
+
foreach( $attribute->getPrices() as $addedPrice )
|
372 |
+
{
|
373 |
+
if ( $AttributeValue == $addedPrice['label'])
|
374 |
+
{
|
375 |
+
if( $addedPrice['is_percent'] )
|
376 |
+
$UsedProductPrice += $UsedProductPrice * $addedPrice['pricing_value'] / 100;
|
377 |
+
else
|
378 |
+
$UsedProductPrice += $addedPrice['pricing_value'] ;
|
379 |
+
}
|
380 |
+
}
|
381 |
+
//Get Delta Price End
|
382 |
+
}
|
383 |
+
|
384 |
+
$ItemitemAttributes = substr($ItemitemAttributes, 0, strlen($ItemitemAttributes)-1 );
|
385 |
+
|
386 |
+
|
387 |
+
|
388 |
+
//Get Item Attributes End
|
389 |
+
//************************ Get Attributes End ************************************
|
390 |
+
//************************* Get Reviews Start ***********************
|
391 |
+
//$enablereviews = Mage::getStoreConfig('codi/codi/codenablereviews') ;
|
392 |
+
$Reviews = $this->enablereviews ? $this->getReviews($product->getId()) : '' ;
|
393 |
+
//************************* Get Reviews End *************************
|
394 |
+
|
395 |
+
//************************* Concatenate Product Info Start ***********************
|
396 |
+
$ProducttoString .= "\r\n" . $this->cleanStr( $UsedProduct->getSku() ) ; //ItemID
|
397 |
+
$ProducttoString .= "\t" . "" ; //ItemQty
|
398 |
+
$ProducttoString .= "\t" . "" ; //ItemUom
|
399 |
+
// $ProducttoString .= "\t" . $this->cleanStr( $product->getPrice() ) ; //ItemPrice
|
400 |
+
$ProducttoString .= "\t" . $this->cleanStr( $UsedProductPrice ) ; //ItemPrice
|
401 |
+
$ProducttoString .= "\t" . ""; //ItemDescription
|
402 |
+
$ProducttoString .= "\t" . $this->cleanStr( $product->getProductUrl() ); //ItemLink
|
403 |
+
$ProducttoString .= "\t" . $this->cleanStr( $ItemitemAttributes ) ; //ItemitemAttributes
|
404 |
+
$ProducttoString .= "\t" . ""; //ItemitemGraphic
|
405 |
+
$ProducttoString .= "\t" . $product->getId().'#$#'.$this->cleanStr( $product->getName() ); //ProductName
|
406 |
+
$ProducttoString .= "\t" . "" ; //ProductMfg
|
407 |
+
$ProducttoString .= "\t" . $this->cleanStr( $ProductDescription ) ; //ProductDescription
|
408 |
+
$ProducttoString .= "\t" . $this->cleanStr( $ImageURL ); //ProductGraphic
|
409 |
+
$ProducttoString .= "\t" . $this->cleanStr( $product->getProductUrl() ) ; //ProductLink
|
410 |
+
$ProducttoString .= "\t" . $this->cleanStr( $ProductAttributes ) ; //ProductAttributes
|
411 |
+
$ProducttoString .= "\t" . $this->cleanStr( $CategoriesString ); //Category
|
412 |
+
$ProducttoString .= "\t" . $this->cleanStr( $Reviews ); //Reviews
|
413 |
+
$ProducttoString .= "\t" . $this->cleanStr( $product->getShortDescription() ); //ShortDescription (Quick Overview)
|
414 |
+
//************************* Concatenate Product Info End ************************* cleanStr
|
415 |
+
}
|
416 |
+
unset($ProductDescription);
|
417 |
+
unset($ImageURL);
|
418 |
+
unset($product);
|
419 |
+
unset($ItemitemAttributes);
|
420 |
+
unset($CategoriesString);
|
421 |
+
unset($Reviews);
|
422 |
+
|
423 |
+
|
424 |
+
return $ProducttoString ;
|
425 |
+
}
|
426 |
+
/////////////////////////////////////////// Simple Products ///////////////////////////////////////////////////////////////////
|
427 |
+
public function ProducttoStringSimple( $product , $from )
|
428 |
+
{
|
429 |
+
$ProducttoString = '' ;
|
430 |
+
//Change for short description
|
431 |
+
//$ProductDescription = $product->getDescription() ;
|
432 |
+
$ProductDescription = '';
|
433 |
+
if(Mage::getStoreConfig('codi/codi/codincludeshortdescription')=="checked")
|
434 |
+
{
|
435 |
+
$ProductDescription .= $product->getShortDescription();
|
436 |
+
}
|
437 |
+
$ProductDescription .= $product->getDescription() ;
|
438 |
+
//************************ Get Attributes Start *******************************
|
439 |
+
//Extract Attributes
|
440 |
+
|
441 |
+
$ImageURL = $this->mediaurl . "catalog/product" . $product->getImage();
|
442 |
+
|
443 |
+
//$excludeAttr = array() ;
|
444 |
+
$attributes = $product->getAttributes();
|
445 |
+
$ItemitemAttributes = "" ;
|
446 |
+
foreach ($attributes as $attribute) {
|
447 |
+
if ($attribute->getIsVisibleOnFront() && !in_array($attribute->getAttributeCode(), array() )) {
|
448 |
+
$value = $attribute->getFrontend()->getValue($product);
|
449 |
+
if (is_string($value))
|
450 |
+
{
|
451 |
+
if (strlen($value) && $product->hasData($attribute->getAttributeCode()))
|
452 |
+
{
|
453 |
+
$ItemitemAttributes .= $attribute->getFrontend()->getLabel() . "=" . $value . "|" ;
|
454 |
+
}
|
455 |
+
}
|
456 |
+
}
|
457 |
+
}
|
458 |
+
$ItemitemAttributes = substr($ItemitemAttributes, 0, strlen($ItemitemAttributes)-1 ) ;
|
459 |
+
//************************ Get Attributes End ************************************
|
460 |
+
//******************** Get Tier Price option *********************//
|
461 |
+
|
462 |
+
if(Mage::getStoreConfig('codi/codi/codpublishtieredpricing')=='checked')
|
463 |
+
{
|
464 |
+
$TierPriceAttributes =Mage::helper('codi')->geTierprice($product);
|
465 |
+
$sp="|";
|
466 |
+
if(($ItemitemAttributes=='') || ($TierPriceAttributes==''))
|
467 |
+
$sp='';
|
468 |
+
|
469 |
+
$ItemitemAttributes.= $sp.$TierPriceAttributes;
|
470 |
+
}
|
471 |
+
//************End Tier Price option *************//
|
472 |
+
|
473 |
+
|
474 |
+
|
475 |
+
//************************* Get Categories names Start ***************************
|
476 |
+
//Changed into 3.0.3 removed the category name
|
477 |
+
|
478 |
+
$CategoriesString = "" ;
|
479 |
+
|
480 |
+
//************************* Get Categories names End ***************************
|
481 |
+
|
482 |
+
//************************* Get Reviews Start ***********************
|
483 |
+
$Reviews = $this->enablereviews ? $this->getReviews($product->getId()) : '' ;
|
484 |
+
//************************* Get Reviews End *************************
|
485 |
+
|
486 |
+
//************************* Concatenate Product Info Start ***********************
|
487 |
+
|
488 |
+
$ProducttoString .= "\r\n" . $this->cleanStr( $product->getSku() ) ; //ItemID
|
489 |
+
$ProducttoString .= "\t" . "" ; //ItemQty
|
490 |
+
$ProducttoString .= "\t" . "" ; //ItemUom
|
491 |
+
$ProducttoString .= "\t" . $this->cleanStr( $product->getFinalPrice() ) ; //ItemPrice
|
492 |
+
$ProducttoString .= "\t" . ""; //ItemDescription
|
493 |
+
$ProducttoString .= "\t" . $this->cleanStr( $product->getProductUrl() ); //ItemLink
|
494 |
+
$ProducttoString .= "\t" . ""; //ItemitemAttributes
|
495 |
+
$ProducttoString .= "\t" . ""; //ItemitemGraphic
|
496 |
+
$ProducttoString .= "\t" . $product->getId().'#$#'.$this->cleanStr( $product->getName() ); //ProductName
|
497 |
+
$ProducttoString .= "\t" . "" ; //ProductMfg
|
498 |
+
$ProducttoString .= "\t" . $this->cleanStr( $ProductDescription ) ; //ProductDescription
|
499 |
+
$ProducttoString .= "\t" . $this->cleanStr( $ImageURL ); //ProductGraphic
|
500 |
+
$ProducttoString .= "\t" . $this->cleanStr( $product->getProductUrl() ) ; //ProductLink
|
501 |
+
$ProducttoString .= "\t" . $this->cleanStr( $ItemitemAttributes ) ; //ProductAttributes
|
502 |
+
$ProducttoString .= "\t" . $this->cleanStr( $CategoriesString ); //Category
|
503 |
+
$ProducttoString .= "\t" . $this->cleanStr( $Reviews ); //Reviews
|
504 |
+
$ProducttoString .= "\t" . $this->cleanStr( $product->getShortDescription() ); //ShortDescription (Quick Overview)
|
505 |
+
//************************* Concatenate Product Info End ************************* cleanStr
|
506 |
+
|
507 |
+
unset($ProductDescription);
|
508 |
+
unset($ImageURL);
|
509 |
+
unset($product);
|
510 |
+
unset($ItemitemAttributes);
|
511 |
+
unset($CategoriesString);
|
512 |
+
unset($Reviews);
|
513 |
+
|
514 |
+
return $ProducttoString ;
|
515 |
+
}
|
516 |
+
|
517 |
+
public function cleanStr($localstr)
|
518 |
+
{
|
519 |
+
//$specialChar=array(''=>'',''=>'');
|
520 |
+
|
521 |
+
$localstr = str_replace("\t","", $localstr ) ;
|
522 |
+
$localstr = str_replace("\r\n","<br>", $localstr ) ;
|
523 |
+
$localstr = str_replace("\r","<br>", $localstr ) ;
|
524 |
+
$localstr = str_replace("\n","<br>", $localstr ) ;
|
525 |
+
$localstr = str_replace("","",$localstr) ;
|
526 |
+
//Changed for special character
|
527 |
+
|
528 |
+
|
529 |
+
|
530 |
+
return $localstr ;
|
531 |
+
}
|
532 |
+
|
533 |
+
public function getReviews( $productid )
|
534 |
+
{
|
535 |
+
$reviewsCollection = $this->reviewsModel->getCollection()
|
536 |
+
->addStoreFilter($this->StoreId)
|
537 |
+
->addStatusFilter('approved')
|
538 |
+
->addEntityFilter('product', $productid)
|
539 |
+
->setDateOrder();
|
540 |
+
|
541 |
+
$Reviews = "" ;
|
542 |
+
foreach($reviewsCollection as $review)
|
543 |
+
{
|
544 |
+
$ratingCollection = $this->ratingModel
|
545 |
+
->getResourceCollection()
|
546 |
+
->setReviewFilter($review->getReviewId())
|
547 |
+
->setStoreFilter($this->StoreId)
|
548 |
+
->addRatingInfo($this->StoreId)
|
549 |
+
->load();
|
550 |
+
$Reviews .= "<p><b>".$review->getTitle()."(". $review->getNickname() .")</b><br>".$review->getDetail()."</p>" ;
|
551 |
+
}
|
552 |
+
return $Reviews ;
|
553 |
+
}
|
554 |
+
|
555 |
+
public function checkvalidity()
|
556 |
+
{
|
557 |
+
$userid = Mage::getStoreConfig('codi/codi/codusername') ;
|
558 |
+
$password = Mage::getStoreConfig('codi/codi/codpassword') ;
|
559 |
+
$url = "https://webservices.catalog-on-demand.com/smanager/api.do?Operation=ValidateUser&ResponseGroups=All&FunctionGroups=All" ;
|
560 |
+
$paramsarray = array('UserID' => $userid ,
|
561 |
+
'Password' => $password );
|
562 |
+
$Responsemsg = $this->Call( $url, $paramsarray );
|
563 |
+
if( $Responsemsg )
|
564 |
+
return $Responsemsg->Message=="OK" ? true : false ;
|
565 |
+
else
|
566 |
+
return false ;
|
567 |
+
}
|
568 |
+
|
569 |
+
//////////////////////////////////// Calling Start /////////////////////////////////////////////////////
|
570 |
+
public function CallusingZend( $url, $paramsarray )
|
571 |
+
{
|
572 |
+
$client = new Zend_Http_Client();
|
573 |
+
$client->setUri($url);
|
574 |
+
$client->setParameterPost('UserID', $this->userid);
|
575 |
+
$client->setParameterPost('Password', $this->password);
|
576 |
+
|
577 |
+
$mystr = '';
|
578 |
+
foreach($paramsarray as $key=>$value)
|
579 |
+
{
|
580 |
+
$client->setParameterPost($key, $value);
|
581 |
+
$mystr .= $key . $value ;
|
582 |
+
}
|
583 |
+
|
584 |
+
$response = $client->request('POST');
|
585 |
+
$result = $response->getBody() ;
|
586 |
+
return $result;
|
587 |
+
}
|
588 |
+
|
589 |
+
public function CallusingCurl( $url, $paramsarray )
|
590 |
+
{
|
591 |
+
$poststr = '';
|
592 |
+
foreach($paramsarray as $key=>$value)
|
593 |
+
{
|
594 |
+
$poststr .= $key ."=". urlencode($value) ."&";
|
595 |
+
}
|
596 |
+
|
597 |
+
$ch = curl_init();
|
598 |
+
curl_setopt($ch, CURLOPT_URL,$url);
|
599 |
+
curl_setopt($ch, CURLOPT_FAILONERROR, 1);
|
600 |
+
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
|
601 |
+
curl_setopt($ch, CURLOPT_POST,1);
|
602 |
+
curl_setopt($ch, CURLOPT_POSTFIELDS, $poststr);
|
603 |
+
$result = curl_exec($ch);
|
604 |
+
curl_close($ch);
|
605 |
+
|
606 |
+
return $result;
|
607 |
+
}
|
608 |
+
|
609 |
+
public function Call( $url, $paramsarray )
|
610 |
+
{
|
611 |
+
$result = "" ;
|
612 |
+
try
|
613 |
+
{
|
614 |
+
$result = $this->CallusingZend( $url, $paramsarray );
|
615 |
+
}
|
616 |
+
catch(Exception $e)
|
617 |
+
{
|
618 |
+
try
|
619 |
+
{
|
620 |
+
$result = $this->CallusingCurl( $url, $paramsarray );
|
621 |
+
}
|
622 |
+
catch(Exception $e){}
|
623 |
+
}
|
624 |
+
|
625 |
+
$Responsemsg = false ;
|
626 |
+
|
627 |
+
return $result ;
|
628 |
+
}
|
629 |
+
//////////////////////////////////// Calling End /////////////////////////////////////////////////////
|
630 |
+
public function getComment($datetime='')
|
631 |
+
{
|
632 |
+
$Comment = "";
|
633 |
+
////////////////////////////////////////////////////////////
|
634 |
+
$extension_version = $this->version;//(string) Mage::getConfig()->getNode()->modules->Mage_Codi->version;
|
635 |
+
$app_version = Mage::getVersion();
|
636 |
+
$php_version = phpversion();
|
637 |
+
|
638 |
+
foreach (Mage::app()->getWebsites() as $website)
|
639 |
+
{
|
640 |
+
$defaultGroup = $website->getDefaultGroup();
|
641 |
+
$StoreId = $defaultGroup->getDefaultStoreId();
|
642 |
+
}
|
643 |
+
|
644 |
+
$design = Mage::getSingleton('core/design')->loadChange($StoreId);
|
645 |
+
$package = $design->getPackage();
|
646 |
+
$default_theme = $design->getTheme();
|
647 |
+
|
648 |
+
if ( $package == "" && $default_theme == "" ){
|
649 |
+
|
650 |
+
$package = Mage::getStoreConfig('design/package/name', $StoreId);
|
651 |
+
$default_theme = Mage::getStoreConfig('design/theme/default', $StoreId);
|
652 |
+
}
|
653 |
+
|
654 |
+
if ( $package == "" ) $package = "default";
|
655 |
+
if ( $default_theme == "" ) $default_theme = "default";
|
656 |
+
|
657 |
+
$theme = "default";
|
658 |
+
if ( $package != "default" || $default_theme != "default" )
|
659 |
+
$theme = $package."/".$default_theme;
|
660 |
+
|
661 |
+
$codbgcheck = ( Mage::getStoreConfig('codi/codi/codbgcheck') == '1' )?'Yes':'No' ;
|
662 |
+
|
663 |
+
$enablefreshflyers = ( Mage::getStoreConfig('codi/codi/enablefreshflyers') == 'checked' )?'Yes':'No' ;
|
664 |
+
$enablereviews = ( Mage::getStoreConfig('codi/codi/codenablereviews') == 'checked' )?'Yes':'No' ;
|
665 |
+
$fromchild = ( Mage::getStoreConfig('codi/codi/fromchild') == 'checked' )?'Yes':'No' ;
|
666 |
+
|
667 |
+
$codflyerlinkimgurl = Mage::getStoreConfig('codi/codi/codflyerlinkimgurl') ;
|
668 |
+
$codflyerlinkimg = ( Mage::getStoreConfig('codi/codi/codflyerlinkimg') == 'Custom' )? $codflyerlinkimgurl:'Default';
|
669 |
+
$codflyerlinkimgalt = Mage::getStoreConfig('codi/codi/codflyerlinkimgalt') ;
|
670 |
+
|
671 |
+
$codbeforename = ( Mage::getStoreConfig('codi/codi/codbeforename') == 'checked' )?'Yes':'No' ;
|
672 |
+
$codaftername = ( Mage::getStoreConfig('codi/codi/codaftername') == 'checked' )?'Yes':'No' ;
|
673 |
+
$codbeforeemailto = ( Mage::getStoreConfig('codi/codi/codbeforeemailto') == 'checked' )?'Yes':'No' ;
|
674 |
+
$codafteremailto = ( Mage::getStoreConfig('codi/codi/codafteremailto') == 'checked' )?'Yes':'No' ;
|
675 |
+
$codbeforeOR = ( Mage::getStoreConfig('codi/codi/codbeforeOR') == 'checked' )?'Yes':'No' ;
|
676 |
+
$codafterOR = ( Mage::getStoreConfig('codi/codi/codafterOR') == 'checked' )?'Yes':'No' ;
|
677 |
+
$codbeforeoverview = ( Mage::getStoreConfig('codi/codi/codbeforeoverview') == 'checked' ) ?'Yes':'No';
|
678 |
+
$codafteroverview = ( Mage::getStoreConfig('codi/codi/codafteroverview') == 'checked' )?'Yes':'No';
|
679 |
+
//Changed for include short description
|
680 |
+
$includeshortdescription = (Mage::getStoreConfig('codi/codi/codincludeshortdescription')== 'checked' )?'Yes':'No';
|
681 |
+
|
682 |
+
$Comment = "App extension version: ".$extension_version." \r\n";
|
683 |
+
$Comment .= "Magento version: ".$app_version." \r\n";
|
684 |
+
$Comment .= "PHP: ".$php_version." \r\n";
|
685 |
+
$Comment .= "Theme: ".$theme." \r\n";
|
686 |
+
$Comment .= "Create data file using background process: ".$codbgcheck." \r\n";
|
687 |
+
$Comment .= "Enable Always Fresh Flyers: ".$enablefreshflyers." \r\n";
|
688 |
+
$Comment .= "Include Short Description: ".$includeshortdescription." \r\n";
|
689 |
+
$Comment .= "Enable Reviews: ".$enablereviews." \r\n";
|
690 |
+
$Comment .= "Get price from associated products: ".$fromchild." \r\n";
|
691 |
+
$Comment .= "Image to be used for flyer link: ".$codflyerlinkimg." \r\n";
|
692 |
+
$Comment .= "Alt text for flyer link image: ".$codflyerlinkimgalt." \r\n";
|
693 |
+
$Comment .= "Display options: \r\n";
|
694 |
+
$Comment .= " Display before product name: ".$codbeforename." \r\n";
|
695 |
+
$Comment .= " Display after product name: ".$codaftername." \r\n";
|
696 |
+
$Comment .= " Display before Email to a friend: ".$codbeforeemailto." \r\n";
|
697 |
+
$Comment .= " Display after Email to a friend: ".$codafteremailto." \r\n";
|
698 |
+
$Comment .= " Display before OR: ".$codbeforeOR." \r\n";
|
699 |
+
$Comment .= " Display after OR: ".$codafterOR." \r\n";
|
700 |
+
$Comment .= " Display before Quick Overview: ".$codbeforeoverview." \r\n";
|
701 |
+
$Comment .= " Display after Quick Overview: ".$codafteroverview." \r\n";
|
702 |
+
|
703 |
+
//Change for site url
|
704 |
+
$siteurl = Mage::getUrl('/');
|
705 |
+
$Comment .="Site Url: ".$siteurl."\r\n";
|
706 |
+
$datafilelaunch = Mage::getStoreConfig('codi/codi/coddatafilelaunch');
|
707 |
+
if($datafilelaunch=='magento')
|
708 |
+
{
|
709 |
+
$datafilelaunch='cronjob';
|
710 |
+
|
711 |
+
}
|
712 |
+
|
713 |
+
//code for version 2.2.16
|
714 |
+
|
715 |
+
$Comment .="Data File Launch Mode: ".$datafilelaunch."\r\n";
|
716 |
+
|
717 |
+
$url = Mage::getUrl('codi/nsync') ;
|
718 |
+
$pos = strrpos ($url , 'key') ;
|
719 |
+
if ( $pos != 0 )
|
720 |
+
$cronjoburl = substr( $url , 0 , $pos ) ;
|
721 |
+
else
|
722 |
+
$cronjoburl = $url;
|
723 |
+
|
724 |
+
if(($datafilelaunch=='cronjob') || ($datafilelaunch=='manual'))
|
725 |
+
{
|
726 |
+
$Comment .="Cron job command: wget ".$cronjoburl."\r\n";
|
727 |
+
}
|
728 |
+
else{
|
729 |
+
$waitforminute=Mage::getStoreConfig('codi/codi/codwaitforminute')/60;
|
730 |
+
$Comment .="WaitFor: ".number_format($waitforminute,2,'.','')."\r\n";
|
731 |
+
|
732 |
+
}
|
733 |
+
|
734 |
+
$Comment .="Extension Name: ".$this->extensionName."\r\n";
|
735 |
+
$Comment .="Date and time of most recent data file: ".$datetime."\r\n";
|
736 |
+
//Changed for Tier Price options
|
737 |
+
|
738 |
+
$publishtieredpricing=Mage::getStoreConfig('codi/codi/codpublishtieredpricing');
|
739 |
+
if($publishtieredpricing=='checked')
|
740 |
+
{
|
741 |
+
$codquantity=Mage::getStoreConfig('codi/codi/codquantity');
|
742 |
+
$codprice=Mage::getStoreConfig('codi/codi/codprice');
|
743 |
+
$codsavings=Mage::getStoreConfig('codi/codi/codsavings');
|
744 |
+
$publish=($publishtieredpricing == 'checked' )?'Yes':'No';
|
745 |
+
$Comment .= "Tiered Pricing Options: \r\n";
|
746 |
+
$Comment .= " Publish tiered pricing: ".$publish." \r\n";
|
747 |
+
$Comment .= " Label for quantity column: ".$codquantity." \r\n";
|
748 |
+
$Comment .= " Label for price column: ".$codprice." \r\n";
|
749 |
+
$Comment .= " Label for savings: ".$codsavings." \r\n";
|
750 |
+
|
751 |
+
}
|
752 |
+
|
753 |
+
|
754 |
+
return $Comment;
|
755 |
+
////////////////////////////////////////////////////////////
|
756 |
+
}
|
757 |
+
//code for version 2.2.16
|
758 |
+
public function new_run_codi_import($basePath)
|
759 |
+
{
|
760 |
+
|
761 |
+
Mage::log("Notice : Codi Import Start", null, $this->_logFile);
|
762 |
+
|
763 |
+
ini_set('memory_limit','1024M');
|
764 |
+
|
765 |
+
$this->InitImportStatuses();
|
766 |
+
|
767 |
+
$fh = fopen($basePath.'CoDzip/CoDfiles/temp.txt', 'w');
|
768 |
+
|
769 |
+
if ( !$fh )
|
770 |
+
{
|
771 |
+
Mage::log("ERROR : Cann't open file for building data file:".$basePath, null, $this->_logFile);
|
772 |
+
$this->addImportStatus("fileerror", 1);
|
773 |
+
return;
|
774 |
+
}
|
775 |
+
|
776 |
+
fwrite($fh, "itemNumber\titemQty\titemUom\titemPrice\titemDescription\titemLink\titemAttributes\titemGraphic\tproductName\tproductMfg\tproductDescription\tproductGraphic\tproductLink\tproductAttributes\tCategory\tReviews\tSupplementalInfo");
|
777 |
+
|
778 |
+
$products = Mage::getModel('catalog/product')->getCollection();
|
779 |
+
$products->addAttributeToFilter('status', 1);//enabled
|
780 |
+
$products->addAttributeToFilter('visibility', 4);//catalog, search
|
781 |
+
$products->addAttributeToSelect('*');
|
782 |
+
|
783 |
+
$prodIds = $products->getAllIds();
|
784 |
+
|
785 |
+
$this->addImportStatus("start");
|
786 |
+
|
787 |
+
$status = "end";
|
788 |
+
$i='0';
|
789 |
+
try{
|
790 |
+
foreach($prodIds as $productId)
|
791 |
+
{
|
792 |
+
set_time_limit(20);
|
793 |
+
$message = $this->getImportStatuses();
|
794 |
+
if ( isset($message) && $message['message'] == "cancel") {
|
795 |
+
$status = "cancel";
|
796 |
+
break;
|
797 |
+
}
|
798 |
+
$product = Mage::getModel('catalog/product');
|
799 |
+
$product->load($productId);
|
800 |
+
Mage::log("Notice : Codi Import Products :".$i, null, $this->_logFile);
|
801 |
+
fwrite($fh, $this->ProducttoString($product, "product"));
|
802 |
+
$i++;
|
803 |
+
}
|
804 |
+
}
|
805 |
+
catch (Exception $e)
|
806 |
+
{
|
807 |
+
Mage::log("Notice : Codi Import Products Exception :".$e->getMessage(), null, $this->_logFile);
|
808 |
+
}
|
809 |
+
//clean up the memory
|
810 |
+
unset($product);
|
811 |
+
unset($prodIds);
|
812 |
+
unset($products);
|
813 |
+
|
814 |
+
fclose($fh);
|
815 |
+
Mage::log("Notice : Codi Import End : ".$status, null, $this->_logFile);
|
816 |
+
|
817 |
+
if ( $status == "end" )
|
818 |
+
$this->addImportStatus($status, 1);
|
819 |
+
|
820 |
+
}
|
821 |
+
//code for create CatalogSection.txt
|
822 |
+
public function createCatalogSection()
|
823 |
+
{
|
824 |
+
Mage::log("Notice : Create Catalog Section Start: ", null, $this->_logFile);
|
825 |
+
|
826 |
+
$helper=Mage::helper('codi');
|
827 |
+
$dir = dirname(__FILE__);
|
828 |
+
$_baseDirArray = explode("app", $dir);
|
829 |
+
$basePath = $_baseDirArray[0];
|
830 |
+
$progress=100;
|
831 |
+
/*
|
832 |
+
//Create object for Codi Model
|
833 |
+
//Create table Codi Catalog Section for insert category hirarchy path
|
834 |
+
*/
|
835 |
+
$catalogSectionModel=Mage::getModel('codi/codi');
|
836 |
+
$catalogSectionModel->InitCatalogSectionTable();
|
837 |
+
|
838 |
+
$collection = Mage::getModel('catalog/category')->getCollection()
|
839 |
+
->setStoreId('1')
|
840 |
+
->addAttributeToSelect('name')
|
841 |
+
->addAttributeToSelect('is_active')
|
842 |
+
->addAttributeToFilter('level', array('eq' => 2))
|
843 |
+
->addAttributeToFilter('is_active', array('eq' => 1))
|
844 |
+
->addAttributeToSort('position', 'asc');
|
845 |
+
//echo $collection->getSelect();
|
846 |
+
|
847 |
+
|
848 |
+
$i=1;
|
849 |
+
$count=count($collection);
|
850 |
+
if($count>0)
|
851 |
+
{
|
852 |
+
|
853 |
+
foreach($collection as $category)
|
854 |
+
{
|
855 |
+
$name=$category->getName();
|
856 |
+
$id=$category->getId();
|
857 |
+
$file = $basePath.'/CoDzip/CoDfiles/CatalogSection.txt';
|
858 |
+
file_put_contents($file,"sec_Project\tsec_Sequence\tsec_HierarchyPath\tsec_Flag\n");
|
859 |
+
$stringe.=$helper->drawItem($category,1,$name,$i);
|
860 |
+
file_put_contents($file,$stringe,FILE_APPEND);
|
861 |
+
$i++;
|
862 |
+
}
|
863 |
+
}
|
864 |
+
if($count==0)
|
865 |
+
{
|
866 |
+
$progress=0;
|
867 |
+
}
|
868 |
+
|
869 |
+
//clean up the memory
|
870 |
+
unset($catalogSectionModel);
|
871 |
+
unset($collection);
|
872 |
+
unset($stringe);
|
873 |
+
|
874 |
+
Mage::log("Notice : Create Catalog Section End: ", null, $this->_logFile);
|
875 |
+
return $progress;
|
876 |
+
}
|
877 |
+
//code for create Catalog Project
|
878 |
+
public function createCatalogProject($fromcron=0)
|
879 |
+
{
|
880 |
+
$dir = dirname(__FILE__);
|
881 |
+
$_baseDirArray = explode("app", $dir);
|
882 |
+
$basePath = $_baseDirArray[0];
|
883 |
+
Mage::log("Notice : Create Catalog Project Start", null, $this->_logFile);
|
884 |
+
|
885 |
+
ini_set('memory_limit','1024M');
|
886 |
+
|
887 |
+
$this->InitImportStatuses();
|
888 |
+
|
889 |
+
$fh = fopen($basePath.'CoDzip/CoDfiles/CatalogProject.txt', 'w');
|
890 |
+
|
891 |
+
if ( !$fh )
|
892 |
+
{
|
893 |
+
Mage::log("ERROR : Cann't open file for building data file:".$basePath, null, $this->_logFile);
|
894 |
+
return;
|
895 |
+
}
|
896 |
+
|
897 |
+
fwrite($fh, "proj_Key\tproj_ProdName\tproj_Sequence\tproj_Name\tproj_HierarchyPath\tproj_Flag\tproj_ProdLayout");
|
898 |
+
|
899 |
+
$products = Mage::getModel('catalog/product')->getCollection();
|
900 |
+
$products->addAttributeToFilter('status', 1);//enabled
|
901 |
+
$products->addAttributeToFilter('visibility', 4);//catalog, search
|
902 |
+
$products->addAttributeToSelect('*');
|
903 |
+
|
904 |
+
$prodIds = $products->getAllIds();
|
905 |
+
$totalproduct=count($prodIds);
|
906 |
+
$this->addImportStatus("start");
|
907 |
+
|
908 |
+
$status = "end";
|
909 |
+
$i='0';
|
910 |
+
|
911 |
+
try{
|
912 |
+
|
913 |
+
foreach($prodIds as $productId)
|
914 |
+
{
|
915 |
+
set_time_limit(20);
|
916 |
+
$message = $this->getImportStatuses();
|
917 |
+
if ( isset($message) && $message['message'] == "cancel") {
|
918 |
+
$status = "cancel";
|
919 |
+
break;
|
920 |
+
}
|
921 |
+
$product = Mage::getModel('catalog/product');
|
922 |
+
$product->load($productId);
|
923 |
+
Mage::log("Notice : Codi Import Products :".$i, null, $this->_logFile);
|
924 |
+
fwrite($fh, $this->CatalogProjucttoString($product, "product"));
|
925 |
+
$i++;
|
926 |
+
|
927 |
+
}
|
928 |
+
//Change for zip code if not call from cronjob
|
929 |
+
if($fromcron==0)
|
930 |
+
{
|
931 |
+
$DataFile = 'CoDMagento';
|
932 |
+
Mage::helper('codi/createzip')->createimportzip($DataFile);
|
933 |
+
}
|
934 |
+
}
|
935 |
+
catch (Exception $e)
|
936 |
+
{
|
937 |
+
return 'error';
|
938 |
+
Mage::log("Notice : Codi Catalog Project Exception :".$e->getMessage(), null, $this->_logFile);
|
939 |
+
}
|
940 |
+
//clean up the memory
|
941 |
+
unset($products);
|
942 |
+
unset($prodIds);
|
943 |
+
unset($product);
|
944 |
+
fclose($fh);
|
945 |
+
$progress='10';
|
946 |
+
Mage::log("Notice :Codi Catalog Project End : ".$status, null, $this->_logFile);
|
947 |
+
|
948 |
+
return $progress;
|
949 |
+
}
|
950 |
+
//Code for Catalog projuct section
|
951 |
+
public function CatalogProjucttoString( $product , $from )
|
952 |
+
{
|
953 |
+
|
954 |
+
if( $product->isConfigurable() )
|
955 |
+
{
|
956 |
+
return $this->ProjucttoStringConfigurable( $product , $from ) ;
|
957 |
+
}
|
958 |
+
else
|
959 |
+
{
|
960 |
+
return $this->ProjucttoStringSimple( $product , $from ) ;
|
961 |
+
}
|
962 |
+
}
|
963 |
+
|
964 |
+
public function ProjucttoStringConfigurable( $product , $from )
|
965 |
+
{
|
966 |
+
//get All associated products
|
967 |
+
$UsedProductIds = Mage::getModel('catalog/product_type_configurable')->getUsedProductIds($product);
|
968 |
+
$countUsedProductIds=count($UsedProductIds);
|
969 |
+
if($countUsedProductIds>0)
|
970 |
+
{
|
971 |
+
ini_set('memory_limit','1024M');
|
972 |
+
$ProducttoString = '' ;
|
973 |
+
//************************* Get Categories names Start ***************************
|
974 |
+
$categories = $product->getCategoryIds();
|
975 |
+
$CategoriesString = "" ;
|
976 |
+
$helper=Mage::helper('codi');
|
977 |
+
$catelogSectionModel=Mage::getModel('codi/codi');
|
978 |
+
foreach($categories as $k => $_category_id){
|
979 |
+
set_time_limit(20);
|
980 |
+
$_cat = Mage::getModel('catalog/category')->load($_category_id);
|
981 |
+
if(($_cat->getName() != '') && ($_cat->getIsActive() == 1) && ($_cat->getName() != 'Root Catalog') && ((string)$_cat->getLevel() != '1') && ($_cat->getParentId() > 1 ) )
|
982 |
+
{
|
983 |
+
$data=$catelogSectionModel->isCatalogSectionStart($_category_id);
|
984 |
+
$CategoriesString=$data['category_hirarchy_path'];
|
985 |
+
//code for product position
|
986 |
+
$position=$helper->productPostion($_category_id,$product->getId());
|
987 |
+
if ($CategoriesString==false) $CategoriesString = 'Uncategorized' ;
|
988 |
+
//************************* Concatenate Product Info Start ***********************
|
989 |
+
$ProducttoString .= "\r\n" . $product->getId().'#$#'. $this->cleanStr( $product->getName()); //ProductKey
|
990 |
+
$ProducttoString .= "\t" . $product->getId().'#$#'.$this->cleanStr( $product->getName()); //Product Name
|
991 |
+
$ProducttoString .= "\t" . $this->cleanStr( $position ) ; //Prod Sequence
|
992 |
+
$ProducttoString .= "\t" . $this->cleanStr('General'); //Change cleanstr parameter from Magento to General //Proj Name
|
993 |
+
$ProducttoString .= "\t" . $this->cleanStr( $CategoriesString ); //Hirarachi Path
|
994 |
+
$ProducttoString .= "\t" . $this->cleanStr('');//Proj Flag
|
995 |
+
$ProducttoString .= "\t" . $this->cleanStr(''); //Proj Prod layout
|
996 |
+
//************************* Concatenate Product Info End ************************* cleanStr
|
997 |
+
|
998 |
+
}
|
999 |
+
}
|
1000 |
+
//Clean up
|
1001 |
+
unset($categories);
|
1002 |
+
unset($catelogSectionModel);
|
1003 |
+
unset($CategoriesString);
|
1004 |
+
unset($position);
|
1005 |
+
unset($product);
|
1006 |
+
}
|
1007 |
+
else
|
1008 |
+
{
|
1009 |
+
$ProducttoString='';
|
1010 |
+
}
|
1011 |
+
|
1012 |
+
|
1013 |
+
return $ProducttoString ;
|
1014 |
+
}
|
1015 |
+
|
1016 |
+
/////////////////////////////////////////// Simple Products ///////////////////////////////////////////////////////////////////
|
1017 |
+
public function ProjucttoStringSimple( $product , $from )
|
1018 |
+
{
|
1019 |
+
ini_set('memory_limit','1024M');
|
1020 |
+
$ProducttoString = '' ;
|
1021 |
+
//************************* Get Categories names Start ***************************
|
1022 |
+
$categories = $product->getCategoryIds();
|
1023 |
+
$CategoriesString = "" ;
|
1024 |
+
$catelogSectionModel=Mage::getModel('codi/codi');
|
1025 |
+
$helper=Mage::helper('codi');
|
1026 |
+
foreach($categories as $k => $_category_id){
|
1027 |
+
set_time_limit(20);
|
1028 |
+
//Code for add category hirarchi_path
|
1029 |
+
$_cat = Mage::getModel('catalog/category')->load($_category_id);
|
1030 |
+
if(($_cat->getName() != '') && ($_cat->getIsActive() == 1) && ($_cat->getName() != 'Root Catalog') && ((string)$_cat->getLevel() != '1') && ($_cat->getParentId() > 1 ) )
|
1031 |
+
{
|
1032 |
+
$data=$catelogSectionModel->isCatalogSectionStart($_category_id);
|
1033 |
+
$CategoriesString=$data['category_hirarchy_path'];
|
1034 |
+
//code for product position
|
1035 |
+
$position=$helper->productPostion($_category_id,$product->getId());
|
1036 |
+
|
1037 |
+
if ($CategoriesString == false ) $CategoriesString = 'Uncategorized' ;
|
1038 |
+
//************************* Concatenate Product Info Start ***********************
|
1039 |
+
$ProducttoString .= "\r\n" . $product->getId().'#$#'.$this->cleanStr( $product->getName()); //ProductKey
|
1040 |
+
$ProducttoString .= "\t" . $product->getId().'#$#'.$this->cleanStr( $product->getName()); //Product Name
|
1041 |
+
$ProducttoString .= "\t" . $this->cleanStr($position) ; //Prod Sequence
|
1042 |
+
$ProducttoString .= "\t" . $this->cleanStr('General'); //Change cleanstr parameter from Magento to General //Proj Name
|
1043 |
+
$ProducttoString .= "\t" . $this->cleanStr( $CategoriesString ); //Hirarachi Path
|
1044 |
+
$ProducttoString .= "\t" . $this->cleanStr('');//Proj Flag
|
1045 |
+
$ProducttoString .= "\t" . $this->cleanStr(''); //Proj Prod layout
|
1046 |
+
//************************* Concatenate Product Info End ************************* cleanStr
|
1047 |
+
}
|
1048 |
+
}
|
1049 |
+
//Clean up
|
1050 |
+
unset($categories);
|
1051 |
+
unset($catelogSectionModel);
|
1052 |
+
unset($CategoriesString);
|
1053 |
+
unset($position);
|
1054 |
+
unset($product);
|
1055 |
+
|
1056 |
+
return $ProducttoString ;
|
1057 |
+
}
|
1058 |
+
//Functions for Codi CatalogSection Table
|
1059 |
+
public function InitCatalogSectionTable(){
|
1060 |
+
|
1061 |
+
$write = Mage::getSingleton('core/resource')->getConnection('core_write');
|
1062 |
+
|
1063 |
+
$write->query("DROP TABLE IF EXISTS codi_catalog_section");
|
1064 |
+
$write->query("CREATE TABLE codi_catalog_section(
|
1065 |
+
category_id int(11) NOT NULL PRIMARY KEY,
|
1066 |
+
category_hirarchy_path text)"
|
1067 |
+
);
|
1068 |
+
}
|
1069 |
+
|
1070 |
+
public function existCatalogSectionTable(){
|
1071 |
+
|
1072 |
+
$write = Mage::getSingleton('core/resource')->getConnection('core_write');
|
1073 |
+
|
1074 |
+
$write->query("CREATE TABLE IF NOT EXISTS codi_catalog_section(
|
1075 |
+
category_id int(11) NOT NULL PRIMARY KEY,
|
1076 |
+
category_hirarchy_path text)"
|
1077 |
+
);
|
1078 |
+
|
1079 |
+
}
|
1080 |
+
|
1081 |
+
public function addCatalogSection( $category_id=1, $category_hirarchy_path = 'uncategorized' ){
|
1082 |
+
|
1083 |
+
$this->existCatalogSectionTable();
|
1084 |
+
|
1085 |
+
$write = Mage::getSingleton('core/resource')->getConnection('core_write');
|
1086 |
+
$query = "insert into codi_catalog_section (category_id, category_hirarchy_path) values('".$category_id."', '".$category_hirarchy_path."')";
|
1087 |
+
$write->query($query);
|
1088 |
+
}
|
1089 |
+
public function deleteCatalogSectionTable(){
|
1090 |
+
|
1091 |
+
$this->existCatalogSectionTable();
|
1092 |
+
|
1093 |
+
$write = Mage::getSingleton('core/resource')->getConnection('core_write');
|
1094 |
+
$query = "delete from codi_catalog_section";
|
1095 |
+
$write->query($query);
|
1096 |
+
}
|
1097 |
+
|
1098 |
+
public function isCatalogSectionStart($category_id=1){
|
1099 |
+
|
1100 |
+
$this->existCatalogSectionTable();
|
1101 |
+
|
1102 |
+
$read= Mage::getSingleton('core/resource')->getConnection('core_read');
|
1103 |
+
|
1104 |
+
$query = "select category_hirarchy_path from codi_catalog_section where category_id = '".$category_id."' order by category_id desc limit 1";
|
1105 |
+
|
1106 |
+
$result = $read->query($query);
|
1107 |
+
|
1108 |
+
if($row = $result->fetch() ){
|
1109 |
+
|
1110 |
+
return $row;
|
1111 |
+
}
|
1112 |
+
|
1113 |
+
return false;
|
1114 |
+
} //Function for save data import progress status public function saveProgressData() { echo $tableName = Mage::getSingleton('core/resource')->getTableName('codi_progress_status'); die(); $write = Mage::getSingleton('core/resource')->getConnection('core_write'); if($update==0) $query = "insert into ".$tableName." (message, finished,created_time) values('".$message."', $finished,$created_time)"; else $query = "update ".$tableName." set message=".$message.", finished=".$finished.", created_time =".$created_time; $write->query($query); }
|
1115 |
+
|
1116 |
+
}
|
|
|
|
app/code/community/Mage/Codi/controllers/SyncController.php
CHANGED
@@ -165,7 +165,8 @@ class Mage_Codi_SyncController extends Mage_Core_Controller_Front_Action
|
|
165 |
$helper=Mage::helper('codi');
|
166 |
$TemplateName=(string)$helper->getTheme();
|
167 |
|
168 |
-
|
|
|
169 |
$paramsarray = array( 'ProcessID' => $ProcessID,
|
170 |
'TemplateName' => $TemplateName,
|
171 |
'DataFileLink' => $DataFileLink ,
|
@@ -173,7 +174,7 @@ class Mage_Codi_SyncController extends Mage_Core_Controller_Front_Action
|
|
173 |
'Encoding' => 'utf-8' ,
|
174 |
'ClearDatabase' => 'MissingOnly' ,
|
175 |
'PartnerID' => 'CoDMagento' ,
|
176 |
-
'CatalogProject' => '
|
177 |
'Comment' => $Comment);
|
178 |
if ( $error != "" ) {
|
179 |
$paramsarray = array('ProcessID' => $ProcessID,
|
@@ -183,7 +184,7 @@ class Mage_Codi_SyncController extends Mage_Core_Controller_Front_Action
|
|
183 |
'Encoding' => 'utf-8' ,
|
184 |
'ClearDatabase' => 'MissingOnly' ,
|
185 |
'PartnerID' => 'CoDMagento' ,
|
186 |
-
'CatalogProject' => '
|
187 |
'Comment' => $Comment,
|
188 |
'Error' => $error);
|
189 |
}
|
@@ -196,4 +197,4 @@ class Mage_Codi_SyncController extends Mage_Core_Controller_Front_Action
|
|
196 |
$Responsemsg = $CodiModel->Call( $url, $paramsarray );
|
197 |
Mage::log("Notice: Prepare the callback response message ". $Responsemsg, null, $this->_logFile);
|
198 |
}
|
199 |
-
}
|
165 |
$helper=Mage::helper('codi');
|
166 |
$TemplateName=(string)$helper->getTheme();
|
167 |
|
168 |
+
|
169 |
+
//Changed the value of CatalogProject value from magento to General
|
170 |
$paramsarray = array( 'ProcessID' => $ProcessID,
|
171 |
'TemplateName' => $TemplateName,
|
172 |
'DataFileLink' => $DataFileLink ,
|
174 |
'Encoding' => 'utf-8' ,
|
175 |
'ClearDatabase' => 'MissingOnly' ,
|
176 |
'PartnerID' => 'CoDMagento' ,
|
177 |
+
'CatalogProject' => 'General',
|
178 |
'Comment' => $Comment);
|
179 |
if ( $error != "" ) {
|
180 |
$paramsarray = array('ProcessID' => $ProcessID,
|
184 |
'Encoding' => 'utf-8' ,
|
185 |
'ClearDatabase' => 'MissingOnly' ,
|
186 |
'PartnerID' => 'CoDMagento' ,
|
187 |
+
'CatalogProject' => 'General',
|
188 |
'Comment' => $Comment,
|
189 |
'Error' => $error);
|
190 |
}
|
197 |
$Responsemsg = $CodiModel->Call( $url, $paramsarray );
|
198 |
Mage::log("Notice: Prepare the callback response message ". $Responsemsg, null, $this->_logFile);
|
199 |
}
|
200 |
+
}
|
app/code/community/Mage/Codi/etc/config.xml
CHANGED
@@ -2,7 +2,7 @@
|
|
2 |
<config>
|
3 |
<modules>
|
4 |
<Mage_Codi>
|
5 |
-
<version>3.0.
|
6 |
</Mage_Codi>
|
7 |
</modules>
|
8 |
<adminhtml>
|
2 |
<config>
|
3 |
<modules>
|
4 |
<Mage_Codi>
|
5 |
+
<version>3.0.5</version>
|
6 |
</Mage_Codi>
|
7 |
</modules>
|
8 |
<adminhtml>
|
app/design/adminhtml/default/default/template/codi/index.phtml
CHANGED
@@ -409,7 +409,7 @@ switch ($target)
|
|
409 |
|
410 |
$zipfileurl=str_replace("index.php/CoDzip/CoDMagento.zip/index/", "CoDzip/CoDMagento.zip",$url);
|
411 |
$modifie="<input class='input-text' type='text' name='zipfileurl' value='".$zipfileurl."'><br/>" ;
|
412 |
-
$modifie.="Last Created Date: " . date("M d, Y H:i:s.", filemtime($filename));
|
413 |
echo $modifie." <button type='button' onclick='download_codi_file();' class='scalable add' style='margin-left:25px;' ><span>Download Data File</span></button> <button type='button' onclick='delete_codi_file();' class='scalable add' style='margin-left:25px;' ><span>Delete Data File</span></button>";
|
414 |
}
|
415 |
else{
|
409 |
|
410 |
$zipfileurl=str_replace("index.php/CoDzip/CoDMagento.zip/index/", "CoDzip/CoDMagento.zip",$url);
|
411 |
$modifie="<input class='input-text' type='text' name='zipfileurl' value='".$zipfileurl."'><br/>" ;
|
412 |
+
$modifie.="Last Created Date: " . date("M d, Y H:i:s.", filemtime($filename))."(GMT)";
|
413 |
echo $modifie." <button type='button' onclick='download_codi_file();' class='scalable add' style='margin-left:25px;' ><span>Download Data File</span></button> <button type='button' onclick='delete_codi_file();' class='scalable add' style='margin-left:25px;' ><span>Delete Data File</span></button>";
|
414 |
}
|
415 |
else{
|
app/design/frontend/default/default/template/catalog/product/view.phtml
CHANGED
@@ -44,7 +44,11 @@ else
|
|
44 |
|
45 |
$enablefreshflyers = Mage::getStoreConfig('codi/codi/enablefreshflyers');
|
46 |
|
47 |
-
|
|
|
|
|
|
|
|
|
48 |
|
49 |
//Catalog-on-Demand
|
50 |
?>
|
44 |
|
45 |
$enablefreshflyers = Mage::getStoreConfig('codi/codi/enablefreshflyers');
|
46 |
|
47 |
+
/*$flyerlink = '<a target="_blank" href="http://catalog-on-demand.com/PDF-e-Link/?FlyerA&AID=' . Mage::getStoreConfig('codi/codi/codusername'). '|' . urlencode($_product->getId() . '#$#' . $_product->getName()) . '">'. '<img id="codflyerlinkimgalt" title="' . Mage::getStoreConfig('codi/codi/codflyerlinkimgalt') . '" alt="' . Mage::getStoreConfig('codi/codi/codflyerlinkimgalt') . '" src="' . $codflyerlinkimgurl . '">'. '</a>';*/
|
48 |
+
|
49 |
+
//Change on 5-Dec-2011
|
50 |
+
|
51 |
+
$flyerlink = '<a target="_blank" href="http://catalog-on-demand.com/PDF-e-Link/?AID=' . Mage::getStoreConfig('codi/codi/codusername'). '|' . urlencode($_product->getId()) . '">'. '<img id="codflyerlinkimgalt" title="' . Mage::getStoreConfig('codi/codi/codflyerlinkimgalt') . '" alt="' . Mage::getStoreConfig('codi/codi/codflyerlinkimgalt') . '" src="' . $codflyerlinkimgurl . '">'. '</a>';
|
52 |
|
53 |
//Catalog-on-Demand
|
54 |
?>
|
package.xml
CHANGED
@@ -1,7 +1,7 @@
|
|
1 |
<?xml version="1.0"?>
|
2 |
<package>
|
3 |
<name>Mage_PDF_per_Product</name>
|
4 |
-
<version>3.0.
|
5 |
<stability>stable</stability>
|
6 |
<license uri="http://www.opensource.org/licenses/osl-3.0.php">OSL v3.0</license>
|
7 |
<channel>community</channel>
|
@@ -10,9 +10,9 @@
|
|
10 |
<description>Catalog-On-Demand</description>
|
11 |
<notes>3.0.4- Added Catalog Project, Sections and Data file support</notes>
|
12 |
<authors><author><name>catalogondemand</name><user>auto-converted</user><email>timh@catalog-on-demand.com</email></author></authors>
|
13 |
-
<date>2011-12-
|
14 |
-
<time>
|
15 |
-
<contents><target name="mageskin"><dir name="adminhtml"><dir name="default"><dir name="default"><dir name="images"><file name="codimport_run.gif" hash="e805ea7eca1f34c75ba0f93780d32d38"/><file name="codimport_yes.gif" hash="0afb20898a704a106cb4c598868abf32"/><file name="preview_field_help.png" hash="1b1601459d25e8b1a6b1d109782078d2"/></dir></dir></dir></dir></target><target name="magedesign"><dir name="adminhtml"><dir name="default"><dir name="default"><dir name="template"><dir name="codi"><file name="index.phtml" hash="
|
16 |
<compatible/>
|
17 |
<dependencies/>
|
18 |
</package>
|
1 |
<?xml version="1.0"?>
|
2 |
<package>
|
3 |
<name>Mage_PDF_per_Product</name>
|
4 |
+
<version>3.0.5</version>
|
5 |
<stability>stable</stability>
|
6 |
<license uri="http://www.opensource.org/licenses/osl-3.0.php">OSL v3.0</license>
|
7 |
<channel>community</channel>
|
10 |
<description>Catalog-On-Demand</description>
|
11 |
<notes>3.0.4- Added Catalog Project, Sections and Data file support</notes>
|
12 |
<authors><author><name>catalogondemand</name><user>auto-converted</user><email>timh@catalog-on-demand.com</email></author></authors>
|
13 |
+
<date>2011-12-06</date>
|
14 |
+
<time>04:38:01</time>
|
15 |
+
<contents><target name="mageskin"><dir name="adminhtml"><dir name="default"><dir name="default"><dir name="images"><file name="codimport_run.gif" hash="e805ea7eca1f34c75ba0f93780d32d38"/><file name="codimport_yes.gif" hash="0afb20898a704a106cb4c598868abf32"/><file name="preview_field_help.png" hash="1b1601459d25e8b1a6b1d109782078d2"/></dir></dir></dir></dir></target><target name="magedesign"><dir name="adminhtml"><dir name="default"><dir name="default"><dir name="template"><dir name="codi"><file name="index.phtml" hash="b1fa1b65044275ab9ec474fc84e0b379"/></dir></dir><dir name="layout"><file name="codi.xml" hash="9407985f30403744eb4e758312d62aef"/></dir></dir></dir></dir><dir name="frontend"><dir name="default"><dir name="default"><dir name="template"><dir name="catalog"><dir name="product"><file name="view.phtml" hash="86eff56921219708a31c279309b949ca"/></dir></dir></dir></dir></dir></dir></target><target name="mageweb"><dir name="js"><dir name="jquery"><file name="jquery-1.2.6.noConflict.min.js" hash="090fdb3fbcb4727c0ca20cca87e7e12d"/><file name="jquery.tooltip.js" hash="d17cc8af1b8a595bd597084232be87e0"/></dir></dir></target><target name="magecommunity"><dir name="Mage"><dir name="Codi"><dir name="Block"><dir name="Adminhtml"><file name="Menu.php" hash="f1f1858f0d5b9ce563e45781dbf6f633"/><file name="Switcher.php" hash="2a8001fa18ff263d6c4a05353e131825"/></dir><dir name="Customer"><file name="Codi.php" hash="a2769ec72db46ce58ceb28823c3dc1a0"/></dir></dir><dir name="Helper"><file name="Createzip.php" hash="03fe07641f6f3f480b1d1c47b5ab3901"/><file name="Data.php" hash="0c5442367142b7c2048ca900e1e5a8f1"/></dir><dir name="Model"><file name="Codi.php" hash="52087a8d0bc51fbb44ca1814ee304bbb"/></dir><dir name="controllers"><dir name="Adminhtml"><file name="MenuController.php" hash="00301b123b460d9b9ac58382701e5806"/></dir><file name="DeleteController.php" hash="7267c76bf9575d0d905d19e281b89905"/><file name="NsyncController.php" hash="8456908a4239529c39f897f07a40b9bc"/><file name="SyncController.php" hash="b0efee98bd5addc1fef81db6fd56634d"/></dir><dir name="etc"><file name="config.xml" hash="1e117f28ce2e0cc6cdb1d64dd7ac5c6c"/></dir><file name="Codi_Process.php" hash="543456357988f8f8301f959fa75f9bb6"/></dir></dir></target><target name="mageetc"><dir name="modules"><file name="Mage_Codi.xml" hash="5d635cd2a0d415b67f095bda0298445d"/></dir></target></contents>
|
16 |
<compatible/>
|
17 |
<dependencies/>
|
18 |
</package>
|