Jump to content

Module Development for custom fields on Product page


vikramdhanjal

Recommended Posts

Hi,

 

I am developing module for adding optical prescription fields to product page on PS1.5.5. Making progress as follows:

http://virtualtryplugin.com/index.php?id_product=1&controller=product

 

I am able to show the dropdowns on product page. But when i click on add to cart, the dropdown values does not get submitted/posted. (default theme and ajax add to cart with flying style)

 

Code from module file to handle posted values and insert in database:

 

public function hookActionCartSave($params) {

$rightSpherical= Tools::getIsset(‘rightSpherical’);//DOES NOT ASSIGN MY VALUE TO VARIABLE

$rightSpherical=Tools::getValue(‘rightSpherical’);//DOES NOT ASSIGN MY VALUE TO VARIABLE

// echo"<pre> ”;

// print_r($params); //DOES NOT SHOW MY VALUES

// print_r($_REQUEST); //DOES NOT SHOW MY VALUES

// echo "</pre>”;

// $rightSpherical=2.09;// ASSIGNED THIS WAY VALUES SAVED TO DB

 

if (!Db::getInstance()->Execute(‘INSERT INTO `’._DB_PREFIX_.’prescription` (`cart_id`, `user_id`, `rightSpherical`) VALUES (‘.(int)($this->id).’, ‘.(int)($id_user).’, ‘.(float)($rightSpherical).’)'))

}

 

Module zip file attached.

 

In addition to the module installation, hook code needs to be placed in product.tpl of theme folder:

{if isset($HOOK_DISPLAY_PRESCRIPTION) && $HOOK_DISPLAY_PRESCRIPTION}{$HOOK_DISPLAY_PRESCRIPTION}{/if}

 

Hook needs to be registered in classes/controllers/frontController.php file in initContent() functioin:

$this->context->smarty->assign(array(

'HOOK_HEADER' => Hook::exec('displayHeader'),

'HOOK_TOP' => Hook::exec('displayTop'),

'HOOK_DISPLAY_PRESCRIPTION' => Hook::exec('displayPrescription'),

'HOOK_LEFT_COLUMN' => ($this->display_column_left ? Hook::exec('displayLeftColumn') : ''),

'HOOK_RIGHT_COLUMN' => ($this->display_column_right ? Hook::exec('displayRightColumn', array('cart' => $this->context->cart)) : ''),

));

 

 

Am I missing something here? Please guide through.

prescription module.zip

Edited by vikramdhanjal (see edit history)
  • Like 1
Link to comment
Share on other sites

Hi,

 

Thanks for responding.

 

Yes because the options have a lot of values, when i use bulk combination generator, i get errors like memory exhausted or the combination tab goes blank or it never completed combination generation process. I tried all available solutions, but it did not work. So now i have to do it this way.

 

By the way:

 

I was able to figure out why values are not being posted above: Because ajax cart feature uses ajax(jason) to send only specific values to cart controller( action page), which is done through "block cart". If i modify ajax-cart.js file in blockcart module, i can pass the values in ajax and my module will work fine thereon. But it will be cusomizing again not through module. Can we do so without modifying blockcart part?

 

Regards

Vikram

Edited by vikramdhanjal (see edit history)
Link to comment
Share on other sites

Hi,

 

Can we discuss further on this topic. I would need some guidance on both aspects with this. Developing this module without modifying any of other files or using attributes combinations without having issues with bulk combination generator.

 

I appreciate your time.

 

Regards

Vikram

Link to comment
Share on other sites

Hi Sir,

 

Thanks for response!

 

Here is the error I face with the domain i actually need it to work on. While using bulk combination generator:

 

Fatal error: Allowed memory size of 2097152000 bytes exhausted (tried to allocate 3072 bytes) in /var/www/vhosts/opticalab.com/httpdocs/controllers/admin/AdminAttributeGeneratorController.php(69) : runtime-created function on line 1

 

In config/defines.inc.php I have it set to :

 

define('_PS_MODE_DEV_', true);

if (_PS_MODE_DEV_)

{

@ini_set('display_errors', 'on');

@ini_set('memory_limit', '2000M');

define('_PS_DEBUG_SQL_', true);

/* Compatibility warning */

define('_PS_DISPLAY_COMPATIBILITY_WARNING_', true);

}

 

 

But it does not help. The client can not get much information about server configuration as its shared hosting. Let me know if the information is sufficient or i need to explain more?

 

Here is the actual domain i am supposed to implement it on: http://opticalab.com

 

I can be available on the same time you responded yesterday to make it faster.

 

Regards

Vikram

Edited by vikramdhanjal (see edit history)
Link to comment
Share on other sites

try using php.ini file and if your hoster using suPHP also add specific configuration below to the .htaccess file

 

php.ini

memory_limit = 256M

.htaccess

<IfModule mod_suphp.c>
suPHP_ConfigPath /PATH_TO_YOUR_PRESTASHOP_INSTALLATION/
</IfModule>

Then you can check on Back Office > Advanced Parameters > Configuration Informations

is memory_limit value successfully increased ?

 

 

The /PATH_TO_YOUR_PRESTASHOP_INSTALLATION/ ussually /home/user-ID/public_html/

Link to comment
Share on other sites

Hi,

 

On my backoffice it shows this information. Where memory limit is already 256M.

 

Server information

 

Server information: Linux #1 SMP Wed May 15 08:23:27 CEST 2013 x86_64

 

Server software version: Apache

 

PHP version: 5.4.20

 

Memory limit: 256M

 

Max execution time: 18000

Database information

 

MySQL version: 5.5.34-log

 

MySQL engine: InnoDB

 

Tables prefix: ps_

Store information

 

PrestaShop version: 1.5.4.1

 

Shop URL: http://opticalab.com/

 

Current theme in use: prestadesigner_shoes_store

Mail configuration

 

Mail method: You are using the PHP mail function.

Your information

 

Your web browser: Mozilla/5.0 (Windows NT 6.1; rv:25.0) Gecko/20100101 Firefox/25.0

 

Do i still need to do those changes to server(php.ini)? I am not sure if they are using suPHP. How do i figure out?

 

my prestashop installation path is:

/var/www/vhosts/opticalab.com/httpdocs/

 

Thanks

Link to comment
Share on other sites

Hi,

 

I just did those updates to server and updated .htaccess file as well. Still getting the same error.

 

Fatal error: Allowed memory size of 268435456 bytes exhausted (tried to allocate 72 bytes) in /var/www/vhosts/opticalab.com/httpdocs/controllers/admin/AdminAttributeGeneratorController.php on line 76

 

Thanks

Link to comment
Share on other sites

Hi,

 

I just received php info file from hosting. I can see max_input_vars is already set to 50000.

 

Please check attached rtf file.

 

I can not reduce the number of combinations. I need to have dropdowns with values as shown on following page. Click on Prescription radio button.

 

http://opticalab.com/en/opticalab/34-colours.html

 

Right now its coming up with the module I am developing( Not with combinations).

 

Here is access to website backoffice if you need to look in to.

 

CREDETIALS REMOVED

 

Thanks

php info opticalab.rtf

Link to comment
Share on other sites

Hi Sir,

 

Thanks for your kind effort, guidance and response on this post. I really appreciate it.

 

I have checked the test products added by you on admin area. I see the colors and left axis and lens type combinations are there on the combinations. But when i try to add Left Cylindrical values from +8.00 to -8.00 to the combinations on test product 2, I am still getting following error.

 

Fatal error: Allowed memory size of 268435456 bytes exhausted (tried to allocate 72 bytes) in /var/www/vhosts/opticalab.com/httpdocs/classes/db/DbPDO.php on line 150

 

There are left axis, right cylindrical and few of left cylindrical values on test product1. But when i try to add more of left cylindrical +5.25 to -8.00 and some colors. I am getting following error again.

 

Fatal error: Allowed memory size of 268435456 bytes exhausted (tried to allocate 640 bytes) in /var/www/vhosts/opticalab.com/httpdocs/controllers/admin/AdminAttributeGeneratorController.php(69) : runtime-created function on line 1

 

The combinations are not showing up on product page for test product 1 because Purpose attributes are not added to combination. When i tried to add that to this product. I get following error, which is also because of  same problem (memory exhausted).

 

Internal Server Error

The server encountered an internal error or misconfiguration and was unable to complete your request.

Please contact the server administrator to inform of the time the error occurred and of anything you might have done that may have caused the error.

More information about this error may be available in the server error log.

 

Web Server at opticalab.com



 

With this problem here i am not able to say its  complete or fixed. I need to provide solution to this to my client, thats why I opted for module development as mentioned in the beginning of this post. The requirement here is the user of the website should be able to order the lenses with the range of powers mentioned in dropdowns. -8.00 to +8.00 for left, same for right and 0-180 for axis. The number of combination multiplying thoes values goes very huge. I understand php/server restrictions with such huge values. So in case we cant do  more than that using combinations, we should proceed with module development part mentioned in beginning of this post. If you have some other recommendations kindly guide through.

 

Regards
Vikram

Edited by vikramdhanjal (see edit history)
Link to comment
Share on other sites

  • 7 months later...

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...