I have a Master/Child grid structure like so:
Parent Grid:
#(Html.Kendo().Grid<ElementViewModel>()
.Name("gridEle")
.Columns(cols =>
{
cols.Bound(e => e.EleNum)
})
.DataSource(dataSource => dataSource
.Ajax()
.Read(read => read.Action("GetElements", "Rating", pi))
)
.ClientDetailTemplateId("tempSubEle")
)
Child Grid as DetailTemplate:
<script id="tempSubEle" type="text/kendo-tmpl">
#(Html.Kendo().Grid<SubElementViewModel>()
.Name("gridSubEle_#=EleID#")
.Columns(cols =>
{
cols.Bound(e => e.Rating)
.ClientTemplate("<input type='checkbox' value='1' " +
"#if(Rating==1){#checked='checked'#}# />" );
})
.DataSource(dataSource => dataSource
.Ajax()
.Read(read => read.Action("GetSubElementsByElementID", "Rating", new {eID = "#=EleID#" }))
)
.ToClientTemplate()
)
</script>
The Problem:
I have a #if{# ... #}# statement in the column ClientTemplate, however the Rating value is from the Parent Grid not the current Child Grid (Parent Grid happen has a column also named 'Rating'), to prove that it is from Parent Grid, if I change Rating to a column that only exists in the Child grid, i.e. SubEleID, it gives error at browser, saying that SubEleID is not found.
The Question:
so what is the syntax for Rating gets the Child Grid value?
just for the sake of trying, I even tried: data.Rating, or $(this).Rating, none worked.
Please advise,
Thank you
# in some kendo template is used for parent property (like you use for the name : gridSubEle_#=EleID#, but for some child property, you have to escape the # with \\ :
cols.Bound(e => e.Rating)
.ClientTemplate("<input type='checkbox' value='1' " +
"\\#if(Rating==1){\\#checked='checked'\\#}\\# />" );
Related
In this list, I want to display out all the items that contains this specific name.
My list items: ['US', 'SG', 'US']
print(list.contains("US"));
Using .contains() returns me a true or false but it doesn’t return me the list of strings that contains that. I want to only extract out the items that has 'US' from the list. In this case, there's 2 of it. Please help!
You can try doing it the following way -
List<String> myList = ['US', 'SG', 'US'];
print(myList.where((item) => item.contains("US")));
You can also display it directly inside a Text widget in the following way -
Text(
myList.where((item) => item.contains("US")).join(" "),
//The join function joins the elements of the Iterable into a single string with the separator provided as an argument.
),
Hope this helps!
UPDATE:
To display each of the word separately as a list you can display them inside a Column in the following way -
Column(
children: myList.map((value) {
if(value.contains("US")){
return Text(value,);
} else {
return Container();
//Return an empty Container for non-matching case
}
}).toList(),
)
The same thing can be used inside a ListView instead of Column if you want it to be scrollable.
Something like this?
var myList = ['US', 'SG', 'US'];
myList.forEach((w){
if(w == "US")
print(w);
});
To show:
class SO extends StatelessWidget {
var myList = ['US', 'SG', 'US'];
#override
Widget build(BuildContext context) {
return Scaffold(
body: Column(
mainAxisSize: MainAxisSize.min,
children: myList.where((w) => w == "US").map((w) => Text(w)).toList(),
),
);
}
}
or for a single line display use, Text instead of Column widget mentioned above
Text(myList.where((w) => w.contains("US")).join(" "))
If you are using "list.contains". It will only show the list exist or not , If you want to print the value you have to use follow :
var fruits = [‘banana’, ‘pineapple’, ‘watermelon’];fruits.forEach((fruit) => print(fruit)); // => banana pineapple watermelon
If you want to print just banana then you can use this
var fruits = [‘banana’, ‘pineapple’, ‘watermelon’];fruits.(fruit) => print(fruit[0]); // => banana
How can I get custom fields into getList function and add they to customer list in backend of opencart?
the following code is form getForm function
// Custom Fields
$this->load->model('customer/custom_field');
$data['custom_fields'] = array();
$custom_fields = $this->model_customer_custom_field->getCustomFields();
$confirmation_info = $this->model_sale_confirmation->getConfirmation($confirmation_id);
foreach ($custom_fields as $custom_field) {
$data['custom_fields'][] = array(
'custom_field_id' => $custom_field['custom_field_id'],
'custom_field_value' => $this->model_customer_custom_field->getCustomFieldValues($custom_field['custom_field_id']),
'name' => $custom_field['name'],
'value' => $custom_field['value'],
'type' => $custom_field['type'],
'location' => $custom_field['location'],
'sort_order' => $custom_field['sort_order']
);
}
$data['download'] = $this->url->link('tool/upload/download', 'user_token=' . $this->session->data['user_token'], true);
if (isset($this->request->post['custom_field'])) {
$data['confirmation_custom_field'] = $this->request->post['custom_field'];
} elseif (!empty($confirmation_info)) {
$data['confirmation_custom_field'] = json_decode($confirmation_info['custom_field'], true);
} else {
$data['confirmation_custom_field'] = array();
}
Custom field values are stored in Json format in oc_customer table custom_field column.
So you can get these values in getList() function and pass them in customers array like this
$data['customers'][] = array(
'account_custom_field'=>json_decode($result['custom_field'], true),
Now you need to get the name of the custom fields for displaying in customer list as columns of the table.
// Custom Fields
$this->load->model('customer/custom_field');
$data['custom_fields'] = array();
$custom_fields = $this->model_customer_custom_field->getCustomFields();
$confirmation_info = $this->model_sale_confirmation->getConfirmation($confirmation_id);
foreach ($custom_fields as $custom_field) {
$data['custom_fields'][] = array(
'custom_field_id' => $custom_field['custom_field_id'],
'custom_field_value' => $this->model_customer_custom_field->getCustomFieldValues($custom_field['custom_field_id']),
'name' => $custom_field['name'],
'value' => $custom_field['value'],
'type' => $custom_field['type'],
'location' => $custom_field['location'],
'sort_order' => $custom_field['sort_order']
);
}
You can create more columns in the table
{% for custom_field in custom_fields %}
<th>{{custom_field.name}}</th>
{% endfor %}
In the each customer row you can find the custom_field in customer's custom field data by matching id of custom field and then displaying the data in that particular column
These array will provide you the column names and then by matching custom_value_id from customer JSON Decode custom values you can display ..
{% for custom_field in custom__fields %}
{% if customer.account_custom_field[custom_field.custom_field_id] %}
{{customer.account_custom_field[custom_field.custom_field_id]}}
{% endif %}
{% endfor %}
There is some more effort required to display the column matching custom value in the right column so use the hint.
I want to add a sub menu in OpenCart, under catalog menu in admin area.
in past we used ocmod or vqmod for do this,
an example by ocmod is here:
<?xml version="1.0" encoding="utf-8"?>
<modification>
<code>submenu5</code>
<name>submenu5</name>
<version>2.3</version>
<author>codertj</author>
<link>codertj.com</link>
<!-- edit header controller -->
<file path="admin/controller/common/column_left.php">
<!-- create link to your page -->
<operation error="log">
<search><![CDATA[if ($this->user->hasPermission('access', 'catalog/product')) {]]></search>
<add position="before"><![CDATA[
if ($this->user->hasPermission('access', 'catalog/product')) {
$catalog[] = array(
'name' => $this->language->get('text_hello_world'),
'href' => $this->url->link('report/helloworld', 'token=' . $this->session->data['token'], true),
'children' => array()
);
}
]]></add>
</operation>
</file>
<!-- edit header template -->
<file path="admin/language/en-gb/common/column_left.php">
<operation error="log">
<search><![CDATA[$_['text_product']]]></search>
<add position="before"><![CDATA[
$_['text_hello_world'] = 'Hello World';
]]></add>
</operation>
</file>
</modification>
Now opencart use of Events system, but I can't find solution for convert this ocmod to event!
You can do that in this way,
We assume that you have recorded the event in the database, if you did not do this, you can create it quickly with the following query:
INSERT INTO `oc_event` (`code`, `trigger`, `action`, `status`) VALUES ('mymodule', 'admin/view/common/column_left/before', 'extension/module/mymodule/addSubmenu', 1)
admin\controller\extension\module\mymodule.php
<?php
class ControllerExtensionModuleMymodule extends Controller {
public function addSubmenu(&$route = false, &$data = false, &$output = false){
$my_language = $this->load->language('extension/module/mymodule');
$data['menus'][1]['children'][] = array(
'name' => $my_language['text_hello_world'],
'href' => $this->url->link('report/helloworld', 'token=' . $this->session->data['token'], true),
'children' => array()
);
}
}
admin\language\en-gb\extension\module\mymodule.php
<?php
$_['text_hello_world'] = 'Hello World!';
I tested this with OpenCart 2.3
How to add admin menu entry for Opencart 3x under a given admin menu item using events
This current topic is about injecting a submenu item above the Catalog -> Products link
Delete the event if it exists, register the event (in your extension on install maybe)
Option A: use Opencart's method
$this->load->model('setting/event');
$this->model_setting_event->deleteEvent('MY_EVENT');
$this->model_setting_event->addEvent('MY_EVENT', 'admin/view/common/column_left/before', 'extension/module/MY_EXTENSION/ADDTOADMINMENU');
Option B: inject your code in the database from an Opencart model (or even from a controller function if you don't care that much about MVC):
$this->db->query("
INSERT INTO
`oc_event`
(`code`, `trigger`, `action`, `status`, `sort_order`)
VALUES
('MY_EVENT', 'admin/view/common/column_left/before', 'extension/module/MY_EXTENSION/ADDTOADMINMENU', 1, 0)
");
Option C: run this query on the Opencart database (from phpMyAdmin, Adminer, etc.):
INSERT INTO
`oc_event`
(`code`, `trigger`, `action`, `status`, `sort_order`)
VALUES
('MY_EVENT', 'admin/view/common/column_left/before', 'extension/module/MY_EXTENSION/ADDTOADMINMENU', 1, 0)
Add the event public function to your extension
public function ADDTOADMINMENU(&$route, &$data){
/**
* Check if current logged in user has permission to access that link
* Replace "extension/module/MY_EXTENSION" with your target path
* This check can very well be ignored/deleted...
**/
if ($this->user->hasPermission('access', 'extension/module/MY_EXTENSION')) {
$my_menu_entry = array(
'id' => 'menu-MY_EXTENSION',
'icon' => 'fa-check',
'name' => 'My menu entry',
'href' => $this->url->link('extension/module/MY_EXTENSION', 'user_token=' . $this->session->data['user_token'], true),
'children' => array()
);
$target_menu_id = 'menu-catalog';
$target_submenu_href = $this->url->link('catalog/product', 'user_token=' . $this->session->data['user_token'], true);
$new_menu = array();
foreach( $data['menus'] as &$menu ) {
if( $menu['id'] == $target_menu_id ) {
$new_submenu = array();
foreach( $menu['children'] as $submenu ) {
if( $submenu['href'] == $target_submenu_href ) {
$new_submenu[] = $my_menu_entry;
$new_submenu[] = $submenu;
} else {
$new_submenu[] = $submenu;
}
}
$menu['children'] = $new_submenu;
$new_menu[] = $menu;
} else {
$new_menu[] = $menu;
}
}
$data['menus'] = $new_menu;
}
}
I’ve a problem with the Coupon API when i make :
$couponCode = "test";
$resultCartCoupon = $proxy->call($sessionId, "cart_coupon.add", array($shoppingCartId, $couponCode));
I always got : Uncaught SoapFault exception: [1083] Coupon is not valid if i try the coupon code in the front end there is no problem. Is there anyone who have ever used this API part with success ?
Thanks.
This error comes from Mage_Checkout_Model_Cart_Coupon_Api::_applyCoupon()
if ($couponCode) {
if (!$couponCode == $quote->getCouponCode()) {
$this->_fault('coupon_code_is_not_valid');
}
}
This looks like it could be a bug, instead it should be if ($couponCode != $quote->getCouponCode()) { but I'm not certain.
It could be that the cart (quote) you're trying to apply the coupon to isn't valid, i.e. doesn't have the qualifying items it needs to receive the coupon. Are you sure $shoppingCartId correctly matches the expected quote in Magento's sales_flat_quote table?
I noticed that the error is in this excerpt:
try {
$quote->getShippingAddress()->setCollectShippingRates(true);
$quote->setCouponCode(strlen($couponCode) ? $couponCode : '')
->collectTotals()
->save();
} catch (Exception $e) {
$this->_fault("cannot_apply_coupon_code", $e->getMessage());
}
In this specific line: ->collectTotals() By removing this stretch , not of error , but not applied the coupon.
After debugging 2-3 hour on API, I have solved this error at my-end. Check below code which i have used in Coupon API.
<?php
$mage_url = 'http://yoursiteurl/api/soap?wsdl';
$mage_user= "API_User"; //webservice user login
$mage_api_key = "API_PASSWORD"; //webservice user pass
$client = new SoapClient($mage_url);
$couponCode = 'couponCode'; // a coupon to be apply
$shoppingCartId = '35'; // a cart Id which i have put test id
$sessionId = $client->login($mage_user, $mage_api_key);
$result = $client->call($sessionId,'cart_coupon.add',array($shoppingCartId,$couponCode));
print_r($result);
?>
The above code gives error that "Uncaught SoapFault exception: [1083] Coupon is not valid". When i debugg the core code i came to know that magento cart.create API insert wrong store id in sales_flat_quote table. I have changed the store id value in sales_flat_quote table manually and again run the Coupon API and after that it works perfectly. So here is the my solution. When you create cart id just run the below update query to change the store id.
<?php
$shoppingCartId = $soap->call( $sessionId, 'cart.create');
$mageFilename = '../app/Mage.php';
require_once $mageFilename;
umask(0);
Mage::app();
$db_write1 = Mage::getSingleton('core/resource')->getConnection('core_write');
$updateQue = "update sales_flat_quote set store_id='1' where entity_id ='".$shoppingCartId."'";
$db_write1->query($updateQue);
// Now run the Coupon API here
?>
Code taken from here : http://chandreshrana.blogspot.in/2015/11/uncaught-soapfault-exception-1083.html
You do not need to write direct SQL to resolve this issue. Just specify store ID parameter in the API call. Example is below is the demo script to apply discount code using Magento SOAP APIs V2 :
/* Set Discount Code */
try
{
$result = $client->shoppingCartCouponAdd($session, $quoteId, 'test123',$storeId);
echo "<br>Apply discount code: ";
var_dump($result);
}
catch(Exception $ex)
{
echo "<br>Discount code Failed: " . $ex->getMessage();
}
To apply discount code, perform following steps :
$quoteId = $client->shoppingCartCreate($session,$storeId);
/* Set cart customer */
$guest = true;
if ($guest)
{
$customerData = array(
"firstname" => "testFirstname",
"lastname" => "testLastName",
"email" => "testEmail#mail.com",
"mode" => "guest",
"website_id" => "1"
);
}
else
{
$customer = array(
"customer_id" => '69301',
"website_id" => "1",
"group_id" => "1",
"store_id" => "1",
"mode" => "customer",
);
}
//Set cart customer (assign customer to quote)
$resultCustomerSet = $client->shoppingCartCustomerSet($session, $quoteId, $customerData,$storeId);
/* Set customer addresses Shipping and Billing */
$addresses = array(
array(
"mode" => "shipping",
"firstname" => "Ahsan",
"lastname" => "testLastname",
"company" => "testCompany",
"street" => "testStreet",
"city" => "Karachi",
"region" => "Sindh",
"postcode" => "7502",
"country_id" => "PK",
"telephone" => "0123456789",
"fax" => "0123456789",
"is_default_shipping" => 0,
"is_default_billing" => 0
),
array(
"mode" => "billing",
"firstname" => "Ahsan",
"lastname" => "testLastname",
"company" => "testCompany",
"street" => "testStreet",
"city" => "Karachi",
"region" => "Sindh",
"postcode" => "7502",
"country_id" => "PK",
"telephone" => "0123456789",
"fax" => "0123456789",
"is_default_shipping" => 0,
"is_default_billing" => 0
)
);
//Set cart customer address
$resultCustomerAddress = $client->shoppingCartCustomerAddresses($session, $quoteId, $addresses,$storeId);
/* Set payment method */
$responsePayment = $client->shoppingCartPaymentMethod($session, $quoteId, array(
'method' => 'cashondelivery',
),$storeId);
/* Set shipping method */
$setShipping = $client->shoppingCartShippingMethod($session, $quoteId, 'flatrate_flatrate',$storeId);
After all above apply discount code,
try
{
$result = $client->shoppingCartCouponAdd($session, $quoteId, 'test123',$storeId);
echo "<br>Apply discount code: ";
var_dump($result);
}
catch(Exception $ex)
{
echo "<br>Discount code Failed: " . $ex->getMessage();
}
I've a problem with dropdown list with Zend Framework 2 & Doctrine.
I would put the "selected" attribute on my dropdown list but all options pass to selected
My code :
Controller :
public function editAction()
{
// get error message during addAction
$this->layout()->setVariable("messageError", $this->flashMessenger()->getErrorMessages());
$auth = $this->getAuthService();
if ($auth->hasIdentity()){
$builder = new AnnotationBuilder();
// Get id of StaticContent
$id = (int)$this->getEvent()->getRouteMatch()->getParam('id');
if (!$id) {
$this->flashMessenger()->addErrorMessage("Aucun plan choisi !");
return $this->redirect()->toRoute('admin/plans');
}
$plan = $this->getEntityManager()->getRepository("Admin\Entity\Plan")->find((int)$id);
$form = $builder->createForm($plan);
// Find options for Localite list (<select>)
$localites = $this->getEntityManager()->getRepository("Admin\Entity\Localite")->getArrayOfAll();
$form->get('localiteid')->setValueOptions($localites);
$form->get('localiteid')->setValue("{$plan->getLocaliteid()->getId()}");
// Find options for TypePlan list (<select>)
$typesPlan = $this->getEntityManager()->getRepository("Admin\Entity\TypePlan")->getArrayOfAll();
$form->get('typeid')->setValueOptions($typesPlan);
$form->get('typeid')->setValue("{$plan->getTypeid()->getId()}");
// Options for Statut list (<select>)
$form->get('statut')->setValueOptions(array('projet'=>'Projet', 'valide'=>'Validé'));
$form->get('statut')->setValue($plan->getStatut());
$form->setBindOnValidate(false);
$form->bind($plan);
$form->add(array(
'name' => 'submit',
'attributes' => array(
'type' => 'submit',
'value' => 'Modifier',
'id' => 'submitbutton',
'class' => "btn btn-primary"
),
));
$request = $this->getRequest();
if ($request->isPost()) {
[...]
}
}
With
$localites = $this->getEntityManager()->getRepository("Admin\Entity\Localite")->getArrayOfAll();
$form->get('localiteid')->setValueOptions($localites);
i populate my dropdown correctly, normally with
$form->get('localiteid')->setValue("{$plan->getLocaliteid()->getId()}");
just set "selected" on option defined by :
$plan->getLocaliteid()->getId()
So why all options are selected in my dropdown ?!
Information : It's the same for typeId but no Statut
It's probably not working because of the curly braces. According to the PHP documentation
Using single curly braces ({}) will not work for accessing the return values of functions or methods or the values of class constants or static class variables.
This is also unnecessary when using setValue. ZF2 will convert it to a string when formatting it in the view.
When you create the arrays to pass to setValueOptions() you should make it an associative array of arrays with the following values:
$form->get('select')->setValueOptions(array(
'field' => array(
'value' => 'value_of_the_option',
'label' => 'what is displayed',
'selected' => true,
),
));
Which ever of the fields has the selected option set to true will be the default selection in the form element.
Personally i don't know if getArrayOfAll() such function exists, i assume that you are correctly passing array to FORM,
I think you should be doing something like this to set value.
$form->get('localiteid')->setValue($plan->getLocaliteid()->getId());
But Since you are populating DROP down i guess this approach will not work best with Drop Down. You need to do something like this
$form->get('localiteid')->setAttributes(array('value'=>$plan->getLocaliteid()->getId(),'selected'=>true));
I've found a bug ?!
$plan = $this->getEntityManager()->getRepository("Admin\Entity\Plan")->find((int)$id);
$idLocalite = 18;//(int)$plan->getLocaliteid()->getId();
$idTypePlan = 2;//(int)$plan->getTypeid()->getId();
When i'm using $plan->getLocaliteid()->getId(); or $plan->getTypeid()->getId() to pass parameter into Repository method getArrayOfAll($idLocalite)
LocaliteRepository.php :
class LocaliteRepository extends EntityRepository {
public function getArrayOfAll($currentLocaliteId) {
$result = $this->_em->createQuery("SELECT l.nom, l.localiteid FROM Admin\Entity\Localite l ORDER BY l.nom")->getArrayResult();
$localite = array();
foreach($result as $loc) {
if ($currentLocaliteId == $loc['localiteid']) {
$localite[$loc['localiteid']] = array(
'value' => $loc['localiteid'],
'label' => $loc['nom'],
'selected' => true,
);
} else {
$localite[$loc['localiteid']] = array(
'value' => $loc['localiteid'],
'label' => $loc['nom'],
'selected' => false
);
//$localite[$loc['localiteid']] = $loc['nom'];
}
}
return $localite;
}
}
So, if i'm using $idLocalite = 18 instead of $idLocalite = (int)$plan->getLocaliteid()->getId() only wanted option are selected. Why ?!