Php 覆盖prestashop 1.6控制器并按模块查看

Php 覆盖prestashop 1.6控制器并按模块查看,php,templates,module,prestashop-1.6,Php,Templates,Module,Prestashop 1.6,我是开发prestashop的新手,我使用第页的教程创建了第一个模块,并创建了配置文件。 现在我想覆盖管理员命令控制器和视图。 我需要在视图中添加一个小表单,它将从配置模块中获取一些数据,然后对其进行处理。 据我所知,要实现这一点/modules/my_module/override/controllers/admin/AdminOrdersController.php 在里面我创建了我的类。基本标记: class AdminOrdersController extends AdminOrder

我是开发prestashop的新手,我使用第页的教程创建了第一个模块,并创建了配置文件。 现在我想覆盖管理员命令控制器和视图。 我需要在视图中添加一个小表单,它将从配置模块中获取一些数据,然后对其进行处理。 据我所知,要实现这一点/modules/my_module/override/controllers/admin/AdminOrdersController.php

在里面我创建了我的类。基本标记:

class AdminOrdersController extends AdminOrdersControllerCore
{
    public function __construct()
    {
        parent::__construct();
    }
}
现在我想知道如何在模块文件中覆盖模板。 模板位于:admin999fxzxg5\themes\default\Template\controllers\orders\helpers\view中。 我尝试放入文件夹modules\mymodule\override\controllers\admin\templates\orders\helpers\view,但没有结果

所以我的第一个问题是我可以把模板文件添加到表单中。 然后,我如何在控制器内部编写函数来检索和传递表单中的数据

我可以覆盖表单,但只能覆盖\controllers\admin\templates\orders\helpers\view内部\ 我确信这是错误的方式:) 另外,我复制并粘贴整个“AdminOrdersController.php”,只分配一个变量($this->tpl\u view\u vars…)来检查t是否工作,它是否工作。 现在我想知道在prestashop中进行覆盖的正确方法是什么?另外,如何在覆盖控制器内创建链接并分配新功能

我试着跟踪我找到的一些文档,最终得到了这个代码,但它仍然不起作用。有任何线索表明我做错了什么? Fow现在我只希望在点击链接时,var在运行函数或更新表单之前显示为sad。。 我要覆盖的控制器的代码

    <?php

class AdminOrdersController extends AdminOrdersControllerCore
{
        public function renderView()
    {
        $order = new Order(Tools::getValue('id_order'));
        if (!Validate::isLoadedObject($order))
            $this->errors[] = Tools::displayError('The order cannot be found within your database.');

        $customer = new Customer($order->id_customer);
        $carrier = new Carrier($order->id_carrier);
        $products = $this->getProducts($order);
        $currency = new Currency((int)$order->id_currency);
        // Carrier module call
        $carrier_module_call = null;
        if ($carrier->is_module)
        {
            $module = Module::getInstanceByName($carrier->external_module_name);
            if (method_exists($module, 'displayInfoByCart'))
                $carrier_module_call = call_user_func(array($module, 'displayInfoByCart'), $order->id_cart);
        }

        // Retrieve addresses information
        $addressInvoice = new Address($order->id_address_invoice, $this->context->language->id);
        if (Validate::isLoadedObject($addressInvoice) && $addressInvoice->id_state)
            $invoiceState = new State((int)$addressInvoice->id_state);

        if ($order->id_address_invoice == $order->id_address_delivery)
        {
            $addressDelivery = $addressInvoice;
            if (isset($invoiceState))
                $deliveryState = $invoiceState;
        }
        else
        {
            $addressDelivery = new Address($order->id_address_delivery, $this->context->language->id);
            if (Validate::isLoadedObject($addressDelivery) && $addressDelivery->id_state)
                $deliveryState = new State((int)($addressDelivery->id_state));
        }

        $this->toolbar_title = sprintf($this->l('Order #%1$d (%2$s) - %3$s %4$s'), $order->id, $order->reference, $customer->firstname, $customer->lastname);
        if (Shop::isFeatureActive())
        {
            $shop = new Shop((int)$order->id_shop);
            $this->toolbar_title .= ' - '.sprintf($this->l('Shop: %s'), $shop->name);
        }

        // gets warehouses to ship products, if and only if advanced stock management is activated
        $warehouse_list = null;

        $order_details = $order->getOrderDetailList();
        foreach ($order_details as $order_detail)
        {
            $product = new Product($order_detail['product_id']);

            if (Configuration::get('PS_ADVANCED_STOCK_MANAGEMENT')
                && $product->advanced_stock_management)
            {
                $warehouses = Warehouse::getWarehousesByProductId($order_detail['product_id'], $order_detail['product_attribute_id']);
                foreach ($warehouses as $warehouse)
                {
                    if (!isset($warehouse_list[$warehouse['id_warehouse']]))
                        $warehouse_list[$warehouse['id_warehouse']] = $warehouse;
                }
            }
        }

        $payment_methods = array();
        foreach (PaymentModule::getInstalledPaymentModules() as $payment)
        {
            $module = Module::getInstanceByName($payment['name']);
            if (Validate::isLoadedObject($module) && $module->active)
                $payment_methods[] = $module->displayName;
        }

        // display warning if there are products out of stock
        $display_out_of_stock_warning = false;
        $current_order_state = $order->getCurrentOrderState();
        if (Configuration::get('PS_STOCK_MANAGEMENT') && (!Validate::isLoadedObject($current_order_state) || ($current_order_state->delivery != 1 && $current_order_state->shipped != 1)))
            $display_out_of_stock_warning = true;

        // products current stock (from stock_available)
        foreach ($products as &$product)
        {
            // Get total customized quantity for current product
            $customized_product_quantity = 0;

            if (is_array($product['customizedDatas']))
                foreach ($product['customizedDatas'] as $customizationPerAddress)
                    foreach ($customizationPerAddress as $customizationId => $customization)
                        $customized_product_quantity += (int)$customization['quantity'];

            $product['customized_product_quantity'] = $customized_product_quantity;
            $product['current_stock'] = StockAvailable::getQuantityAvailableByProduct($product['product_id'], $product['product_attribute_id'], $product['id_shop']);
            $resume = OrderSlip::getProductSlipResume($product['id_order_detail']);
            $product['quantity_refundable'] = $product['product_quantity'] - $resume['product_quantity'];
            $product['amount_refundable'] = $product['total_price_tax_excl'] - $resume['amount_tax_excl'];
            $product['amount_refund'] = Tools::displayPrice($resume['amount_tax_incl'], $currency);
            $product['refund_history'] = OrderSlip::getProductSlipDetail($product['id_order_detail']);
            $product['return_history'] = OrderReturn::getProductReturnDetail($product['id_order_detail']);

            // if the current stock requires a warning
            if ($product['current_stock'] == 0 && $display_out_of_stock_warning)
                $this->displayWarning($this->l('This product is out of stock: ').' '.$product['product_name']);
            if ($product['id_warehouse'] != 0)
            {
                $warehouse = new Warehouse((int)$product['id_warehouse']);
                $product['warehouse_name'] = $warehouse->name;
            }
            else
                $product['warehouse_name'] = '--';
        }

        $gender = new Gender((int)$customer->id_gender, $this->context->language->id);

        $history = $order->getHistory($this->context->language->id);

        foreach ($history as &$order_state)
            $order_state['text-color'] = Tools::getBrightness($order_state['color']) < 128 ? 'white' : 'black';

        //felek 

            $my_module_name = Configuration::get('CDSIODEMKA_test1');

        //felek end

        // Smarty assign
        $this->tpl_view_vars = array(
            'test'=>$my_module_name,
            'order' => $order,
            'cart' => new Cart($order->id_cart),
            'customer' => $customer,
            'gender' => $gender,
            'customer_addresses' => $customer->getAddresses($this->context->language->id),
            'addresses' => array(
                'delivery' => $addressDelivery,
                'deliveryState' => isset($deliveryState) ? $deliveryState : null,
                'invoice' => $addressInvoice,
                'invoiceState' => isset($invoiceState) ? $invoiceState : null
            ),
            'customerStats' => $customer->getStats(),
            'products' => $products,
            'discounts' => $order->getCartRules(),
            'orders_total_paid_tax_incl' => $order->getOrdersTotalPaid(), // Get the sum of total_paid_tax_incl of the order with similar reference
            'total_paid' => $order->getTotalPaid(),
            'returns' => OrderReturn::getOrdersReturn($order->id_customer, $order->id),
            'customer_thread_message' => CustomerThread::getCustomerMessages($order->id_customer, null, $order->id),
            'orderMessages' => OrderMessage::getOrderMessages($order->id_lang),
            'messages' => Message::getMessagesByOrderId($order->id, true),
            'carrier' => new Carrier($order->id_carrier),
            'history' => $history,
            'states' => OrderState::getOrderStates($this->context->language->id),
            'warehouse_list' => $warehouse_list,
            'sources' => ConnectionsSource::getOrderSources($order->id),
            'currentState' => $order->getCurrentOrderState(),
            'currency' => new Currency($order->id_currency),
            'currencies' => Currency::getCurrenciesByIdShop($order->id_shop),
            'previousOrder' => $order->getPreviousOrderId(),
            'nextOrder' => $order->getNextOrderId(),
            'current_index' => self::$currentIndex,
            'carrierModuleCall' => $carrier_module_call,
            'iso_code_lang' => $this->context->language->iso_code,
            'id_lang' => $this->context->language->id,
            'can_edit' => ($this->tabAccess['edit'] == 1),
            'current_id_lang' => $this->context->language->id,
            'invoices_collection' => $order->getInvoicesCollection(),
            'not_paid_invoices_collection' => $order->getNotPaidInvoicesCollection(),
            'payment_methods' => $payment_methods,
            'invoice_management_active' => Configuration::get('PS_INVOICE', null, null, $order->id_shop),
            'display_warehouse' => (int)Configuration::get('PS_ADVANCED_STOCK_MANAGEMENT'),
            'HOOK_CONTENT_ORDER' => Hook::exec('displayAdminOrderContentOrder', array(
                'order' => $order,
                'products' => $products,
                'customer' => $customer)
            ),
            'HOOK_CONTENT_SHIP' => Hook::exec('displayAdminOrderContentShip', array(
                'order' => $order,
                'products' => $products,
                'customer' => $customer)
            ),
            'HOOK_TAB_ORDER' => Hook::exec('displayAdminOrderTabOrder', array(
                'order' => $order,
                'products' => $products,
                'customer' => $customer)
            ),
            'HOOK_TAB_SHIP' => Hook::exec('displayAdminOrderTabShip', array(
                'order' => $order,
                'products' => $products,
                'customer' => $customer)
            ),
        );

        return AdminOrdersController::renderView();
    }
}

已解决。为了覆盖AdminOrder,您必须注册新的钩子,并将函数附加到mymodule.php内的钩子。这可能是不久前发布的,但我面临着类似的问题。我已经创建了这个模块,并测试了一个用.tpl文件显示的函数。我可以知道您是如何在自定义模块中覆盖AdminOrdersController.php的吗?基本上我只想添加一个载体过滤器和批量更新的订单。我可以通过编辑我不打算做的核心文件来做到这一点。相反,我只是为这个特性创建了一个模块。参考: