when you add a BigCommerce product to Wishlist, the SKU is not added to {{wishlist.item}} object - bigcommerce

When you add BigCommerce product to Wishlist, the SKU is not added to {{wishlist.item}} object.
I did a {{log wishlist}}, after the product is added, the SKU is null.
the item object has a lot of key fields that are null like availability, summary, stock_level and also boolean values like pre-order, has_options etc. How can i populate them when adding a product to wishlist?
Is there a way to pass the SKU thru "/wishlist.php?action=addWIshlist&product_id={{product.id}} ??
if possible, how and where can i use JS code to pass this value to the wishlist action everytime i add a product to wishlist?

According to BC's Wishlist Object documentation, you should have access to the product's SKU. Now, if you have SKUs set at the variant level, and are trying to access that, you will be out of luck. Products only get added to the wishlist at the product level, and do not contain any variant information.
The issue you might be having is you might be trying to access this data on a page where it is not exposed. The only page where this data is exposed is on the wishlist details page for that wishlist. To access it on another page, you would need to make an AJAX request to the wishlist details page.

Related

Prestashop add custom radio button on shipping carriers on front end checkout

I have created one custom module in Prestashop 1.7.8.7 which will add multiple shipping methods (Carrier) and will show shipping cost based on product dimensions and delivery address. So shipping carrier will look something like this on front-end checkout page. https://prnt.sc/E1avDASyJYYW
Now if someone select SameDay Courier Shipping then i need to show two radio button to select which service they want.
It will have two radio options like
Delivery pickup (by default this option will be selected)
Locker pickup
So if someone select Delivery pickup then it will have different shipping cost and if someone select Locker pickup then it will have different shipping cost.
Can anybody help me how can i achieve this functionality.
While digging, i found that we have file called DeliveryOptionsFinder.php and in that file we have one public function called getDeliveryOptions() where we have this line of code
if ($moduleId = Module::getModuleIdByName($carrier['external_module_name'])) {
$carrier['extraContent'] = Hook::exec('displayCarrierExtraContent', ['carrier' => $carrier], $moduleId);
}
}
So if i set is_module to 1 to all my carriers directly from DB then on frontend checkout page, no carriers is being displayed.
Thanks in advance.
I've already done something like this in the last 2 year as prestashop developer.
The truth is that you can't achieve what you want by "respecting" prestashop processes.
Maybe you can hook using a module the hookDisplayCarrierExtraContent($data) and then return the 2 radios if carrier is certain one (use $data).
But you can't handle a form submit or something else, or include it to prestashop checkout data.
But what you can do as workaround, for example, is the following.
In your module, as I said, hook the extra content, render a template with the 2 radios. Hook displayHeader too and use $this->context->controller->addJS() to add your own js if the current controller is the checkout one.
Then in this JS code you can handle the "change" event of the radios and send an ajax request to your module.
You can create inside {your_module}/controllers/front/ a controller called, for example, radio-choose and handle the js ajax request by saving inside your own table the choosen one.
Obviously you can disable the "next" button in checkout untill one of the two radios are selected, or maybe you can just set a radio button as default one to simplify.
For example your table "ps_cart_choosen_radio" could look like this |id_cart|choosen_radio|.
Then you have all the data you needed. When a cart is converted into an order you will have inside Order object (and ps_orders table as well) the id_cart.
Just select / join choosen radio from your own table by using order's id_cart.
"SELECT choosen_radio FROM ps_cart_choosen_radio WHERE id_cart = {$order.id_cart}"
If you need to show data depending on choosen_radio in frontend you can hook everywhere an order is present and select these data. Or maybe you can edit carrier name in ps_orders table by adding a piece of string. Let' say carrier is "express" and customer choosed "24h". You can update that column with carrier name by changing it to "express-24h" so around the whole prestashop ecosystem everybody will see that's a 24h choice.
Remember that the carrier name related to an order is not the carrier name inside the carriers table. So you can edit it without having trouble.
All these problems comes from the "need" to show some nested choices instead of listing all these in the main selections. In that case it would be easy (just create carrier in the prestashop backoffice)

Can you change the shortID from SKU to variant ID? (Shopify integration)

i'm writing on behalf of our client MOEBE.
Our developer has a problem with the way Roomle use the shortID which is used to add the items into the cart. He says that we need to change the shortID from SKU to product variant ID. Shopify doesn’t allow the cart API to use SKU to add items in the basket.
Alternative if we can get access to the backend in Roomle, then he will be able to create a map between the SKU and variant ID.
Sadly shopify do not allow using SKU codes using Ajax API.
If you modify the process of adding to the cart You probably need use some try and error run.
The very fact of adding a product to the cart can be largely solved by extending the JS code on the product page.
I suggest listing the variants of the product to the variable in the liquid template and using an additional script to handle adding to the cart. It might look dirty, but it will work.
<script type="text/javascript">
var product= `{{ product | json }}`; //Whole product variable
var variant_id = {{ product.variants[0].id }}; //First product variant id
</script>
Do you have one variant per product or more?

Filter BigCommerce products on a custom field using API

I have products in my catalog that benefit from a rebate.
If a product does have a rebate, he has a custom field "rebate" set to 1.
I want to display a page with all products having a rebate, and I'm doing it trough the API.
As I'm new, I'm wondering what should be the syntax to get the custom field value and filter on it.
I'm testing with something like this :
https://api.bigcommerce.com/stores/{store_hash}/v3/catalog/products?include=custom_fields&rebate=1
But not working at all ... I'm getting a 422, saying that rebate is not a valid filter.
Thank you for your help,
Jaad
That's correct--custom_field keys are not a valid filter on a product request. To see the list of valid parameters you can use with a Get Product request, see our documentation here (expand the Query Params section):
https://developer.bigcommerce.com/api-reference/catalog/catalog-api/products/getproducts
You could make the request for all product data and sort the products by custom field key within your application. Or, if you wanted to limit the request to only rebate products, you could tag all rebate products in a Rebate category (this category could even be hidden). Then you could filter the request to get all products that are in that category:
https://api.bigcommerce.com/stores/{store_hash}/v3/catalog/products?categories:in={rebateCategoryID}

How to access Customizable Text Fields From Prestashop Module?

I'm creating a new module for Prestashop where users can design their own product from a third party service. When the user later adds the product to their cart, I would like to save a ID that I get from this Third Party Service where the user designed their product.
I guess the best way to do this is to create a Customization Textfield within Prestashop called "designID". Now I want to know how I save data to this field from module development in Prestashop instead of letting the users manually fill in the data.
So basically... How do I add data to these customizable fields from within a Prestashop module, when the user adds the product to their cart?
These customization fields are used if you are simple user and you are not designing a module. Using it to save the designID will be just a hack.
Since you're creating a new module my advice is to keep the 3rd party ID in a newly created database table, which will match the id_product, id_design, id_cart, id_order, etc...
You can hook to "actionCartSave" and add the record with the matching ids, and all the other required data at your table.
If you want to stick to that Customization feature, add a sample field and review the following database tables:
ps_customization
ps_customization_field
ps_customization_field_lang
ps_customized_data
and replicate the changes when you receive the 3rd party ID.
If all your products will be customized, consider adding the required data in ps_customization_field & ps_customization_field_lang (the table for the field structure) during the module installation, so after it's installed you can just fill
ps_customization & ps_customized_data (the tables for the field data)
PrestaShop does not have proper API for adding customizations, only for retrieving data, so you'll have to write the SQL queries yourself. Just review the ProductController for the ps_customization & ps_customized_data changes and the AdminProductsController for ps_customization_field & ps_customization_field_lang.
Do not forget to remove the Customization markup code from your product & cart templates.
I was able to find this out by myself by first trying to use Customization for a couple of hours without any success.
So basically how my module work is that the customer can open a popup iframe to a third party design tool, the customer then save the design in the iframe, which then sends the data to the parent window (The Prestashop Window).
So to store this I did the following:
Add a new column to the database table ps_cart_product
Hook into any display-hook on the product page and check if any post data is send containing the data from the third party module. If so, then:
if(isset($_POST['thirdparty'])){
$id_product = (int)Tools::getValue('id_product');
if (!$this->context->cart->id){
$this->context->cart->add();
if ($this->context->cart->id)
$this->context->cookie->id_cart = (int)$this->context->cart->id;
}
$this->context->cart->updateQty(1, $id_product);
if(!Db::getInstance()->update('cart_product', array('id_design'=> pSQL(trim($_POST['thirdparty']))) ,'id_cart = '.$this->context->cart->id.' AND id_product = '.(int)Tools::getValue('id_product') ))
$this->context->controller->_errors[] = Tools::displayError('Error: ').mysql_error();
}
So basically first I check if POST is set, then I check if any cart exist, if cart does not exist then add a new cart with ->add() (This function took hours to find, 0 documentation). updateQty() is used to update the cart with the new product.
The last part is the SQL query that updates the value of id_design column with the data that is send from the third party.

Shopify API CARTS - Changing line_item line_price for price Override

Shopify has a CARTS api but it is read-only. I am trying to find a way to manipulate the line_item's line_price or price attribute. Shopify support has directed me here for an answer.
Since there is no proper documentation on this any help would be appreciated.
Products have variants, and a line item has a product ID and a variant ID. A line item has a price too. And no matter how you access that item (using the Ajax API or the backend API) you cannot manipulate the price. If you want to change a price, you have to change the product's variants price. That you do with the backend API and the product or variant calls.
You can't directly manipulate the price of a line item in a cart. As you mentioned, the Carts API is read-only. That's all there is to it.
Yes you can!
Dont mess the people, you can do everything you want with your store.
You can do it via JavaScript, this is some related code i have used:
//update price when changing quantity
function updatePricing() {
jQuery('#quantity').val(jQuery('#choose-select-value option:selected').val());
var quantity = jQuery('#choose-select-value').val();
var unitPriceTotal = jQuery('.product .total-price').text();
var totalPrice = unitPriceTotal * quantity;
jQuery('.product .price').html().replace(regInput ,totalPrice);
}
This is just a way to help you go to the right place...
But please, people dont mess if you dont know something, its your store and you can do anything....
I hope this helps to you to find the way.