Version Notes
First Release
Download this release
Release Info
Developer | Chandan Kumar Singh |
Extension | profile_Image |
Version | 1.0.1 |
Comparing to | |
See all releases |
Code changes from version 1.0.0 to 1.0.1
- app/code/community/Chandan/Customerattribute/Helper/Data.php +25 -0
- app/code/community/Chandan/Customerattribute/Model/Mysql4.php +17 -0
- app/code/community/Chandan/Customerattribute/controllers/ProfileimageController.php +97 -0
- app/code/community/Chandan/Customerattribute/etc/config.xml +44 -0
- app/code/community/Chandan/Customerattribute/sql/customerattribute_setup/mysql4-install-1.0.0.php +23 -0
- package.xml +3 -3
app/code/community/Chandan/Customerattribute/Helper/Data.php
ADDED
@@ -0,0 +1,25 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
class Chandan_Customerattribute_Helper_Data extends Mage_Core_Block_Template
|
3 |
+
{
|
4 |
+
public function getImage(){
|
5 |
+
echo $this->getUrl('profile/profileimage/getimage');
|
6 |
+
}
|
7 |
+
|
8 |
+
public function getUploadUrl(){
|
9 |
+
return Mage::getUrl('profile/profileimage/upload');
|
10 |
+
}
|
11 |
+
|
12 |
+
public function getFileExt($file_path)
|
13 |
+
{
|
14 |
+
return pathinfo($file_path, PATHINFO_EXTENSION);
|
15 |
+
}
|
16 |
+
|
17 |
+
public function generateImgName($ext)
|
18 |
+
{
|
19 |
+
if(Mage::getSingleton('customer/session')->isLoggedIn()) {
|
20 |
+
$customerData = Mage::getSingleton('customer/session')->getCustomer();
|
21 |
+
$customerid = $customerData->getId();
|
22 |
+
}
|
23 |
+
return 'avtar'.'_'.$customerid.".".$ext;
|
24 |
+
}
|
25 |
+
}
|
app/code/community/Chandan/Customerattribute/Model/Mysql4.php
ADDED
@@ -0,0 +1,17 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
class Chandan_Customerattribute_Model_Mysql4 extends Mage_Eav_Model_Entity_Setup
|
3 |
+
{
|
4 |
+
public function attributeExists($entityTypeId, $attributeId)
|
5 |
+
{
|
6 |
+
try
|
7 |
+
{
|
8 |
+
$entityTypeId = $this->getEntityTypeId($entityTypeId);
|
9 |
+
$attributeId = $this->getAttributeId($entityTypeId, $attributeId);
|
10 |
+
return !empty($attributeId);
|
11 |
+
}
|
12 |
+
catch(Exception $e)
|
13 |
+
{
|
14 |
+
return FALSE;
|
15 |
+
}
|
16 |
+
}
|
17 |
+
}
|
app/code/community/Chandan/Customerattribute/controllers/ProfileimageController.php
ADDED
@@ -0,0 +1,97 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
class Chandan_Customerattribute_ProfileimageController extends Mage_Core_Controller_Front_Action
|
3 |
+
{
|
4 |
+
public function indexAction()
|
5 |
+
{
|
6 |
+
//$this->loadLayout();
|
7 |
+
$this->loadLayout(array('default','profile_profileimage_index'));
|
8 |
+
$this->getLayout()->getBlock('head')->setTitle('Profile Image');
|
9 |
+
$this->renderLayout();
|
10 |
+
}
|
11 |
+
|
12 |
+
public function uploadAction(){
|
13 |
+
$_helper = Mage::helper('customerattribute');
|
14 |
+
$root_path = Mage::getBaseDir();
|
15 |
+
|
16 |
+
//Get the tmp url
|
17 |
+
$photo_src = $_FILES['avatar']['tmp_name'];
|
18 |
+
$photo_path = $_FILES['avatar']['name'];
|
19 |
+
$ext = $_helper->getFileExt($photo_path);
|
20 |
+
|
21 |
+
if (is_file($photo_src)) {
|
22 |
+
if (!file_exists($root_path.'/media/customer/')) {
|
23 |
+
mkdir($root_path.'/media/customer/', 0777, true);
|
24 |
+
}
|
25 |
+
$img_name = $_helper->generateImgName($ext);
|
26 |
+
$photo_dest = $root_path.'/media/customer/'.$img_name;
|
27 |
+
copy($photo_src, $photo_dest);
|
28 |
+
}
|
29 |
+
$this->saveImage($img_name);
|
30 |
+
Mage::getSingleton('core/session')->addSuccess(Mage::helper('customerattribute')->__('Profile Image has uploaded successfully'));
|
31 |
+
$this->_redirect('*/*/index');
|
32 |
+
}
|
33 |
+
|
34 |
+
public function saveImage($img_name){
|
35 |
+
if (Mage::getSingleton('customer/session')->isLoggedIn()) {
|
36 |
+
$customer = Mage::getSingleton('customer/session')->getCustomer();
|
37 |
+
$custObj = Mage::getModel('customer/customer')->load($customer->getId());
|
38 |
+
if($img_name != ''){
|
39 |
+
$img_name = '/'.$img_name;
|
40 |
+
$custObj->setavatar($img_name);
|
41 |
+
$custObj->save();
|
42 |
+
}
|
43 |
+
}
|
44 |
+
}
|
45 |
+
|
46 |
+
public function getImageAction(){
|
47 |
+
if(Mage::getSingleton('customer/session')->isLoggedIn()) {
|
48 |
+
$customerData = Mage::getSingleton('customer/session')->getCustomer();
|
49 |
+
$custid = $customerData->getId();
|
50 |
+
}
|
51 |
+
|
52 |
+
$customer = Mage::getModel('customer/customer')->load($custid);
|
53 |
+
$file = $customer->getavatar();
|
54 |
+
|
55 |
+
$path = Mage::getBaseDir('media') . DS . 'customer';
|
56 |
+
$ioFile = new Varien_Io_File();
|
57 |
+
$ioFile->open(array('path' => $path));
|
58 |
+
$fileName = $ioFile->getCleanPath($path . $file);
|
59 |
+
$path = $ioFile->getCleanPath($path);
|
60 |
+
$ioFile->streamOpen($fileName, 'r');
|
61 |
+
$contentLength = $ioFile->streamStat('size');
|
62 |
+
$contentModify = $ioFile->streamStat('mtime');
|
63 |
+
|
64 |
+
|
65 |
+
if ($plain) {
|
66 |
+
$extension = pathinfo($fileName, PATHINFO_EXTENSION);
|
67 |
+
switch (strtolower($extension)) {
|
68 |
+
case 'gif':
|
69 |
+
$contentType = 'image/gif';
|
70 |
+
break;
|
71 |
+
case 'jpg':
|
72 |
+
$contentType = 'image/jpeg';
|
73 |
+
break;
|
74 |
+
case 'png':
|
75 |
+
$contentType = 'image/png';
|
76 |
+
break;
|
77 |
+
default:
|
78 |
+
$contentType = 'application/octet-stream';
|
79 |
+
break;
|
80 |
+
}
|
81 |
+
}
|
82 |
+
|
83 |
+
$this->getResponse()
|
84 |
+
->setHttpResponseCode(200)
|
85 |
+
->setHeader('Pragma', 'public', true)
|
86 |
+
->setHeader('Content-type', $contentType, true)
|
87 |
+
->setHeader('Content-Length', $contentLength)
|
88 |
+
->setHeader('Last-Modified', date('r', $contentModify))
|
89 |
+
->clearBody();
|
90 |
+
$this->getResponse()->sendHeaders();
|
91 |
+
while (false !== ($buffer = $ioFile->streamRead())) {
|
92 |
+
echo $buffer;
|
93 |
+
}
|
94 |
+
//echo $fileName;
|
95 |
+
exit();
|
96 |
+
}
|
97 |
+
}
|
app/code/community/Chandan/Customerattribute/etc/config.xml
ADDED
@@ -0,0 +1,44 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?xml version="1.0" encoding="UTF-8"?>
|
2 |
+
<config>
|
3 |
+
<modules>
|
4 |
+
<Chandan_Customerattribute>
|
5 |
+
<version>1.0.0</version>
|
6 |
+
</Chandan_Customerattribute>
|
7 |
+
</modules>
|
8 |
+
<global>
|
9 |
+
<resources>
|
10 |
+
<customerattribute_setup>
|
11 |
+
<setup>
|
12 |
+
<module>Chandan_Customerattribute</module>
|
13 |
+
<class>Chandan_Customerattribute_Model_Mysql4</class>
|
14 |
+
</setup>
|
15 |
+
</customerattribute_setup>
|
16 |
+
</resources>
|
17 |
+
<helpers>
|
18 |
+
<customerattribute>
|
19 |
+
<class>Chandan_Customerattribute_Helper</class>
|
20 |
+
</customerattribute>
|
21 |
+
</helpers>
|
22 |
+
</global>
|
23 |
+
|
24 |
+
<frontend>
|
25 |
+
|
26 |
+
<routers>
|
27 |
+
<customerattribute>
|
28 |
+
<use>standard</use>
|
29 |
+
<args>
|
30 |
+
<module>Chandan_Customerattribute</module>
|
31 |
+
<frontName>profile</frontName>
|
32 |
+
</args>
|
33 |
+
</customerattribute>
|
34 |
+
</routers>
|
35 |
+
|
36 |
+
<layout>
|
37 |
+
<updates>
|
38 |
+
<customerattribute>
|
39 |
+
<file>attributecustomer.xml</file>
|
40 |
+
</customerattribute>
|
41 |
+
</updates>
|
42 |
+
</layout>
|
43 |
+
</frontend>
|
44 |
+
</config>
|
app/code/community/Chandan/Customerattribute/sql/customerattribute_setup/mysql4-install-1.0.0.php
ADDED
@@ -0,0 +1,23 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
$installer = $this;
|
3 |
+
$installer->startSetup();
|
4 |
+
$vCustomerEntityType = $installer->getEntityTypeId('customer');
|
5 |
+
$vCustAttributeSetId = $installer->getDefaultAttributeSetId($vCustomerEntityType);
|
6 |
+
$vCustAttributeGroupId = $installer->getDefaultAttributeGroupId($vCustomerEntityType, $vCustAttributeSetId);
|
7 |
+
|
8 |
+
$installer->addAttribute('customer', 'avatar', array(
|
9 |
+
'label' => 'Avatar Image',
|
10 |
+
'input' => 'image',
|
11 |
+
'type' => 'varchar',
|
12 |
+
'forms' => array('customer_account_edit','customer_account_create','adminhtml_customer','checkout_register'),
|
13 |
+
'required' => 0,
|
14 |
+
'user_defined' => 1,
|
15 |
+
));
|
16 |
+
|
17 |
+
$installer->addAttributeToGroup($vCustomerEntityType, $vCustAttributeSetId, $vCustAttributeGroupId, 'avatar', 0);
|
18 |
+
|
19 |
+
$oAttribute = Mage::getSingleton('eav/config')->getAttribute('customer', 'avatar');
|
20 |
+
$oAttribute->setData('used_in_forms', array('customer_account_edit','customer_account_create','adminhtml_customer','checkout_register'));
|
21 |
+
$oAttribute->save();
|
22 |
+
|
23 |
+
$installer->endSetup();
|
package.xml
CHANGED
@@ -1,7 +1,7 @@
|
|
1 |
<?xml version="1.0"?>
|
2 |
<package>
|
3 |
<name>profile_Image</name>
|
4 |
-
<version>1.0.
|
5 |
<stability>stable</stability>
|
6 |
<license uri="http://opensource.org/licenses/osl-3.0.php">OSL</license>
|
7 |
<channel>community</channel>
|
@@ -11,8 +11,8 @@
|
|
11 |
<notes>First Release</notes>
|
12 |
<authors><author><name>Chandan Kumar Singh</name><user>chandan8050</user><email>chandankumar8050@gmail.com</email></author></authors>
|
13 |
<date>2017-02-03</date>
|
14 |
-
<time>04:
|
15 |
-
<contents><target name="mageetc"><dir name="modules"><file name="Chandan_Customerattribute.xml" hash="aec08690c29efa9a66bfb42d23036baf"/></dir></target><target name="magedesign"><dir name="frontend"><dir name="base"><dir name="default"><dir name="layout"><file name="attributecustomer.xml" hash="68afb39335f3640492892f5de74b0263"/></dir><dir name="template"><dir name="attributecustomer"><dir name="customer"><dir name="form"><file name="register.phtml" hash="b924a70fbd6c7e9b445106ebecbbb741"/></dir></dir><file name="profileimage.phtml" hash="275211ba4183cf0b20aa7c2ab380210a"/></dir></dir></dir></dir></dir></target></contents>
|
16 |
<compatible/>
|
17 |
<dependencies><required><php><min>5.2.0</min><max>7.1.0</max></php></required></dependencies>
|
18 |
</package>
|
1 |
<?xml version="1.0"?>
|
2 |
<package>
|
3 |
<name>profile_Image</name>
|
4 |
+
<version>1.0.1</version>
|
5 |
<stability>stable</stability>
|
6 |
<license uri="http://opensource.org/licenses/osl-3.0.php">OSL</license>
|
7 |
<channel>community</channel>
|
11 |
<notes>First Release</notes>
|
12 |
<authors><author><name>Chandan Kumar Singh</name><user>chandan8050</user><email>chandankumar8050@gmail.com</email></author></authors>
|
13 |
<date>2017-02-03</date>
|
14 |
+
<time>04:52:18</time>
|
15 |
+
<contents><target name="magecommunity"><dir name="Chandan"><dir name="Customerattribute"><dir name="Helper"><file name="Data.php" hash="1679c76d4d24bcaeead56719a50e7ac8"/></dir><dir name="Model"><file name="Mysql4.php" hash="fda7f2b680143bcddb05d71bdccfa57f"/></dir><dir name="controllers"><file name="ProfileimageController.php" hash="52dd38f754f32445d3223086552eed01"/></dir><dir name="etc"><file name="config.xml" hash="0cecebd732caf14f1db33d6d8f3672eb"/></dir><dir name="sql"><dir name="customerattribute_setup"><file name="mysql4-install-1.0.0.php" hash="a1cf981386bf4e17ae215722d831907f"/></dir></dir></dir></dir></target><target name="mageetc"><dir name="modules"><file name="Chandan_Customerattribute.xml" hash="aec08690c29efa9a66bfb42d23036baf"/></dir></target><target name="magedesign"><dir name="frontend"><dir name="base"><dir name="default"><dir name="layout"><file name="attributecustomer.xml" hash="68afb39335f3640492892f5de74b0263"/></dir><dir name="template"><dir name="attributecustomer"><dir name="customer"><dir name="form"><file name="register.phtml" hash="b924a70fbd6c7e9b445106ebecbbb741"/></dir></dir><file name="profileimage.phtml" hash="275211ba4183cf0b20aa7c2ab380210a"/></dir></dir></dir></dir></dir></target></contents>
|
16 |
<compatible/>
|
17 |
<dependencies><required><php><min>5.2.0</min><max>7.1.0</max></php></required></dependencies>
|
18 |
</package>
|