Payment methods only for some shipping methods

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.
13 anos atrás
Hi

Is there any way to load specific payment methods for some specific shipping methods?

For example if i select as shipping method pick up at store it doesnt make any sense to show Cash On Delivery  payment method, but for the shipping method By Air or by Ground makes sense to show Cash On Delivery .

How can i do that?

Thanks in advance for your help.
13 anos atrás
Can anybody help me on this on please?

Thank you.
13 anos atrás
UP!!
Please i need to do the same thing!
Anyone can tell me if it's possible to disable some payment methods for specific shipping methods?
13 anos atrás
Boas Ferreira,

O teu problema não é difícil de resolver, eu também já passei por essa dificuldade e como não encontrei ajuda, meti dedos à obra e aqui está a minha solução, que podes adaptar à tua situação.

Uso a versão 1.60
Uso o módulo "Shipping By Country & Order Weight " modificado para calcular portes em escalas de peso 0-2KH, 2-5Kg, etc da CTT Expresso.

1 - Nos métodos de envio criei os vários escalões de peso dos CTT Expresso e ao primeiro deles chamei-lhe "Entrega no nosso balcão".

2 - Depois de criados todos os escalões fui ao módulo "Shipping By Country & Order Weight" e nas configurações inseri os vários escalões de peso com os respectivos preços e claro inseri também o famoso "Entrega no nosso balcão" com valores a zero euros... Aqui já está.

3- Agora os métodos de pagamento. Uso vários todos sem possibilidade de entrega na loja, mas um deles ficou reservado para "pagamento na loja" para ser associado ao envio "Entrega no nosso balcão". Para esse usei o módulo "PAYINSTORE". Importante para a modificação que fiz: o método ""PAYINSTORE" tem de ser o primeiro da lista de ordenação. Atribui-lhe o valor 1 nas configurações do "PAYINSTORE" e aos outros métodos que tenhas pões números acima desse.

4- Agora abres o teu projecto (com source para puderes recomplilar) e abres \NopCommerceStore\Modules\CheckoutPaymentMethod.ascx.cs

5 - Procuras por:

            //payment methods
            int? filterByCountryId = null;
            if (NopContext.Current.User.BillingAddress != null && NopContext.Current.User.BillingAddress.Country != null)
            {
                filterByCountryId = NopContext.Current.User.BillingAddress.CountryId;
            }

            bool hasButtonMethods = false;
            var boundPaymentMethods = new PaymentMethodCollection();
(a)       var paymentMethods = PaymentMethodManager.GetAllPaymentMethods(filterByCountryId);
(b)       foreach (var pm in paymentMethods)
            {
                switch (pm.PaymentMethodType)

6 - Abre espaço entre (a) e (b), na 1.60 são as linhas 154 e 155.

7 - Insere aí o seguinte código:

            //Remover pagamentos > .00 para entregas na loja
            if (NopContext.Current.User.LastShippingOption.Rate == 0) // Cliente escolheu entrega na loja, não paga nada (Rate=0) de portes
            {
                paymentMethods.RemoveRange(1,paymentMethods.Count-1); // Remove todas excepto a 1ª opção (por isso tem de ser a 1ª da lista, não te esqueças)
            }
            else
            {
                paymentMethods.RemoveAt(0); // Para os pagamentos à distância remove só a opção pagamento na loja.
            }
            //End Remover pagamentos > .00€

8 - Recopila REBUILD, e copia os ficheiros da pasta \NopCommerceStore\BIN para a pasta \BIN do teu servidor. Copia também o ficheiro que alteraste: \Modules\CheckoutPaymentMethod.ascx.cs

9 - Quando se faz alterações aos BIN é normal o servidor demorar um pouco a reagir (digerir) quando tentamos usar uma página pela 1ª vez. Isso é normal.

Depois diz se te safaste. Se quiseres podes traduzir isto para inglês que eu não me apetece :))

Boa sorte
Bento
13 anos atrás
English translation: (sorry that)

(...)
I use version 1.60
I use the module "Shipping Weight By Country & Order" modified to calculate postage weight 0-2Kg, 2-5kg, etc.

1 - In the shipping methods I created the various weight categories and the first one I called him "Delivery on our balcony".

2 - After I have created all weight tables I went to the module "Shipping Weight By Country & Order" and enter the settings for the various weight categories with their prices and of course also enter the famous "Delivery on our balcony" with value zero euros.

3 - Now the payment methods: I use several, all without the possibility of delivery at the store, but one was reserved to "pay at the store" to be associated with sending "Delivery on our balcony." For this I used the module "PAYINSTORE. Important for the change I made: the method "PAYINSTORE" has to be the first in the ordering list. Assigns it a value 1 and to the other methods that you will have, put numbers above it.

4 - Now you open your project (with source) and open \NopCommerceStore\Modules\CheckoutPaymentMethod.ascx.cs

5 - Find:

            //payment methods
            int? filterByCountryId = null;
            if (NopContext.Current.User.BillingAddress != null && NopContext.Current.User.BillingAddress.Country != null)
            {
                filterByCountryId = NopContext.Current.User.BillingAddress.CountryId;
            }

            bool hasButtonMethods = false;
            var boundPaymentMethods = new PaymentMethodCollection();
(a)       var paymentMethods = PaymentMethodManager.GetAllPaymentMethods(filterByCountryId);
(b)       foreach (var pm in paymentMethods)
            {
                switch (pm.PaymentMethodType)

6 - Open space between (a) and (b): at 1.60 are the lines 154 and 155.

7 - There insert the code:

            //Remov payments > .00 for Delivery on our balcony
            if (NopContext.Current.User.LastShippingOption.Rate == 0) // If the customer chooses delivery at the store, pay nothing (Rate = 0)
            {
                paymentMethods.RemoveRange(1,paymentMethods.Count-1); // Remove all but the 1st option (so it must be the 1st in the list, do not forget)
            }
            else
            {
                paymentMethods.RemoveAt(0); // For remote payments removes only the payment option at the store.
            }
            //End Remov payments > .00

8 - SAVE, REBUILD and COPY \NopCommerceStore\BIN\Modified files to yoursite\BIN. COPY also \Modules\CheckoutPaymentMethod.ascx.cs

Good luck
Bento
13 anos atrás
I tries the same but its not working. Can i miss something in it/
This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.