在prestashop中安装模块时,如何在“ps_product”表的产品部分和列中添加自定义字段?

时间:2015-09-07 11:28:10

标签: prestashop

我想在prestashop产品部分添加新字段,如:

YouTube HTML5 Video Player

同时,我想在prestashop ps_product 表中添加一个新列。我只想在后台的产品部分。 我已经完成了我的模块部分,但是在安装或卸载时需要添加什么?

<?php
/**
* Prestashop Module Name: sent CURL
* Purpose: It sends curl request when payment successfully done by any payment module.
*/

if (!defined('_PS_VERSION_'))
exit;

class SentCurlToWordprss extends Module
{

  public function __construct()
  {
    /*Define properties for the prestashop module*/

    /*Prestashop Module name should be same as the module folder*/
    $this->name = 'sentcurl';

    /*tab, used to display the module in the modules list tabs.*/
    $this->tab = 'front_office_features';

    /* Module version */
    $this->version = '1.0';

    /* Author for the module */
    $this->author = 'xyz';

    /* Security key used for the module */
    $this->secure_key = Tools::encrypt($this->name);

    parent::__construct();

    /* Module display name, displayed at admin in the modules list */
    $this->displayName = $this->l('Send CURL Module');

    /* Short description for the module */
    $this->description = $this->l('Sends curl request to wordpress after payment done successfully.');

  } /* End of __constructor */

  /**
   *  Installs the module and the associated database tables.
  */
  public function install()
  {
    if (!parent::install() OR !$this->registerHook('orderConfirmation'))
      return false;
    return true;

  } /* End of install member */

  /**
  * Uninstalls the module and delete the associated database tables
  */
  public function uninstall()
  {
    if (!parent::uninstall())
      return false;
    return true;

  } /* End of uninstall member */

  /* Hook member method to send CURL request after successfully payment done by customer
  * @params array: This array has some useful data which may be used or not. This argument is passed by prestashop by default.
  * Later on, you will find it very useful*/
  public function hookOrderConfirmation($params) {

    $customerFirstName = $this->context->customer->firstname;
    $customerLastName =  $this->context->customer->lastname;
    $customerEmail = $this->context->customer->email;
    $userName = $customerFirstName."".$customerLastName;

    //get all order details in Associative array form
    $order = $params['objOrder'];
    $products_with_details = $order->getProductsDetail();
    //print "<pre>";
    //print_r($products_with_details);
    //die("Get Details.");
    foreach ($products_with_details as $productKey => $productValue) {
        $membership_id = $productValue['pro_membership_id'];
        if(!empty($membership_id)) {
            //set POST variables
            $url = 'http://localhost/memtest/web-service/';
            $fields = array(
                        'first_name' => urlencode($customerFirstName),
                        'last_name' => urlencode($customerLastName),
                        'username' => urlencode($userName),
                        'email' => urlencode($customerEmail),
                        'membership_id' => urlencode($membership_id),
                        'password' => urlencode("admin21122"),
                        'password2' => urlencode("admin21122")
                    );

            //url-ify the data for the POST
            foreach($fields as $key=>$value) { $fields_string .= $key.'='.$value.'&'; }
            rtrim($fields_string, '&');

            //open connection
            $ch = curl_init();

            //set the url, number of POST vars, POST data
            curl_setopt($ch,CURLOPT_URL, $url);
            curl_setopt($ch,CURLOPT_POST, count($fields));
            curl_setopt($ch,CURLOPT_POSTFIELDS, $fields_string);

            //execute post
            $result = curl_exec($ch);

            //close connection
            curl_close($ch);

        }
     }

    //Lets display our template file.
    return $this->display(__FILE__, 'sentcurl.tpl');

  } // End of hookOrderConfirmation

} /* End of Send CURL module calss. */

?>

0 个答案:

没有答案