How to add custom shipment CS-Cart - cs-cart

I need to add dynamic shipment option to the checkout page, the shipment's pricing, duration and name come from other API.
I tried these hook, none of these invoked during checkout.
'get_available_shippings',
'get_shipping_methods',
'get_shipping_methods_post',
'get_shipments_info_post'
tried to hook shipping_methods_list.pre.tpl
{assign var="s" value=$all_shippings[0][1]}
{$s["shipping_id"] = '2'}
{$all_shippings[0][2] = $s}
I'm using cs-cart 4.14

The right hook was shippings_get_shippings_list_post, since it's not adding to the database, it seems you need to hook orders:shipping_info on the backend for further customization.
function fn_example_addons_shippings_get_shippings_list_post(&$group, &$lang, &$area, &$shippings_info)
{
$package_info = $group['package_info'];
$fromZipcode = $package_info['origination']['zipcode'];
$toZipcode = $package_info['location']['zipcode'];
$weight = (int)round(ceil($package_info["W"]));
$item_price = (int)round(ceil($package_info["C"]));
$shipments = fn_example_addons_getRates($fromZipcode, $toZipcode, $weight, $item_price);
foreach ($shipments as $key => $shipment) {
$shippings_info[$key] = $shipment;
}
}
for the shipments
$shipments["SHIPMENT_ID"] = array(
"shipping_id" => "SHIPMENT_ID",
"shipping" => "Example Shipment"
"delivery_time" => "2-3 days",
"description" => "",
"rate_calculation" => "M",
"service_params" => array(),
"destination" => "I",
"min_weight" => "0.0",
"max_weight" => "0.0",
"service_id" => "0",
"free_shipping" => "N",
"module" => null,
"service_code" => null,
"is_address_required" => "Y",
"rate_info" => array(
"rate_id" => "0",
"shipping_id" => "0",
"rate_value" => array(
"C" => array(
array(
"range_from_value" => 0,
"range_to_value" => "",
"value" => $price_in_point
)
)
),
"destination_id" => "1",
"base_rate" => "0.0"
),
"disable_payments_ids" => array()
);

Related

sum of data in array and add the same sum in same array at bottom

I am self leaner and stuck at getting the sum of array which i am getting.
Ref. attached image showing the array.
for Month of Aug.
"Aug-2022" => array:6 [▼
"annualbuffalomilksalerecordforcustomer" => "8.00"
"annuala2milksalerecordforcustomer" => "5.50"
"annualjerseymilksalerecordforcustomer" => "2.50"
"annualbuffalomilksalerecord" => "168.00"
"annuala2milksalerecord" => "0.00"
"annualjerseymilksalerecord" => "390.00"
Here i want the sum all 6 which is = 574.00
expected result is -
"Aug-2022" => array:6 [▼
"annualbuffalomilksalerecordforcustomer" => "8.00"
"annuala2milksalerecordforcustomer" => "5.50"
"annualjerseymilksalerecordforcustomer" => "2.50"
"annualbuffalomilksalerecord" => "168.00"
"annuala2milksalerecord" => "0.00"
"annualjerseymilksalerecord" => "390.00"
"sumofmilksale" => "574.00"
You could do it like this using the map() function :
$collection = collect([
'Apr-2022' => [
"annualbuffalomilksalerecordforcustomer" => "8.00",
"annuala2milksalerecordforcustomer" => "5.50",
"annualjerseymilksalerecordforcustomer" => "2.50",
"annualbuffalomilksalerecord" => "168.00",
"annuala2milksalerecord" => "0.00",
"annualjerseymilksalerecord" => "390.00",
],
'May-2022' => [
"annualbuffalomilksalerecordforcustomer" => "8.00",
"annuala2milksalerecordforcustomer" => "5.50",
"annualjerseymilksalerecordforcustomer" => "2.50",
"annualbuffalomilksalerecord" => "168.00",
"annuala2milksalerecord" => "0.00",
"annualjerseymilksalerecord" => "390.00",
],
]);
$mapped = $collection->map(function ($entry) {
$sum = array_sum($entry);
return array_merge($entry, ['sumofmilksale' => $sum]);
})
dd($mapped);

Default value for select in custom Modifier

I have a select field from a form defined like bellow. As you can see that select has two values, Yes and No. I'm looking to set a default value for this select.
"children" => [
"bc_offer_is_duration_count_fixed" => [
"arguments" => [
"data" => [
"config" => [
"dataType" => "select",
"formElement" => "select",
"visible" => "1",
"required" => "1",
"validation" => [
'required-entry' => "1"
],
"default" => null,
"label" => __('Is duration count fixed'),
"scopeLabel" => __('[GLOBAL]'),
"code" => "bc_offer_offer_durations",
"source" => "content",
"globalScope" => true,
"sortOrder" => 10,
"componentType" => "field",
"component" => "Project_OfferProducts/js/form/element/offer-is-duration-count-fixed",
'options' => [['label' => __('Yes'), 'value' => '1'], ['label' => __('No'), 'value' => '0']]
]
]
]
]
]
It's part of the modifyData method from a class defined here
use Magento\Catalog\Ui\DataProvider\Product\Form\Modifier\AbstractModifier as CatalogAbstractModifier;
abstract class AbstractModifier extends CatalogAbstractModifier
Obviously I already tried to set "default" => "Yes" and "default" => "1" and "default" => 1
I also have an offer-js-duration-count-fixed.js file with that content
define([
'Magento_Ui/js/form/element/select',
'Project_OfferProducts/js/model/offer-configuration/context'
], function (Select, context) {
'use strict';
return Select.extend({
updatingDurationFromField: false,
initialize: function () {
this._super();
context.isDurationCountFixed.subscribe(function(newValue){
this.refreshInField(newValue);
}.bind(this));
this.value.subscribe(this.refreshInGrid.bind(this));
if(context.isDurationCountFixed())
{
this.value(1);
}
else
{
this.value(0);
}
return this;
},
refreshInGrid: function(){
this.updatingDurationFromField = true;
context.isDurationCountFixed(this.value());
this.updatingDurationFromField = false;
},
refreshInField: function(newValue){
if(!this.updatingDurationFromField)
{
this.value(context.isDurationCountFixed());
}
}
});});
I'm under Magento 2.
just what i think
change this
'options' => [['label' => __('Yes'), 'value' => '1'], ['label' => __('No'), 'value' => '0']]
to
'options' => [['label' => __('Yes'), 'value' => 1], ['label' => __('No'), 'value' => 0]]
and change
"default" => null,
to
"default" => "1",

Elastica Mapping include_type_name

I'm trying to create a mapping from Elastica.
Here is my code to create my index with params of mapping :
$elasticaClient = new ElasticaClient;
$elasticaIndex = $elasticaClient->getIndex('products');
$elasticaIndex->create(
array(
'settings' => array(
'number_of_shards' => 1,
'number_of_replicas' => 0,
'analysis' => array(
'filter' => array(
'french_elision' => array(
'type' => 'elision',
'articles_case' => 'true',
'articles' => array("l", "m", "t", "qu", "n", "s", "j", "d", "c", "jusqu", "quoiqu", "lorsqu", "puisqu"),
),
'french_synonym' => array(
"type" => "synonym",
"ignore_case" => true,
"expand" => true,
"synonyms" => []
),
'french_stemmer' => array(
"type" => "stemmer",
"language" => "light_french"
)
),
'analyzer' => array(
'french_heavy' => array(
'type' => 'custom',
'tokenizer' => 'icu_tokenizer',
'filter' => array('french_elision', 'icu_folding', 'french_synonym', 'french_stemmer', 'asciifolding', 'lowercase')
),
'french_light' => array(
'type' => 'custom',
'tokenizer' => 'icu_tokenizer',
'filter' => array('french_elision', 'icu_folding', 'lowercase', 'asciifolding')
)
)
)
)
),
true
);
$elasticaType = $elasticaIndex->getType('product');
$mapping = new $mapping = new ElasticaTypeMapping;
$mapping->setType($elasticaType);
$mapping->setParam('index_analyzer', 'french_heavy');
$mapping->setParam('search_analyzer', 'french_light');
$mapping->setProperties(
array(
'name' => array(
'type' => 'string',
'boost' => 4
),
'description' => array(
'type' => 'string',
'boost' => 2
),
)
);
$mapping->send();
But I'm having the following error:
Types can not be provided in put mapping requests, unless the include_type_name parameter is set to true.
I can't find how to pass "include_type_name = true" in Ruflin/Elastica.
All my searches return examples in CURL ..
Thank a lot to help me
You seem to be running ES7 and include_type_name is false by default.
You can prevent that error from occurring by changing the last line with this one:
$mapping->send(['include_type_name' => true]);
It's WORK !!
Here is my config :
PHP 7.3.4
Symfony 4.3
Elasticsearch 7.0.1
composer require elasticsearch/elasticsearch "dev-master"
composer require ruflin/elastica "dev-master"
$elasticaClient = new ElasticaClient;
$elasticaIndex = $elasticaClient->getIndex('products');
$elasticaType = $elasticaIndex->getType('product');
$elasticaIndex->create(
array(
'settings' => array(
'number_of_shards' => 1,
'number_of_replicas' => 0,
'analysis' => array(
'filter' => array(
'french_elision' => array(
'type' => 'elision',
'articles_case' => 'true',
'articles' => array("l", "m", "t", "qu", "n", "s", "j", "d", "c", "jusqu", "quoiqu", "lorsqu", "puisqu"),
),
'french_synonym' => array(
"type" => "synonym",
"ignore_case" => true,
"expand" => true,
"synonyms" => []
),
'french_stemmer' => array(
"type" => "stemmer",
"language" => "light_french"
),
),
'analyzer' => array(
'french_heavy' => array(
'type' => 'custom',
'tokenizer' => 'icu_tokenizer',
'filter' => array('french_elision', 'icu_folding', 'french_synonym', 'french_stemmer', 'asciifolding', 'lowercase')
),
'french_light' => array(
'type' => 'custom',
'tokenizer' => 'icu_tokenizer',
'filter' => array('french_elision', 'icu_folding', 'lowercase', 'asciifolding')
),
)
)
)
),
true
);
$mapping = new ElasticaTypeMapping;
$mapping->setType($elasticaType);
$mapping->setProperties(
array(
'name' => array(
'type' => 'text',
'analyzer' => 'french_heavy',
'boost' => 4
),
'description' => array(
'type' => 'text',
'analyzer' => 'french_light',
'boost' => 2
),
)
);
$mapping->send(['include_type_name' => true]);

Get Redis Status Through Ruby

I would like to retrieve the Redis status using a Ruby script, I tried the following commands:
redis_status_command, stdeerr, status = Open3.capture3(`redis-cli -h 127.0.0.1 -p 6379 info|grep status`)
OR
redis_status_command, stdeerr, status = Open3.capture3(`systemctl status redis`)
Then when I try to print the variable redis_status_command it returns a blank space, but I know that the commands that are inside the Open3.capture3 part work in the command line. How can I retrieve the Redis status using Ruby? Thank you
With the "redis" gem, you can get all the info properties as follows:
require 'redis'
client = Redis.new(
url: "redis://your-host.your-domain.com",
port: 6379
)
client.info
The output will be a Hash of the info:
{
"redis_version" => "3.2.4",
"redis_git_sha1" => "0",
"redis_git_dirty" => "0",
"redis_build_id" => "0",
"redis_mode" => "standalone",
"os" => "Amazon ElastiCache",
"arch_bits" => "64",
"multiplexing_api" => "epoll",
"gcc_version" => "0.0.0",
"process_id" => "1",
"run_id" => "73f5f76133b7bfd66eb89850a2f9df43e838f567",
"tcp_port" => "6379",
"uptime_in_seconds" => "1754115",
"uptime_in_days" => "20",
"hz" => "10",
"lru_clock" => "5884700",
"executable" => "-",
"config_file" => "-",
"connected_clients" => "10",
"client_longest_output_list" => "0",
"client_biggest_input_buf" => "0",
"blocked_clients" => "0",
"used_memory" => "16110168",
"used_memory_human" => "15.36M",
"used_memory_rss" => "19808256",
"used_memory_rss_human" => "18.89M",
"used_memory_peak" => "19915496",
"used_memory_peak_human" => "18.99M",
"used_memory_lua" => "37888",
"used_memory_lua_human" => "37.00K",
"maxmemory" => "6501171200",
"maxmemory_human" => "6.05G",
"maxmemory_policy" => "volatile-lru",
"mem_fragmentation_ratio" => "1.23",
"mem_allocator" => "jemalloc-4.0.3",
"loading" => "0",
"rdb_changes_since_last_save" => "30264",
"rdb_bgsave_in_progress" => "0",
"rdb_last_save_time" => "1497302809",
"rdb_last_bgsave_status" => "ok",
"rdb_last_bgsave_time_sec" => "-1",
"rdb_current_bgsave_time_sec" => "-1",
"aof_enabled" => "0",
"aof_rewrite_in_progress" => "0",
"aof_rewrite_scheduled" => "0",
"aof_last_rewrite_time_sec" => "-1",
"aof_current_rewrite_time_sec" => "-1",
"aof_last_bgrewrite_status" => "ok",
"aof_last_write_status" => "ok",
"total_connections_received" => "29746",
"total_commands_processed" => "3809776",
"instantaneous_ops_per_sec" => "1",
"total_net_input_bytes" => "382270539",
"total_net_output_bytes" => "3134102675",
"instantaneous_input_kbps" => "0.05",
"instantaneous_output_kbps" => "0.03",
"rejected_connections" => "0",
"sync_full" => "1",
"sync_partial_ok" => "0",
"sync_partial_err" => "0",
"expired_keys" => "0",
"evicted_keys" => "0",
"keyspace_hits" => "674",
"keyspace_misses" => "318",
"pubsub_channels" => "0",
"pubsub_patterns" => "0",
"latest_fork_usec" => "162",
"migrate_cached_sockets" => "0",
"role" => "master",
"connected_slaves" => "1",
"slave0" => "ip=192.168.1.2,port=6379,state=online,offset=341359205,lag=0",
"master_repl_offset" => "341359205",
"repl_backlog_active" => "1",
"repl_backlog_size" => "1048576",
"repl_backlog_first_byte_offset" => "340310630",
"repl_backlog_histlen" => "1048576",
"used_cpu_sys" => "494.00",
"used_cpu_user" => "912.16",
"used_cpu_sys_children" => "0.00",
"used_cpu_user_children" => "0.00",
"cluster_enabled" => "0",
"db0" => "keys=3479,expires=0,avg_ttl=0"
}

Magento API version incompatibility

I am creating catalog products using Magento's core API. It works fine on Magento version 1.4.1.1, but the same code doesn't work on Magento ver 1.5.0.1.
Here's my code:
require 'rubygems'
require 'soap/wsdlDriver'
WSDL_URL = 'http://example.code/api/v2_soap/?wsdl=1'
soap = SOAP::WSDLDriverFactory.new(WSDL_URL).create_rpc_driver
session = soap.login('theuser','theuser123')
data = { "name" => "BARRACUDA", "description" => "fill", "short_description" => "fill", "weight" => "12", "status" => 1, "visibility" => 4, "price" => 350.00 , "tax_class_id" => "2", "qty" => 10, "stock_availability" => "0", "category_ids" => [3] }
a1 = soap.call('catalogProductCreate',session,"simple",1,"black: ONT-920-B",data)
Is there any problem with my code, or any new things added to Magento version 1.5.0.1?
Thanks
The problem is missing one attribute in date field
data = { "name" => "BARRACUDA", "description" => "fill", "short_description" => "fill", "weight" => "12", "status" => 1, "visibility" => 4, "price" => 350.00 , "tax_class_id" => "2", "qty" => 10, "stock_availability" => "0", "category_ids" => [3], "websites" => [1] }
Need to mention the websites id in the array of data in magento 1.5.
This is works for me!

Resources