Version Notes
Fixed SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry .
Fixed prefix issue
Download this release
Release Info
Developer | Iverve |
Extension | Ifuturz_Uploadpdf |
Version | 0.4.1 |
Comparing to | |
See all releases |
Code changes from version 0.4.0 to 0.4.1
app/code/local/Ifuturz/Uploadpdf/Model/Observer.php
CHANGED
@@ -16,23 +16,17 @@ class Ifuturz_Uploadpdf_Model_Observer
|
|
16 |
*
|
17 |
* @param Varien_Event_Observer $observer
|
18 |
*/
|
19 |
-
public function
|
20 |
-
{
|
21 |
-
//echo "hello";die;
|
22 |
if (!self::$_singletonFlag) {
|
23 |
self::$_singletonFlag = true;
|
24 |
-
|
|
|
25 |
$product = $observer->getEvent()->getProduct();
|
26 |
-
|
27 |
$productid = $product->getId();
|
28 |
|
29 |
-
try {
|
30 |
-
/**
|
31 |
-
* Perform any actions you want here
|
32 |
-
*
|
33 |
-
*/
|
34 |
-
//$id = $this->_getRequest()->getParam('id');
|
35 |
-
//$countcolorid = $this->_getRequest()->getParam('hidden');
|
36 |
|
37 |
$write = Mage::getSingleton('core/resource')->getConnection('core_write');
|
38 |
$collection = array();
|
@@ -40,67 +34,54 @@ class Ifuturz_Uploadpdf_Model_Observer
|
|
40 |
foreach($data1 as $cd)
|
41 |
{
|
42 |
$collection[] = $cd['pdf_file'];
|
43 |
-
}
|
44 |
-
|
45 |
-
$det_edit_id = $this->_getRequest()->getParam('editid');
|
46 |
-
//unlink("/pdfs/test3.pdf");die;
|
47 |
|
48 |
if ($data = $this->_getRequest()->getPost())
|
49 |
-
{
|
50 |
-
//echo "<pre>"; print_r($data);die;
|
51 |
$pdfname = $data['pdf_name'];
|
52 |
-
if(isset($_FILES['upload_pdf']['name']) && $_FILES['upload_pdf']['name'] != '')
|
53 |
-
|
54 |
-
//this way the name is saved in DB
|
55 |
$data['upload_pdf'] = $_FILES['upload_pdf']['name'];
|
56 |
-
$front = $data['upload_pdf'];
|
57 |
-
|
58 |
-
//$imgPath = Mage::getBaseUrl('media')."pdffiles/uploadedfiles/".$front;
|
59 |
$imgPath1 = Mage::getBaseUrl()."pdfs/".$front;
|
60 |
$imgPath = str_replace("/index.php","",$imgPath1);//die;
|
61 |
$data['pdf_path'] = '<img src="'.$imgPath.'" border="0" />';
|
62 |
-
|
63 |
-
}
|
64 |
}
|
|
|
65 |
|
66 |
$collection = array();
|
67 |
$data1 = Mage::getModel('uploadpdf/uploadpdf')->getCollection();
|
68 |
foreach($data1 as $cd)
|
69 |
{
|
70 |
$collection[] = $cd['pdf_file'];
|
71 |
-
}
|
72 |
-
|
73 |
-
$cpid=Mage::registry('current_product')->getId();
|
74 |
-
//$uploadpdf = "media/pdffiles/uploadedfiles/";
|
75 |
$uploadpdf = "pdfs/";
|
76 |
|
77 |
-
|
78 |
|
79 |
if(!empty($_POST['chkdelete'])) {
|
80 |
-
foreach($_POST['chkdelete'] as $checkdel) {
|
81 |
-
|
82 |
-
|
83 |
-
$readresult = $write->query("SELECT pdf_file FROM ifuturz_uploadpdf WHERE pdf_id ='$checkdel'");
|
84 |
$entityid = $readresult->fetch();
|
85 |
$delfilef = $entityid['pdf_file'];
|
86 |
|
87 |
unlink("pdfs/".$delfilef);
|
88 |
|
89 |
-
$sql1del = "DELETE FROM
|
90 |
$write->query($sql1del);
|
91 |
}
|
92 |
Mage::getSingleton('adminhtml/session')->addSuccess(Mage::helper('uploadpdf')->__('PDF(s) deleted successfully.'));
|
93 |
-
}
|
94 |
-
//die;
|
95 |
|
96 |
if($det_edit_id == '')
|
97 |
{
|
98 |
|
99 |
-
|
100 |
|
101 |
if($front != "")
|
102 |
-
{
|
103 |
-
|
104 |
if(file_exists($uploadpdf.$front))
|
105 |
{
|
106 |
Mage::getSingleton('adminhtml/session')->addError(Mage::helper('uploadpdf')->__('PDF file already exists!!'));
|
@@ -111,13 +92,12 @@ class Ifuturz_Uploadpdf_Model_Observer
|
|
111 |
|
112 |
if(($ext == "pdf") || ($ext == "PDF"))
|
113 |
{
|
114 |
-
$pdftempfile = $_FILES['upload_pdf']['tmp_name'];
|
115 |
-
//echo $pdftempfile."<br>".$uploadpdf.$front;
|
116 |
move_uploaded_file($pdftempfile,$uploadpdf.$front);
|
117 |
|
118 |
if(!in_array($front,$collection))
|
119 |
-
{
|
120 |
-
$sql1 = "INSERT INTO
|
121 |
$write->query($sql1);
|
122 |
Mage::getSingleton('adminhtml/session')->addSuccess(Mage::helper('uploadpdf')->__('PDF uploaded successfully.'));
|
123 |
}
|
@@ -127,15 +107,13 @@ class Ifuturz_Uploadpdf_Model_Observer
|
|
127 |
Mage::getSingleton('adminhtml/session')->addError(Mage::helper('uploadpdf')->__('Only PDF file is allowed.!'));
|
128 |
}
|
129 |
}
|
130 |
-
}
|
131 |
-
$product->save();
|
132 |
}
|
133 |
else
|
134 |
-
{
|
135 |
-
|
136 |
-
/*------------------------------ UPDATE PDF CODE -------------------------------------*/
|
137 |
|
138 |
-
$readresultn = $write->query("SELECT pdf_file FROM
|
139 |
$entityidn = $readresultn->fetch();
|
140 |
$delfilefn = $entityidn['pdf_file'];
|
141 |
|
@@ -164,14 +142,13 @@ class Ifuturz_Uploadpdf_Model_Observer
|
|
164 |
|
165 |
if(($ext == "pdf") || ($ext == "PDF"))
|
166 |
{
|
167 |
-
$pdftempfile = $_FILES['upload_pdf']['tmp_name'];
|
168 |
-
//echo $pdftempfile."<br>".$uploadpdf.$front;die;
|
169 |
move_uploaded_file($pdftempfile,$uploadpdf.$front);
|
170 |
|
171 |
$imgUpPath1 = Mage::getBaseUrl()."pdfs/".$front;
|
172 |
$imgUpPath = str_replace("/index.php","",$imgUpPath1);
|
173 |
|
174 |
-
$sql1_edit = "Update
|
175 |
$write->query($sql1_edit);
|
176 |
Mage::getSingleton('adminhtml/session')->addSuccess(Mage::helper('uploadpdf')->__('PDF updated successfully.'));
|
177 |
}
|
@@ -179,9 +156,7 @@ class Ifuturz_Uploadpdf_Model_Observer
|
|
179 |
{
|
180 |
Mage::getSingleton('adminhtml/session')->addError(Mage::helper('uploadpdf')->__('Only PDF file is allowed.!'));
|
181 |
}
|
182 |
-
}
|
183 |
-
$product->save();
|
184 |
-
|
185 |
}
|
186 |
|
187 |
}
|
@@ -212,13 +187,15 @@ class Ifuturz_Uploadpdf_Model_Observer
|
|
212 |
|
213 |
public function checkInstallation($observer)
|
214 |
{
|
|
|
|
|
215 |
$read = Mage::getSingleton('core/resource')->getConnection('core_read');
|
216 |
-
$sql ="SELECT * FROM
|
217 |
$data = $read->fetchAll($sql);
|
218 |
if(count($data)==1)
|
219 |
{
|
220 |
-
|
221 |
-
$admindata = $read->fetchAll("SELECT email FROM
|
222 |
|
223 |
$storename = Mage::getStoreConfig('general/store_information/name');
|
224 |
$storephone = Mage::getStoreConfig('general/store_information/phone');
|
@@ -242,14 +219,11 @@ class Ifuturz_Uploadpdf_Model_Observer
|
|
242 |
try{
|
243 |
$mail->send();
|
244 |
$write = Mage::getSingleton('core/resource')->getConnection('core_write');
|
245 |
-
$write->query("update
|
246 |
}
|
247 |
catch(Exception $e)
|
248 |
{
|
249 |
-
}
|
250 |
-
|
251 |
-
|
252 |
-
}
|
253 |
-
|
254 |
}
|
255 |
}
|
16 |
*
|
17 |
* @param Varien_Event_Observer $observer
|
18 |
*/
|
19 |
+
public function saveProductPdf(Varien_Event_Observer $observer)
|
20 |
+
{
|
|
|
21 |
if (!self::$_singletonFlag) {
|
22 |
self::$_singletonFlag = true;
|
23 |
+
$prefix = Mage::getConfig()->getTablePrefix();
|
24 |
+
$tablename = $prefix.'ifuturz_uploadpdf';
|
25 |
$product = $observer->getEvent()->getProduct();
|
26 |
+
|
27 |
$productid = $product->getId();
|
28 |
|
29 |
+
try {
|
|
|
|
|
|
|
|
|
|
|
|
|
30 |
|
31 |
$write = Mage::getSingleton('core/resource')->getConnection('core_write');
|
32 |
$collection = array();
|
34 |
foreach($data1 as $cd)
|
35 |
{
|
36 |
$collection[] = $cd['pdf_file'];
|
37 |
+
}
|
38 |
+
$det_edit_id = $this->_getRequest()->getParam('editid');
|
|
|
|
|
39 |
|
40 |
if ($data = $this->_getRequest()->getPost())
|
41 |
+
{
|
|
|
42 |
$pdfname = $data['pdf_name'];
|
43 |
+
if(isset($_FILES['upload_pdf']['name']) && $_FILES['upload_pdf']['name'] != '')
|
44 |
+
{
|
|
|
45 |
$data['upload_pdf'] = $_FILES['upload_pdf']['name'];
|
46 |
+
$front = $data['upload_pdf'];
|
|
|
|
|
47 |
$imgPath1 = Mage::getBaseUrl()."pdfs/".$front;
|
48 |
$imgPath = str_replace("/index.php","",$imgPath1);//die;
|
49 |
$data['pdf_path'] = '<img src="'.$imgPath.'" border="0" />';
|
|
|
|
|
50 |
}
|
51 |
+
}
|
52 |
|
53 |
$collection = array();
|
54 |
$data1 = Mage::getModel('uploadpdf/uploadpdf')->getCollection();
|
55 |
foreach($data1 as $cd)
|
56 |
{
|
57 |
$collection[] = $cd['pdf_file'];
|
58 |
+
}
|
59 |
+
$cpid=Mage::registry('current_product')->getId();
|
|
|
|
|
60 |
$uploadpdf = "pdfs/";
|
61 |
|
62 |
+
/*-----------Multiple DELETE PDF CODE ------------*/
|
63 |
|
64 |
if(!empty($_POST['chkdelete'])) {
|
65 |
+
foreach($_POST['chkdelete'] as $checkdel) {
|
66 |
+
$readresult = $write->query("SELECT pdf_file FROM ".$tablename." WHERE pdf_id ='$checkdel'");
|
|
|
|
|
67 |
$entityid = $readresult->fetch();
|
68 |
$delfilef = $entityid['pdf_file'];
|
69 |
|
70 |
unlink("pdfs/".$delfilef);
|
71 |
|
72 |
+
$sql1del = "DELETE FROM ".$tablename." WHERE pdf_id = '$checkdel'";
|
73 |
$write->query($sql1del);
|
74 |
}
|
75 |
Mage::getSingleton('adminhtml/session')->addSuccess(Mage::helper('uploadpdf')->__('PDF(s) deleted successfully.'));
|
76 |
+
}
|
|
|
77 |
|
78 |
if($det_edit_id == '')
|
79 |
{
|
80 |
|
81 |
+
/*---------------- ADD PDF CODE ------------------*/
|
82 |
|
83 |
if($front != "")
|
84 |
+
{
|
|
|
85 |
if(file_exists($uploadpdf.$front))
|
86 |
{
|
87 |
Mage::getSingleton('adminhtml/session')->addError(Mage::helper('uploadpdf')->__('PDF file already exists!!'));
|
92 |
|
93 |
if(($ext == "pdf") || ($ext == "PDF"))
|
94 |
{
|
95 |
+
$pdftempfile = $_FILES['upload_pdf']['tmp_name'];
|
|
|
96 |
move_uploaded_file($pdftempfile,$uploadpdf.$front);
|
97 |
|
98 |
if(!in_array($front,$collection))
|
99 |
+
{
|
100 |
+
$sql1 = "INSERT INTO ".$tablename." (`product_id`,`pdf_file`,`pdfname`,`pdf_path`) VALUES ('$productid','$front','$pdfname','$imgPath' )";
|
101 |
$write->query($sql1);
|
102 |
Mage::getSingleton('adminhtml/session')->addSuccess(Mage::helper('uploadpdf')->__('PDF uploaded successfully.'));
|
103 |
}
|
107 |
Mage::getSingleton('adminhtml/session')->addError(Mage::helper('uploadpdf')->__('Only PDF file is allowed.!'));
|
108 |
}
|
109 |
}
|
110 |
+
}
|
|
|
111 |
}
|
112 |
else
|
113 |
+
{
|
114 |
+
/*-------------- UPDATE PDF CODE --------------*/
|
|
|
115 |
|
116 |
+
$readresultn = $write->query("SELECT pdf_file FROM ".$tablename." WHERE pdf_id ='$det_edit_id'");
|
117 |
$entityidn = $readresultn->fetch();
|
118 |
$delfilefn = $entityidn['pdf_file'];
|
119 |
|
142 |
|
143 |
if(($ext == "pdf") || ($ext == "PDF"))
|
144 |
{
|
145 |
+
$pdftempfile = $_FILES['upload_pdf']['tmp_name'];
|
|
|
146 |
move_uploaded_file($pdftempfile,$uploadpdf.$front);
|
147 |
|
148 |
$imgUpPath1 = Mage::getBaseUrl()."pdfs/".$front;
|
149 |
$imgUpPath = str_replace("/index.php","",$imgUpPath1);
|
150 |
|
151 |
+
$sql1_edit = "Update ".$tablename." SET pdf_file = '$front',pdfname = '$pdfname',pdf_path = '$imgUpPath' WHERE pdf_id='$det_edit_id'";
|
152 |
$write->query($sql1_edit);
|
153 |
Mage::getSingleton('adminhtml/session')->addSuccess(Mage::helper('uploadpdf')->__('PDF updated successfully.'));
|
154 |
}
|
156 |
{
|
157 |
Mage::getSingleton('adminhtml/session')->addError(Mage::helper('uploadpdf')->__('Only PDF file is allowed.!'));
|
158 |
}
|
159 |
+
}
|
|
|
|
|
160 |
}
|
161 |
|
162 |
}
|
187 |
|
188 |
public function checkInstallation($observer)
|
189 |
{
|
190 |
+
$prefix = Mage::getConfig()->getTablePrefix();
|
191 |
+
$table_name = $prefix.'uploadpdf_lck';
|
192 |
$read = Mage::getSingleton('core/resource')->getConnection('core_read');
|
193 |
+
$sql ="SELECT * FROM ".$table_name." WHERE flag='LCK' AND value='1'";
|
194 |
$data = $read->fetchAll($sql);
|
195 |
if(count($data)==1)
|
196 |
{
|
197 |
+
$admintable = $prefix.'admin_user';
|
198 |
+
$admindata = $read->fetchAll("SELECT email FROM ".$admintable." WHERE username='admin'");
|
199 |
|
200 |
$storename = Mage::getStoreConfig('general/store_information/name');
|
201 |
$storephone = Mage::getStoreConfig('general/store_information/phone');
|
219 |
try{
|
220 |
$mail->send();
|
221 |
$write = Mage::getSingleton('core/resource')->getConnection('core_write');
|
222 |
+
$write->query("update ".$table_name." set value='0' where flag='LCK'");
|
223 |
}
|
224 |
catch(Exception $e)
|
225 |
{
|
226 |
+
}
|
227 |
+
}
|
|
|
|
|
|
|
228 |
}
|
229 |
}
|
app/code/local/Ifuturz/Uploadpdf/etc/config.xml
CHANGED
@@ -96,11 +96,11 @@
|
|
96 |
<events>
|
97 |
<catalog_product_save_after>
|
98 |
<observers>
|
99 |
-
<
|
100 |
<type>singleton</type>
|
101 |
<class>uploadpdf/observer</class>
|
102 |
-
<method>
|
103 |
-
</
|
104 |
</observers>
|
105 |
</catalog_product_save_after>
|
106 |
</events>
|
96 |
<events>
|
97 |
<catalog_product_save_after>
|
98 |
<observers>
|
99 |
+
<ifuturz_save_product_pdf>
|
100 |
<type>singleton</type>
|
101 |
<class>uploadpdf/observer</class>
|
102 |
+
<method>saveProductPdf</method>
|
103 |
+
</ifuturz_save_product_pdf>
|
104 |
</observers>
|
105 |
</catalog_product_save_after>
|
106 |
</events>
|
package.xml
CHANGED
@@ -1,7 +1,7 @@
|
|
1 |
<?xml version="1.0"?>
|
2 |
<package>
|
3 |
<name>Ifuturz_Uploadpdf</name>
|
4 |
-
<version>0.4.
|
5 |
<stability>stable</stability>
|
6 |
<license uri="http://opensource.org/licenses/osl-3.0.php">OSL v3.0</license>
|
7 |
<channel>community</channel>
|
@@ -11,11 +11,13 @@
|
|
11 |
• On product edit page admin can upload more than one PDF for specific one product.
|
12 |
• Admin can add/update/delete the pdf from admin panel on product edit page. There must be a listing of uploaded pdf so admin can have idea of how many pdfs are uploaded for one particular product.
|
13 |
• The uploaded pdf must be shown on product page on front end so customer can see the uploaded pdfs for particular product.</description>
|
14 |
-
<notes>
|
|
|
|
|
15 |
<authors><author><name>Iverve</name><user>iverve</user><email>extension.geek@ifuturz.com</email></author></authors>
|
16 |
-
<date>
|
17 |
-
<time>
|
18 |
-
<contents><target name="mageetc"><dir name="modules"><file name="Ifuturz_Uploadpdf.xml" hash="4bf0cf4a78783360d83d36d82efc0c1c"/></dir></target><target name="magelocal"><dir name="Ifuturz"><dir name="Uploadpdf"><dir name="Block"><dir name="Adminhtml"><dir name="Catalog"><dir name="Product"><dir name="Edit"><file name="Form.php" hash="da851444cc8a8d054c1fa061b23be63b"/><dir name="Tab"><file name="Uploadpdf.php" hash="29d2e39637ebcc96a530840cf9ba80c7"/></dir><file name="Tabs.php" hash="2d0244615617397f671a327d719aba4a"/></dir></dir></dir></dir></dir><dir name="Helper"><file name="Data.php" hash="7da275b559a1d56075d4839559ea3903"/></dir><dir name="Model"><dir name="Mysql4"><dir name="Uploadpdf"><file name="Collection.php" hash="a43f5a17243d9c11c8cef06fac2edfef"/></dir><file name="Uploadpdf.php" hash="745f41fbf6c53f262d217eab67ab8e06"/></dir><file name="Observer.php" hash="
|
19 |
<compatible/>
|
20 |
<dependencies><required><php><min>5.1.0</min><max>6.0.0</max></php></required></dependencies>
|
21 |
</package>
|
1 |
<?xml version="1.0"?>
|
2 |
<package>
|
3 |
<name>Ifuturz_Uploadpdf</name>
|
4 |
+
<version>0.4.1</version>
|
5 |
<stability>stable</stability>
|
6 |
<license uri="http://opensource.org/licenses/osl-3.0.php">OSL v3.0</license>
|
7 |
<channel>community</channel>
|
11 |
• On product edit page admin can upload more than one PDF for specific one product.
|
12 |
• Admin can add/update/delete the pdf from admin panel on product edit page. There must be a listing of uploaded pdf so admin can have idea of how many pdfs are uploaded for one particular product.
|
13 |
• The uploaded pdf must be shown on product page on front end so customer can see the uploaded pdfs for particular product.</description>
|
14 |
+
<notes>Fixed SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry .
|
15 |
+

|
16 |
+
Fixed prefix issue</notes>
|
17 |
<authors><author><name>Iverve</name><user>iverve</user><email>extension.geek@ifuturz.com</email></author></authors>
|
18 |
+
<date>2015-10-07</date>
|
19 |
+
<time>08:47:36</time>
|
20 |
+
<contents><target name="mageetc"><dir name="modules"><file name="Ifuturz_Uploadpdf.xml" hash="4bf0cf4a78783360d83d36d82efc0c1c"/></dir></target><target name="magelocal"><dir name="Ifuturz"><dir name="Uploadpdf"><dir name="Block"><dir name="Adminhtml"><dir name="Catalog"><dir name="Product"><dir name="Edit"><file name="Form.php" hash="da851444cc8a8d054c1fa061b23be63b"/><dir name="Tab"><file name="Uploadpdf.php" hash="29d2e39637ebcc96a530840cf9ba80c7"/></dir><file name="Tabs.php" hash="2d0244615617397f671a327d719aba4a"/></dir></dir></dir></dir></dir><dir name="Helper"><file name="Data.php" hash="7da275b559a1d56075d4839559ea3903"/></dir><dir name="Model"><dir name="Mysql4"><dir name="Uploadpdf"><file name="Collection.php" hash="a43f5a17243d9c11c8cef06fac2edfef"/></dir><file name="Uploadpdf.php" hash="745f41fbf6c53f262d217eab67ab8e06"/></dir><file name="Observer.php" hash="553cf2d731a26d63ecc07957a1c2088c"/><file name="Uploadpdf.php" hash="be43a3fbf5f88d4cc1434ef80856c0cd"/></dir><dir name="controllers"><dir name="Adminhtml"><file name="UploadpdfController.php" hash="45ac98d3dc6b6ec842da6c3386e01c49"/></dir><file name="IndexController.php" hash="721a4c0c77fbd5df29cfda3f3f2708c8"/></dir><dir name="etc"><file name="config.xml" hash="b7488fe1e065239384f04af3e9545f5c"/></dir><dir name="sql"><dir name="uploadpdf_setup"><file name="mysql4-install-0.4.0.php" hash="321222ceb13eac89fbefbd75bc234c4a"/></dir></dir></dir></dir></target><target name="magedesign"><dir name="adminhtml"><dir name="default"><dir name="default"><dir name="template"><dir name="uploadpdf"><dir name="catalog"><dir name="product"><dir name="tab"><file name="uploadpdf.phtml" hash="bc114f89e585bc0a70f8ed8c2da2b2cf"/></dir></dir></dir></dir></dir></dir></dir></dir><dir name="frontend"><dir name="base"><dir name="default"><dir name="layout"><file name="uploadpdf.xml" hash="e1e4382f9123e8cf82bbc6497507327a"/></dir><dir name="template"><dir name="uploadpdf"><file name="uploadpdf.phtml" hash="ba5d09594094f774dcca14e176fb51fa"/></dir></dir></dir></dir></dir></target><target name="mage"><dir name="pdfs"><file name="100_Series_Color_Chart-new.pdf" hash="e679543c12951769ed675853a62258b6"/><file name="100_Series_Color_Chart.pdf" hash="e679543c12951769ed675853a62258b6"/><file name="test.pdf" hash="e679543c12951769ed675853a62258b6"/><file name="test123.pdf" hash="e679543c12951769ed675853a62258b6"/></dir></target></contents>
|
21 |
<compatible/>
|
22 |
<dependencies><required><php><min>5.1.0</min><max>6.0.0</max></php></required></dependencies>
|
23 |
</package>
|
pdfs/100_Series_Color_Chart-new.pdf
ADDED
Binary file
|
pdfs/100_Series_Color_Chart.pdf
ADDED
Binary file
|
pdfs/test.pdf
ADDED
Binary file
|
pdfs/test123.pdf
ADDED
Binary file
|