Skyneuron Posted August 9, 2021 Share Posted August 9, 2021 (edited) 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"))); } } Edited August 9, 2021 by Motchanyy (see edit history) Link to comment Share on other sites More sharing options...
Skyneuron Posted August 9, 2021 Author Share Posted August 9, 2021 Disgusting prestashop documentation. It is not surprising why this system is not popular. Link to comment Share on other sites More sharing options...
Shabab Posted August 10, 2021 Share Posted August 10, 2021 Hi, Enable debug mode and send us screenshot error . Link to comment Share on other sites More sharing options...
SmartDataSoft Posted August 10, 2021 Share Posted August 10, 2021 @Motchanyy First of all here we need few information to understand. fro where you will call this ajax class. I saw your first code hook in admin oder but your hooked the ajax in fronted. If you want to fire the ajax in backend. In that case you need to register the admin tab after that you are able to class that ajax tab via jquery or other. If you share your idea details and module code here or PM in that case we are able to give you a good solution Thank you Link to comment Share on other sites More sharing options...
Skyneuron Posted August 10, 2021 Author Share Posted August 10, 2021 5 hours ago, SmartDataSoft said: @Motchanyy First of all here we need few information to understand. fro where you will call this ajax class. I saw your first code hook in admin oder but your hooked the ajax in fronted. If you want to fire the ajax in backend. In that case you need to register the admin tab after that you are able to class that ajax tab via jquery or other. If you share your idea details and module code here or PM in that case we are able to give you a good solution Thank you I need that when I click on the button, a row in the database is deleted. Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now