Prestashop – Unable to Retrieve Axios Parameters in PHP Controller

I’m working on the native BlockWishlist wishlist module. The idea is to add an option in the filtering system by making it customizable by the customer. I added a “custom_order” column to the “ps_wishlist_product” table with the default value of 10000 (so that when sorting the unsorted products end up last). When the “customizable” option is enabled, arrows appear next to products to move products up and down and create a new order. The idea is to record the new order in the database with each move. Initially I wanted to do it in local storage, but if the client changes positions it can be annoying for them to lose their list.
I edited the VueJS view of ProductListContainer.vue in order to add the option and also to be able to order using the vue-draggable module. I can move my elements well. I use Axios because I understand how it works, unlike GraphQL which already seems more technical for what I want to do. So I have two functions: saveOrder and loadOrder.

  • saveOrder allows you to save the position in the list in custom_order (in the database)
  • loadOrder allows to display in order when user chooses “Custom” in sorting options.
    My loadOrder function works well but it’s saveOrder where I have a problem.

Here is the saveOrder method in my VueJS:

async saveOrder() {
        console.log('Saving order...');
        const orderData = this.filteredProducts.map((product, index) => ({
          productId: product.id,
          customOrder: index + 1,
        }));

        try {
          await axios.post('/index.php?fc=module&module=blockwishlist&controller=action&action=saveOrder', {
            wishlistId: this.listId,
            orderData: JSON.stringify(orderData),
          }).then((response) => {
            if (response.data.success) {
              console.log('Order saved successfully!');
            } else {
              console.error('Failed to save order:', response.data.message);
            }
          });
        } catch (error) {
          console.error('Error saving order:', error);
        }
      },

On the controller side I work in /blockwishlist/controllers/front/js/action.php

public function postProcess()
    {
        if (false === $this->context->customer->isLogged()) {
            $this->ajaxRender(
                json_encode([
                    'success' => false,
                    'message' => $this->trans('You aren't logged in', [], 'Modules.Blockwishlist.Shop'),
                ])
            );
            exit;
        }

        $params = Tools::getValue('params');
        $action = Tools::getValue('action');

        if ($_SERVER['REQUEST_METHOD'] === 'POST') {
            if (isset($_POST['wishlistId']) && isset($_POST['orderData'])) {
                // Récupérez les valeurs de 'wishlistId' et 'orderData'
                $wishlistId = $_POST['wishlistId'];
                $orderData = json_decode($_POST['orderData'], true);
            }
        }
        // Here we call all methods dynamically given by the path
        if ($action === 'loadOrder') {
            call_user_func([$this, 'loadCustomOrder']);
            exit;
        }
        if ($action === 'saveOrder') {
            call_user_func([$this, 'saveCustomOrder'], $wishlistId, $orderData);
            exit;
        }
        if (method_exists($this, $action . 'Action')) {
            call_user_func([$this, $action . 'Action'], $params);
            exit;
        }

        $this->ajaxRender(
            json_encode([
                'success' => false,
                'message' => $this->trans('Unknown action', [], 'Modules.Blockwishlist.Shop'),
            ])
        );
        exit;
    }

    // Function to save the custom order of products
    protected function saveCustomOrder($wishlistId, $orderData)
    {
        // Parcourir chaque élément de la commande
        foreach ($orderData as $item) {
            // Mettre à jour la table ps_wishlist_product avec le nouvel ordre personnalisé
            Db::getInstance()->update(
                'ps_wishlist_product',
                ['custom_order' => (int)$item['customOrder']], // Nouvelle valeur de custom_order
                'id_wishlist = ' . (int)$wishlistId . ' AND id_product = ' . (int)$item['productId'] // Conditions de mise à jour
            );
        }

        // Renvoyer une réponse JSON indiquant le succès de l'opération
        $this->ajaxRender(json_encode(['success' => true]));
    }

The problem is that the parameters entered in Axios do not seem to reach the controller. After various tests, the values ​​that go into:

$wishlistId = $_POST['wishlistId'];
$orderData = json_decode($_POST['orderData'], true);

are empty (NULL). I would like to know how to get the values ​​from Axios into my PHP controller.
Send information to ajax

Revieved data

New contributor

Vincent letb is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật