Jump to content

Edit History

Skyneuron

Skyneuron

I can't understand why the error is

1. deleteorders.php

<?php
/**
 * After install clean prestashop cache
 */

use PrestaShop\PrestaShop\Core\Domain\Customer\Exception\CustomerException;
use Symfony\Component\Form\Extension\Core\Type\TextType;

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

class Deleteorders extends Module
{
    // const CLASS_NAME = 'deleteorders';

    public function __construct()
    {
        $this->name = 'deleteorders';
        $this->version = '1.0.0';
        $this->author = 'wfpaisa';
        $this->need_instance = 0;

        parent::__construct();

        $this->displayName = $this->getTranslator()->trans(
            'Cedula123',
            [],
            'Modules.deleteorders.Admin'
        );

        $this->description =
            $this->getTranslator()->trans(
                'Customer cedula',
                [],
                'Modules.deleteorders.Admin'
            );

        $this->ps_versions_compliancy = [
            'min' => '1.7.6.0',
            'max' => _PS_VERSION_,
        ];
    }
    /**
     * This function is required in order to make module compatible with new translation system.
     *
     * @return bool
     */
	
    public function isUsingNewTranslationSystem()
    {
        return true;
    }

    /**
     * Install module and register hooks to allow grid modification.
     *
     * @see https://devdocs.prestashop.com/1.7/modules/concepts/hooks/use-hooks-on-modern-pages/
     *
     * @return bool
     */
    public function install()
    {
        return parent::install() &&
            $this->registerHook('actionGetAdminOrderButtons') &&
            $this->registerHook('actionCustomerFormBuilderModifier') &&
            $this->registerHook('actionAfterCreateCustomerFormHandler') &&
            $this->registerHook('displayAdminOrder') &&
            $this->alterCustomerTable()
        ;
    }

    public function uninstall()
    {
        return parent::uninstall() && $this->uninstallAlterCustomerTable();
    }

    /**
     * Alter customer table, add module fields
     *
     * @return bool true if success or already done.
     */
    protected function alterCustomerTable()
    {
        $sql = 'ALTER TABLE `' . pSQL(_DB_PREFIX_) . 'customer` ADD `cedula` VARCHAR(50) CHARACTER SET utf8 COLLATE utf8_unicode_ci NULL DEFAULT NULL';
        // CLEAN_INSTALATION 1/2  (if you want to delete all data after an installation)
        // comment:
        Db::getInstance()->execute($sql);
        return true;
        // and uncomment:
        // return Db::getInstance()->execute($sql);
    }

    /**
     * Uninstalls sample tables required for demonstration.
     *
     * @return bool
     */
    private function uninstallAlterCustomerTable()
    {
        // CLEAN_INSTALATION 2/2 (if you want to delete all data after an installation)
        // uncomment:
        // $sql = 'ALTER TABLE `' . pSQL(_DB_PREFIX_) . 'customer` DROP `cedula`';
        // return Db::getInstance()->execute($sql);
        // 
        // and comment:
        return true;
    }


    /**
     * Hook allows to modify Customers form and add additional form fields as well as modify or add new data to the forms.
     * FRONT_END
     * @param array $params
     */
    public function hookActionGetAdminOrderButtons($params)
    {
        $order = new Order($params['id_order']);

        /** @var \Symfony\Bundle\FrameworkBundle\Routing\Router $router */
        $router = $this->get('router');

        /** @var \PrestaShopBundle\Controller\Admin\Sell\Order\ActionsBarButtonsCollection $bar */
        $bar = $params['actions_bar_buttons_collection'];

        $viewCustomerUrl = $router->generate('admin_customers_view', ['customerId'=> (int)$order->id_customer]);
        $bar->add(
            new \PrestaShopBundle\Controller\Admin\Sell\Order\ActionsBarButton(
			//['data-toggle' => 'modal'], ['data-target' => 'remove_order'],
                'btn-secondary remove-order', ['href' => '#order-'.$order->id, 'data-toggle' => 'modal', 'data-target' => '#remove_order'], 'View customer'
            )
        );
    }
	
    public function hookDisplayAdminOrder($params)
    {		
		$order = new Order($params['id_order']);

        /** @var \Symfony\Bundle\FrameworkBundle\Routing\Router $router */
        $router = $this->get('router');

        /** @var \PrestaShopBundle\Controller\Admin\Sell\Order\ActionsBarButtonsCollection $bar */
        $bar = $params['actions_bar_buttons_collection'];
		
        //return $text;
		
		global $smarty;
		
		$id_order = $order->id;
		$order = new Order((int) $id_order);
		if (Validate::isLoadedObject($order)) {
			$customer = new Customer($order->id_customer);
		}		
		
		//$smarty->assign('module_templates', dirname(__FILE__).'/views/templates/hook/');
		$smarty->assign(
        array(
            'hook_name' => $order->id,
			'reference' => $order->reference,
			'customer_firstname' => $customer->firstname,
			'customer_lastname' => $customer->lastname,
			'customer_email' => $customer->email
        )
    );
		
		return $this->display(__FILE__, '/views/templates/hook/payment_return.tpl');

    }
	
	

     public function actionAjaxDieDoSomeAction()
    {
        $db = \Db::getInstance();
		$result = $db->delete('log', 'id_log = 3');
    }
}

 
    

2. ajax.php - url: /modules/deleteorders/controllers/front/ajax.php

<?php
class DeleteordersAjaxModuleFrontControllers extends ModuleFrontControllers
{
    public function initContent()
    {
        $this->ajax = true;
        parent::initContent();
    }
 
    public function displayAjax()
    {
        die(Tools::jsonEncode(array('result' => "test")));
    }
}

 

Skyneuron

Skyneuron

I can't understand why the error is

1. deleteorders.php

<?php
/**
 * After install clean prestashop cache
 */

use PrestaShop\PrestaShop\Core\Domain\Customer\Exception\CustomerException;
use Symfony\Component\Form\Extension\Core\Type\TextType;

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

class Deleteorders extends Module
{
    // const CLASS_NAME = 'deleteorders';

    public function __construct()
    {
        $this->name = 'deleteorders';
        $this->version = '1.0.0';
        $this->author = 'wfpaisa';
        $this->need_instance = 0;

        parent::__construct();

        $this->displayName = $this->getTranslator()->trans(
            'Cedula123',
            [],
            'Modules.deleteorders.Admin'
        );

        $this->description =
            $this->getTranslator()->trans(
                'Customer cedula',
                [],
                'Modules.deleteorders.Admin'
            );

        $this->ps_versions_compliancy = [
            'min' => '1.7.6.0',
            'max' => _PS_VERSION_,
        ];
    }
    /**
     * This function is required in order to make module compatible with new translation system.
     *
     * @return bool
     */
	
    public function isUsingNewTranslationSystem()
    {
        return true;
    }

    /**
     * Install module and register hooks to allow grid modification.
     *
     * @see https://devdocs.prestashop.com/1.7/modules/concepts/hooks/use-hooks-on-modern-pages/
     *
     * @return bool
     */
    public function install()
    {
        return parent::install() &&
            $this->registerHook('actionGetAdminOrderButtons') &&
            $this->registerHook('actionCustomerFormBuilderModifier') &&
            $this->registerHook('actionAfterCreateCustomerFormHandler') &&
            $this->registerHook('displayAdminOrder') &&
            $this->alterCustomerTable()
        ;
    }

    public function uninstall()
    {
        return parent::uninstall() && $this->uninstallAlterCustomerTable();
    }

    /**
     * Alter customer table, add module fields
     *
     * @return bool true if success or already done.
     */
    protected function alterCustomerTable()
    {
        $sql = 'ALTER TABLE `' . pSQL(_DB_PREFIX_) . 'customer` ADD `cedula` VARCHAR(50) CHARACTER SET utf8 COLLATE utf8_unicode_ci NULL DEFAULT NULL';
        // CLEAN_INSTALATION 1/2  (if you want to delete all data after an installation)
        // comment:
        Db::getInstance()->execute($sql);
        return true;
        // and uncomment:
        // return Db::getInstance()->execute($sql);
    }

    /**
     * Uninstalls sample tables required for demonstration.
     *
     * @return bool
     */
    private function uninstallAlterCustomerTable()
    {
        // CLEAN_INSTALATION 2/2 (if you want to delete all data after an installation)
        // uncomment:
        // $sql = 'ALTER TABLE `' . pSQL(_DB_PREFIX_) . 'customer` DROP `cedula`';
        // return Db::getInstance()->execute($sql);
        // 
        // and comment:
        return true;
    }


    /**
     * Hook allows to modify Customers form and add additional form fields as well as modify or add new data to the forms.
     * FRONT_END
     * @param array $params
     */
    public function hookActionGetAdminOrderButtons($params)
    {
        $order = new Order($params['id_order']);

        /** @var \Symfony\Bundle\FrameworkBundle\Routing\Router $router */
        $router = $this->get('router');

        /** @var \PrestaShopBundle\Controller\Admin\Sell\Order\ActionsBarButtonsCollection $bar */
        $bar = $params['actions_bar_buttons_collection'];

        $viewCustomerUrl = $router->generate('admin_customers_view', ['customerId'=> (int)$order->id_customer]);
        $bar->add(
            new \PrestaShopBundle\Controller\Admin\Sell\Order\ActionsBarButton(
			//['data-toggle' => 'modal'], ['data-target' => 'remove_order'],
                'btn-secondary remove-order', ['href' => '#order-'.$order->id, 'data-toggle' => 'modal', 'data-target' => '#remove_order'], 'View customer'
            )
        );
    }
	
    public function hookDisplayAdminOrder($params)
    {		
		$order = new Order($params['id_order']);

        /** @var \Symfony\Bundle\FrameworkBundle\Routing\Router $router */
        $router = $this->get('router');

        /** @var \PrestaShopBundle\Controller\Admin\Sell\Order\ActionsBarButtonsCollection $bar */
        $bar = $params['actions_bar_buttons_collection'];
		
        //return $text;
		
		global $smarty;
		
		$id_order = $order->id;
		$order = new Order((int) $id_order);
		if (Validate::isLoadedObject($order)) {
			$customer = new Customer($order->id_customer);
		}		
		
		//$smarty->assign('module_templates', dirname(__FILE__).'/views/templates/hook/');
		$smarty->assign(
        array(
            'hook_name' => $order->id,
			'reference' => $order->reference,
			'customer_firstname' => $customer->firstname,
			'customer_lastname' => $customer->lastname,
			'customer_email' => $customer->email
        )
    );
		
		return $this->display(__FILE__, '/views/templates/hook/payment_return.tpl');

    }
	
	

     public function actionAjaxDieDoSomeAction()
    {
        $db = \Db::getInstance();
		$result = $db->delete('log', 'id_log = 3');
    }
}

 
    

2. ajax.php - url: /modules/deleteorders/controllers/front/ajax.php

<?php
class DeleteordersAjaxModuleFrontControllers extends ModuleFrontControllers
{
    public function initContent()
    {
        $this->ajax = true;
        parent::initContent();
    }
 
    public function displayAjax()
    {
        die(Tools::jsonEncode(array('result' => "test")));
    }
}

 

×
×
  • Create New...