Prestashop 1.7 get current step in checkout process - prestashop

The PS website we try to configure has to deliver only in a single state from a specific country but has to allow the billing to any country in the world.
For that, I managed to restrict the country to only one and then by code to change the behaviour of the states dropdown with the following code:
public function getFormat()
{
$format = parent::getFormat();
$format['id_state']->setAvailableValues(
[999 =>'CustomState'],
);
}
The code was placed inside a override of CustomerAddressFormatterCore but using it like this will also restrict the billing states to only one.
Now, we try to capture the steps from the checkout process and up to now without any success
I saw that PS 1.7 uses the class CheckoutProcess function public function getCurrentStep()
Anyone knows how to use that inside an override of the CustomerAddressFormatterCore?
Is that the correct approach? Is there any other better solution?
Thank you!

There is no clear distinction saying that Address X is the billing one, and Address Y is the shipping one, and I'm afraid checking if you're in the context of the checkout step won't help you.
Most of the time, one address is used for both the shipping and the invoice. If someone wants to edit a particular address, you will have information about it in the $_GET params. Unless you're using a third-party OPC module?

Related

Prestashop one step checkout programatically change carrier

I'm dealing with an issue, I've been working in a module that does pretty much the same as a cart rule if you have certan type of products and a certain amount in your cart, the module sets a free shipping carrier for you, this can be achieved with discount codes I know that, but the requierement was specific, Do that ... without using discount codes, So, the site has enabled the one step checkout, the module does it well in the 5 step checkout, but the hook DisplayBeforePayment does not work, I know that maybe it isn't working because of ajax call, To keep it simple, What can I do to get my module working with the One step checkout? (order-opc Controller). Thanks in advance!
I think you need to use a different hook. Please have a look at this page.
If you search for "DisplayBeforePayment", you see it's only used in /controllers/front/OrderController.php. The 5 step checkout uses this controller.
The one step checkout uses a different controller: /controllers/front/OrderOpcController.php.
The hook DisplayBeforePayment is not present in that controller, so that's why i think your module doesn't work on the one page checkout.

WHMCS API: How to override domain price?

I couldn't get a response here. So I figured I'd ask on good ol' reliable stackoverflow.
When you do a call to WHMCS, you can override prices for products:
"priceoverride[0]" = 333;
However, this does not work for domains. The documentation states:
"priceoverride - allows you to pass in a custom price override for the product (domains are not products)"
So, how is one supposed to override the domain price. I have certain "premium domains" that cost most than normal domains and I need to be able to include them on an order with their own price.
Therefore... this wont work:
- Creating an invoice for the domain only means there will be two invoices
- Merging the invoices without sending them sounds like a lot of effort for a field that should just be supported for domains as well
How can I get around this?
Hook OrderDomainPricingOverride can help:
http://docs.whmcs.com/Hooks:OrderDomainPricingOverride
As the cart page is being displayed, this hook is run separately for each Domain added to the cart. You can change price for each of them

VirtoCommerce - Creation of a new payment gateway

I have a big problem dealing with new payment gateway creation. I followed a tutorial but I think I did something wrong because it doesn't work well.
I would like to create a "devis" (sorry I don't know the word in english... It looks like that.
When the customer buys something, he could choose this kind of payment which does nothing but provide the "devis". It would be perfect if the status of the order could be "on hold" directly in order to unhold it when the "real payment" is done.
I hope you have understand what I try to do but if you have not be free to ask me questions.
Here is what I've done:
I created a new class in the VirtoCommerce.PaymentGateways namespace called DevisPaymentGateway which inherits from the PaymentGatewayBase class.
In this class there is just one method: ProcessPayment where I do:
payment.status = PaymentStatus.Completed.ToString();
in the SqlOrderDatabaseInitializer.cs
I created a private SetupDevisGateway method:
private void SetupPaypalGateway(List<PaymentGateway> gateways)
which is called in the CreatePaymentGateways method just after the paypal gateway.
I deployed the database thanks to your powershell script, the gateway
is created as expected.
I enabled the gateway payment via
VirtoCommerce Manager Then I bought something on the website and I
chose the new Payment which is available so it seems to work.
When I click on proceed to checkout I have a new order line which is created
with the "Pending" status so it's perfect...
When I bought something with paypal for example, there was the same reaction BUUUT when the new order line was created there was the onBeforeUpdate method which detected that new line and some work was done asynchronously. With the new gateway it seems that the onBeforeUpdate method doesn't work anymore...
I think that I've forgot something which is done with Paypal and not with my gateway but what and where?
I already know that it's not a good idea to write something in the SqlOrderDatabaseInitializer.cs but I don't think that it's the problem... Does anybody have a solution?
Thanks
Edit: Explanation on what I try to achieve:
Products which are sold are in fact a couple: "images treatments" + "images"
Each customer can manage album and put photos into it, and when he clicks on a product (which is a treatment) he can choose an album.
So it's why I need this event, when the payment is done and the status change from pending to in progress, I send relevant information (about the treatment, the album...) to a queue and I have worker roles (one for each treatment) which read these messages and do some work.
I hope you understand the idea but if you don't, do not hesitate to ask me questions
can you explain why do you need that event? What will you do when that event is raised?
Some explanation below on how status is changed for the order below:
The order status is actually changed by the job "ProcessOrderStatusWork class" that simply runs in the background and changes the status order status from "Pending" to "InProgress" after order has been in pending state for a certain period of time. I would suggesting for you to create a copy of "ProcessOrderStatusWork" class and create a new job (name it MyProcessOrderStatusWork class), that in addition to changing status also adds custom work for your payment. You can then register that Job and disable the one included with VC, so it is not duplicated (by adding it in the database,similar to how you did payment gateway).
It might work for PayPal, because it uses slightly different logic, as order created on call back from PayPal, thus executing in the same web process and event is raised.

Shopify API: Create a Promotion?

Using the Shopify API, is there a way to creation promotions for your store? If not, is there a way to programmatically create promotions in Shopify? (short of using CURL posts to the admin)
That is, I can create a promotion by hand using the admin and navigating to the Promotions and clicking the Add a discount code link. I'd like to be able to do the same thing programmatically, or to know for certain this isn't possible. I don't see any obvious method on the api list, but it seems like something should be an API method.
Unfortunately they don't allow it... I resorted to creating an interface to do so, though:
https://github.com/MartinAmps/Shopify-Private-APIs
Hope it helps
Edit
I also created a blog post about it.
There is no way to create discounts via the API.
If you want we have made an application that can be used to create discount codes.
Otherwise you can use a tool like Mechanize to automate coupon creation for you, but keep in mind theres a good chance that any time in the future it will break since we don't make any promises to keep our admin the same in the future. Any changes have a good chance of breaking whatever script you'd end up writing.
The Price Rules API is now public and allow any app to create price rules and discount codes.
https://help.shopify.com/api/price-rules
If you're familiar with Rails or you're already using ActiveResource for your Shopify API calls, then you can drop in this modified version of Discount < ActiveResource::Base https://gist.github.com/choonkeat/09a56da222f506e627c5

Clickbank - Create products for testing (in Sandbox)

I am new to Clickbank.
I want to try out the API for the same.
But I am stuck in between.
Can anyone guide me through the steps to successfully create a product.
I am getting some errors
You must make a test purchase before submiting this request.
A footer disclaimer is required for all Pitch and Thank You pages.
Also wanted to know, like how can I setup the sandbox account?
Please help me out.
Thanks in advance.
This question was asked a very long time ago but I just happened across it and know the answers.
First, however I think anyone starting on ClickBank, technical or otherwise, will benefit from the following: https://www.clickbank.com/launch-checklist/
Now, to answer the question(s):
Test Purchase:
• Can't do this without creating a product first
• To create a product you do the following:
Login to the account
Click: Vendor Settings -> My Products
On this page locate the list of ADD NEW buttons & Click Product
The product editor pretty well walks you through the process
AND now for the test purchase.
That process is described here: https://support.clickbank.com/hc/en-us/articles/360036958431-How-do-I-test-a-payment-link-
Footer/disclaimer:
This is what is known as the ClickBank Trust Badge currently, (not sure about 9years ago).
It's a little element that you copy and paste into your webpage, after configuring what you want it to look like & where you want it to be, from the available options.
To find and set it up:
Login to the account
Click Vendor Settings -> My Site
Scroll down to the section with the title "ClickBank Trust Badge - Injection Code"
If you like the default setup you can copy what's in the Javascript Snippet field
If you want to change where it's located and colors click the Configure Settings button (not going to describe everything here as it's pretty straight forward as well)
ClickBank APIs
Last, you mentioned wanting to use the ClickBank API, which I happen to know very well. However, the documentation for it is also actually pretty good so let me start off with that:
General ClickBank API documentation
Additionally each APIs primary endpoint is self documenting. Additionally this documentation tends to be the most relevant for a programmer
Example of self documenting endpoint: https://api.clickbank.com/rest/1.3/orders2
So, it's worth noting the following that are required to use the API:
You must have an HTTP header of "Authorization" and it must be set to both of the API keys for an account.
Both keys refers to the API- "Clerk Key" as well as the DEV- "Developer Key"
Enter them both, separated by a colon ":" as the value of the Authorization key with the DEV- key first (DEV-A23478C...:API-IA23456...)
You must also use the correct HTTP request type for the query you are wanting to make (the only two that are utilized are GET and POST)
Examples:(NOTE: ACCOUNT_NAME_HERE is the ClickBank "nickname" or account name)
Single transaction: https://api.clickbank.com/rest/1.3/orders2/RECEIPT_NUMBER_HERE
List transactions by date range and specific account: https://api.clickbank.com/rest/1.3/orders2/list?vendor=ACCOUNTNAME_HERE&startDate=2021-12-11&endDate=2021-12-14
Count of transactions by date range: https://api.clickbank.com/rest/1.3/orders2/count/?vendor=ACCOUNT_NAME_HERE&startDate=2022-01-01&endDate=2022-01-01
Monetary value of transactions by date range: https://api.clickbank.com/rest/1.3/quickstats/count/?account=ACCOUNT_NAME_HERE&startDate=2022-02-01&endDate=2022-02-10
Sending shipping data for physical products (POST): https://api.clickbank.com/rest/1.3/shipping2/shipnotice/4NVXUFNW?item=2&date=2018-08-14&carrier=UPS&tracking=1NH323452345WODFS&comments=Test%20again%20comment%20with%20spaces10%20receipt=4NVXUFNW