Zasilkovna / magento2

module Packeta for Magento 2
MIT License
4 stars 6 forks source link

Agree to the terms and conditions #3

Closed adrianalin89 closed 4 years ago

adrianalin89 commented 4 years ago

Hello,

Magento 2.3.3 php 7.1 multistore.

If you have this module installed on your system "Zasilkovna_Shipping" it will conflict whit this module. Zasilkovna_Shipping dose the same thing but it's filled whit bugs.

My first issue after installing: At the shipping methods, the button for selecting a place to ship was not appearing when selected payment z-points whas active. -Reson: in layout xml the module is trying to override an HTML template file. This approach is not good since a lot a module are overriding the same file. -What is this file doing: Basically it's adding a new row in the shipping methods and using ko to show this row if the shipping methods is z-points. This row contains the button that activates the api map where you can select the location of the box. -Fix: A quick fix i've done is to add the row manual in my design folder. A better solution would be in the layout xml file of the module to call a js file on the page. Create this file under js folder and using jquery to create the button and events.

The second issue you may encounter is at the payment method after clicking the place order button you can get this error: "The order wasn't placed. First, agree to the terms and conditions, then try placing your order again." -Reson: The extension in reqier-js map: { '*': { 'Magento_Checkout/js/action/place-order':'Packetery_Checkout/js/view/place-order' } } This is extension is not triggering a js file that adds another parameter to the payment object in the payload. You can spot this by looking in the developer tools / network at the payload send "paymentMethod":{ "method":"cashinstore", "po_number":null, "additional_data":null, "extension_attributes":{ "agreement_ids":[ "1" ] } } If you don't see this key "extension_attributes" then that is the reason. -Fix: Edit this file using the blow cod Packetery/Checkout/view/frontend/web/js/view/place-order.js `define([ 'Magento_Checkout/js/model/quote', 'Magento_Checkout/js/model/url-builder', 'Magento_Customer/js/model/customer', 'Magento_Checkout/js/model/place-order', 'jquery' ], function (quote, urlBuilder, customer, placeOrderService, $) { 'use strict';

var agreementsConfig = window.checkoutConfig.checkoutAgreements;
return function (paymentData, messageContainer) {
    var serviceUrl, payload;

    let pointId = "";
    let pointName = "";

    if( window.packetaPointId !== undefined ){
        if ( window.packetaPointId != "" ){
            pointId = window.packetaPointId;
        }
    }
    if( window.packetaPointName !== undefined ){
        if ( window.packetaPointName != "" ){
            pointName = window.packetaPointName;
        }
    }

    var agreementForm,
    agreementData,
    agreementIds;

    if (!agreementsConfig.isEnabled) {
        return;
    }

    agreementForm = $('.payment-method._active div[data-role=checkout-agreements] input');
    agreementData = agreementForm.serializeArray();
    agreementIds = [];

    agreementData.forEach(function (item) {
        agreementIds.push(item.value);
    });

    if (paymentData['extension_attributes'] === undefined) {
        paymentData['extension_attributes'] = {};
    }

    paymentData['extension_attributes']['agreement_ids'] = agreementIds;

    payload = {
        cartId: quote.getQuoteId(),
        billingAddress: quote.billingAddress(),
        paymentMethod: paymentData,
        packetery:{
            id: pointId,
            name: pointName
        }
    };
    console.log(payload);
    console.log('----------');
    if (customer.isLoggedIn()) {
        serviceUrl = urlBuilder.createUrl('/carts/mine/payment-information', {});
    } else {
        serviceUrl = urlBuilder.createUrl('/guest-carts/:quoteId/payment-information', {
            quoteId: quote.getQuoteId()
        });
        payload.email = quote.guestEmail;
    }

    return placeOrderService(serviceUrl, payload, messageContainer);
};

}); ` This will fix the issue.

The module has some files that are not integrated or called at all and there can be deleted.

Packetery/Checkout/view/frontend/web/js/custom-method-item-template.js
Packetery/Checkout/view/frontend/web/template/custom-method-item-template.html
Packetery/Checkout/view/frontend/web/template/payment/cod.html

Another issue I got is that it's not really multi-store friendly in ..../public_html/app/code/Packetery/Checkout/Model/Misc/PaymentMethod.php function getActiveMethods from Magento\Payment\Model\Config will return active list on default website I will need changing to get the current store id and grab only active payment methods.

I'm not sure but after placing the order i deed not see it in the client admin website. It may not offer this functionality. Also, it would be nice to print the labels from the Magento backend also. Instead of exporting CSV files, we can have another option print labels using api.