How to add shipping method programmatically into carrier in prestashop? - prestashop

I want to add shipping methods programmatically into carrier table using my custom module.

Take a look at the documentation:
https://devdocs.prestashop.com/1.7/modules/carrier/#principles
You might want to look at an example:
https://github.com/prestarocket/myprestashop/blob/9000c9cc2837da1d31f9f69f077aa2c18b452daa/MyCarrierModule.php
https://github.com/FabienSerny/mymodcarrier/blob/d00771b1998bf7ec69196c3a4491e0022f7b6d08/mymodcarrier.php

Related

How can I create a metafield with the type: product, for a shopify input?

I have made several metafields with the type as product, so I know they work, but in this section they don't show up for this link. I can hardcode the link to a specific product, but I want it to be dynamic using metafields. I'm using the palo alto theme.
and this is the result when I click the dynamic source button:
I'd rather leave any theme customization or coding as a last resort.
A link would take a metafield of type url but you are trying to add a metafield of type product. Type product stores the product object with all its data that's not what you need here if you just need to link to the product page.
Id just set up another metafield of type url and pop the url of the product in there.
I'm not familiar with where you are adding this in the Palo Alto theme but unless this is a section that appears on multiple pages, like product pages or blog pages, where you need to link to a different product on each page you may not need a metafield at all.

How to pass optional attribute to the Product via custom add to cart in Prestashop 1.6

I wonder if there's a way to pass some extra information (attribute) by using custom add to cart button.
We've got clear products with their prices. We also sell the same products with print.
Printed version is more expensive. The product is going out from special generator and there, "add to cart button" will be added to where -if that's possible- I would like to pass attribute to this product (so I could change base price to printed)
Is there any way to pass/add this attribute to the product before it will go to cart?
I think the best way to do that would be use combinations - you can make combination with different prices and then you will be able to send combination_id using your extra button.

Add custom fields on adding product in shopify

How to add some extra details while adding products?
Currently I am able to add Variant in Product which shows an input field for the product in product details page. But then, I require to add the same Variants for all products.
My Requirement was to add custom field, e.g. Weight, Height, Wood Type, Color etc. that would appear for all products that are of category Table.
Is this possible some how?
This can be accomplished by creating a new template for your product. You can find some documentation for manually configuration additional product options here.
Most merchants on Shopify use apps to avoid manually configuring additional product options.
A simple task for you would be to add the information using the API for metafields since you are saying they are to be added to all the products. More information on metafields API and liquid are in the links below
Metafield Object and Metafield API
If they are only a few products, you can give this app a spin - ShopifyFD
If the different fields affect the price, create variants. Metafields can also be defined at variant level.
Product metafields can be managed from the Shopify adminpanel directly. You don't need a third-party app or chrome extension anymore!
From the adminpage, go to settings (bottomleft corner) and go to Metafields. From there, you can add the metafields to the product and set the desired contenttype (inputfield, image upload, checkbox, etcetera)
You will need to provide a namespace and key, which you can refer to from the code template. For instance: setting the "namespace and key" field to my_custom_fields.somefield, you will be able to access it from the product template file (product.liquid) like so:
{{ product.metafields.my_custom_fields.somefield }} or, of course, assign it like so:
{% assign myField = product.metafields.my_custom_fields.somefield %}
The created metafields will appear on the product editpage at the bottom. No chrome extensions needed!!
The accurate answer to your question is NO, You can't
But, the good news is there are some apps to accomplish the result. Here is one of the apps which is free!

New module for personal collection/receive with possibility to choose shop (pickup to store)

I want to add possibility for clients to receive orders personally in one of our shops. I tried to find some module which gives possibility to select in which shop they want to receive order but I haven't found anything for free. Because of that I want to create new module for it. What's more I'm totally new in prestashop and I don't know where to start or how to create this module. I spend two-three days reading how to do it and these are my assumptions:
New carrier module can be created by extending CarrierModule class.
I read some articles / documentation about hooks.
I have created my first carrier module by editing module attached in this article http://www.prestashop.com/blog/en/carrier_modules_functions_creation_and_configuration/.
What I achieved is that I installed module and used hook 'BeforeCarrier' to add some layout to page after selecting my carrier.
This is how my carrier should work:
It should be a part of carrier list so customer is able to select it.
If carrier is not selected nothing hapens. If carrier is selected by customer then button 'Choose shop' should be shown.
After pressing button 'Choose shop' new window should be show with addresses of our shops (instead of new window it may be placed somewhere in current page).
Window with shop adresses will contain list of addresses with radiobuttons and button to confirm selection.
After confirmation of selection window will be closed and address should be shown as a part of carreir.
E-mail with confirmation will contain information in which shop customer can collect order.
Suppose that addresses will be hardcoded in php code.
These are my questions:
I created new carrier module so I assume it works correctly (as described here http://www.prestashop.com/blog/en/carrier_modules_functions_creation_and_configuration/).
How to add new button 'Choose shop' near selected carrier?
Can I use hooks to add 'Choose shop' button?
Where should I remember choosen shop address? Has 'Carrier' class place for it?
How to add shop address to e-mails? Should I edit layouts? Does e-mail layout contain place for it or do I need to add new 'placeholder' for it?
How to show chosen address on admin side?
To describe my problem more detail I have created few scenario (see attachment).
I will be greatful for any help.
I've posted the same question on prestashop forum.
These example are usually old and poorly written. They lack structure. But for your purpose I suppose they're ok.
Use hookDisplayCarrierList($args). Check $args to see which carrier has been selected, then return <select> element which you
shop addresses. This hook is triggered every time a user selects a carrier and is return via Ajax. Therefore, you may not use ajax here.
You should include you javascript in a file. Use hookDisplayHeader to detect when to insert this file into your page:
public function hookDisplayHeader(){
$propExists = property_exists($this->context->controller, 'php_self');
if($propExists){
$controllerName = $this->context->controller->php_self;
if(in_array($controllerName, array('order', 'order-opc'))){
// $this->context->controller->addJS($this->_path.'js/customcarrier.js');
This Javascript file should check whether a valid shop has been selected before going to the next step;
Because your Js code is in a file and the hookDisplayCarrierList cannot contain any JavaScript (because it returns Ajax),
you should also make use of hookDisplayBeforeCarrier. Here you could insert you custom carrier ID - this way you'd know
when to check for errors with your JS file.
Same question as #2.
The correct way to save the information would be to add a model. CustomCarrierSelectedAddress - or something like it.
It would have these columns: id_cart, id_shop_address;
The way you implement shop addresses is up to you. You may define them as constants or even make a new model for them.
Models arent that hard to create, you just need to declare class properties, static variable $definition that's it.
You may add you own methods. You should also add createTable()/dropTable() methods for convenience.
This is more complicated. You could:
Send your own email about selected shop address.
Search the controller method which send the email you wish to change.
Then you should override that method by copying the file to your module, delete all the other methods and
rename the class definition inside -> class AdminAddressesController extends AdminAddressesControllerCore
There should be an array of email placeholders and their values, which the controllers assigns.
for example '{order_id}'. You should add your email variable to array {chosen_shop_info} and assign whole
paragraph of text to it. Then you may use it in the actual email template which you can edit in BO.
This is more or less the only way I know to edit the existing templates, because you can't do conditional statements inside email templates.
To add chosen address to order page in BO, you should use another hook - hookDisplayAdminOrder.
here you can add your own block to be display in order summary.
To find out which hooks are available, go to Hook.php and look for method exec(). Add this line error_log($hook_name).
When you perform a specific action, executed hooks will be logged and you will see what kind of hook you need.

Prestashop : Adding a field to choose Shipping carrier in product page front office

I'm using PrestaShop 1.5.5.0.
I want to add a custom check box list to the product page so a customer can choose shipping carrier on the product details page. Can it be possible ? I can add a specific fields in the product details page. As I'm new it's little difficult for me to figure out how can I add other details and carry the values to the order page and that is also dynamically. Is there any module available by which I can accomplish the task ? Please suggest me.
What I want to do is this : Choosing shipping carrier in product page :
http://www.wayfair.com/LifeStyle-Solutions-Zurich-Platform-Bed-LS3-ZUR-X-CP-LF1087.html
Well It's a tough task. You need to work on the controller if you want to carry the values or create a module like shipping estimate and hook it to the product page that might work.