Custom field for specific product in order review at checkout - woocommerce-subscriptions

I have this function that adds a custom field to the review order of all the products.
How can I make this field display only for a specific product?
Thanks a lot!
add_action( 'woocommerce_review_order_after_order_total', 'checkout_review_order_custom_field1' );
function checkout_review_order_custom_field1() {
echo '<td><h6>abcdefg<h6><td>';
}

Related

SuiteScript 2.0 - Load Custom Record Table Data

Within Customization -> List, Records & Fields -> Custom Records I have a table with id: customrecord_{name} with the type "customrecordtype". I have multiple fields in that record
How can I use the load function to get all the data for this table/record? (For all the fields)
const data= record.load({
type: 'customrecord_{name}',
isDynamic: false
... //get all fields
});
I tried to look at the help center but am a bit lost on how to accomplish this.
As far as I know load won't do it. After loading a custom record with load, you can check all the fields of this custom record by calling data.getFields() method. This will return a list of field ids (including custom ones) that you can fetch by calling data.getValue such as data.getValue({'fieldId':'isinactive'}) // a regular field or data.getValue({'fieldId':'custrecord_routeproduce_highpriority'}) // a custom field
loading a custom record, checking its fields, fetching value of a custom field

Netsuite email template - how to get child values from custentity field?

guys!
I'm writing an email template for the invoices. On the invoice form I have a "Project" (internalId: Job) field -> on the "Project" form I have a "custom entity" field with employee-type. I can get an employee's name with ${transaction.job.custentity5}. But I can't get access to related fields such as email, phone number and etc. The code ${transaction.job.custentity5.email} gives me nothing. The code ${transaction.job.custentity5.mobilephone} gives me a strange error like "field job.mobilephone not found" (netsuite hides custentity5 in this objects chain), but I see this field in employee's profile.
How do i get child values from custentity field?
Unfortunately, you can't go into such a deep level with the standard data provided.
You can however fetch the data with a search.lookupFields during a beforeLoad and set it as default value on a custom field of the form.
/**
* #NApiVersion 2.x
* #NScriptType UserEventScript
*/
define(['N/ui/serverWidget', 'N/search'], function(serverWidget, search) {
function beforeLoad(context) {
var invoice = context.newRecord;
var form = context.form;
var type = context.type;
var UserEventType = context.UserEventType;
// only execute during printing...
if (type != UserEventType.PRINT) return
var jobID = invoice.getValue({fieldId: 'job'});
// return when no job/project is set on the invoice...
if (!jobID) return
var job = search.lookupFields({
type: search.Type.JOB,
id: jobID,
columns: ["custentity5"]
})
// return when no employee is set on the project...
if (!(job.custentity5 && job.custentity5[0] && job.custentity5[0].value)) return
var employee = search.lookupFields({
type: search.Type.JOB,
id: job.custentity5[0].value,
columns: ["email", "phone"]
})
var field = form.addField({
id : 'custpage_custom_data_employee',
label: 'Employee',
type : serverWidget.FieldType.LONGTEXT
});
field.defaultValue = JSON.stringify(employee);
}
return {
beforeLoad: beforeLoad
};
})
You can access the data within the template through:
<#if record.custpage_custom_data_employee?has_content>
<#assign employee = record.custpage_custom_data_employee?eval />
</#if>
Netsuite doesn't drill down that far for you. Generally you get one step away from the primary record so you see a name using ${transaction.job.custentity5} because you'd see a name if you opened the associated job record.
How you can show the details from custentity5 depends on a bunch of factors like who is sending this email? Is is special enough to have its own button? Is the email being sent batch etc.
Options:
A before load user event script can check whether the record is being printed or emailed the standard way. That script can load and populate custom fields on the main record so you may be able to reference ${transaction.custpage_ent5.mobilephone} where you'd added the job's custom entity to the transaction
fully script your email using n/Render. You'll likely need to script everything but you can look up and add arbitrary records and datastructures to your renderer. This would be triggered by a custom button or batched script.

GraphQl filter in list field

I'm working on GraphQL API, and I want to filter my data "Products" by sellerId knowing that a product can be sold by several sellers, which means the sellers' field is an array.
Here is the query:
query GetProducts($filterObject:ProductWhereInput!){
products(where:$filterObject){
id
name
description
sku
price
sellers(where:$filterObject.sellers){
id
firstname
lastname
}
images{
url
fileName
}
}
}
Filter variable is defined like that
{
"filter":{
"sellerId":"ckzia0llkfngz0d09mrppd7kh"
}
}
and when I execute this query I get the error
"message": "unknown field 'filterObject.sellers' in variables"
I'm not sure if that's the correct method to apply the filter, it worked for me when I use it for single-value fields, but not with arrays.
If someone could help me, I'll be thankful.
Here you defined $filterObject as a query variable
query GetProducts($filterObject:ProductWhereInput!)
But the way this line is written, it "uses" a variable that is not defined:
sellers(where:$filterObject.sellers)
It's looking for a variable named: "$filterObject.sellers", not a property "sellers" of $filterObject.
Possible solution 1 - server side:
You can change the sellers field definition to use the whole $filterObject and then the resolver function on the server can extract the field it needs.
sellers(where:$filterObject)
This solution makes sense if you have control over the server side.
Possible solution 2 - client side:
If you cannot change the code on the server side, you can define a separate variable and use it instead:
query GetProducts($filterObject:ProductWhereInput!, $filterSellersObject:ProductSellersWhereInput!){
//...
sellers(where:$filterSellersObject){
//...
(assuming ProductSellersWhereInput is a defined type)

insert custom value to table using grocerycrud Add/Edit

I have a table customer with fields id,name,nickname.. I'm using grocery crud for add/edit. The field nickname should be automatically created based upon the name field. Can anyone suggest what can be done to accomplish this
You can accomplish this by using the callback_before_insert function of grocerycrud.
Here is a link to the description: callback_before_insert
Before you render your output add this:
$crud->callback_before_insert(array($this,'create_nickname_callback'));
Add the callback method:
function create_nickname_callback($post_array) {
$post_array['nickname'] = your_nickname_value;
return $post_array;
}

Kohana 3: Validation rule for has_many through relationship

Is it possible to create a validation rule in Kohana 3 that will validate the has_many through relationship?
Using the example on the guide page, a blog post can have many categories through the categories_posts table. Is there a validation rule that can be setup in the Post model to verify at least one category was added?
I tried the following:
public function rules()
{
return array(
'categories' => array(
array(array($this, 'has'), array('categories'))
)
);
}
because I see that the ORM::has function will return true/false. But I think because 'categories' is a relationship, and not a field, the rule I wrote never gets checked.
Any ideas?
You must save Post before adding has_many relations. You can check Post for categories after saving, and mark it as draft if they were not set.
Woo, good idea.
Focus in MVC design pattern. I think that's C business not the M.
if ($post->categories->find_all())
{
//blablabla
}
Since categories is external to the posts table, you'll want to use external validation. Create a function called Model_Post::rule_has_valid_categories($submitted_categories, $post) that returns a boolean denoting whether or not the submitted categories are valid for this post.
Then, create the extra rule just before you try to save the post:
$extra_rules = Validation::factory(array('categories' => $submitted_categories))
->rule(
'categories',
'Model_Post::rule_has_valid_categories',
array(':value', ':model')
);
try
{
$post->save($extra_rules);
}
catch (ORM_Validation_Exception $e)
{
// if categories rule failed, array will contain _external[categories] field
print_r($e->errors('models'));
}
You store the message in /application/messages/models/post/_external.php:
return array(
'categories' => array(
'Model_Post::rule_has_valid_categories' => 'Invalid categories'
),
);

Resources