I hope all of you are doing well.
How can i create DateTime field in Module (Vtlib Function) from my CRM vtiger 7.
Category: PHP
Category Added in a WPeMatico Campaign
get_post_meta() get the lowest regular price from all variations
I would like to find the lowest regular price of all variations. For this I have written the following code:
add_action( 'woocommerce_before_add_to_cart_form', 'preis_von' );
function preis_von() {
global $product;
global $post;
$theproductid = array(15174, 15175);
$product_id = method_exists( $product, 'get_id' ) ? $product->get_id() : $product->id;
if(in_array($product_id, $theproductid)) {
$prices = min(get_post_meta( $post->ID, '_regular_price', true ));
//rsort($prices); // sort in descending order
//$minPrice=min($prices);
echo '<div id="preisab" class="abpreis">Preis ab '.$prices.'€ pro Won</div>';
?>
<script>
jQuery(document).ready(function($) {
$( ".variations_form" ).on( "woocommerce_variation_select_change", function () {
document.getElementById("preisab").innerHTML= " ";
});
});
</script>
<?php
}
}
But there is no output. If I use the variation ID instead of $post->ID, I get the output of the regular price for the variation. What did I do wrong?
Style.css file in WordPress child theme doesn’t work
I am using for the first time a child theme on WordPress and I noticed that despite having inserted the customizations in the style.css of the child they are not actually visible in the front-end.
In the child’s functions.php the content is this:
function kerge_child_theme_enqueue_styles() {
$parent_style = 'parent-style';
wp_enqueue_style( $parent_style, get_template_directory_uri() . '/style.css' );
wp_enqueue_style( 'child-style',
get_stylesheet_directory_uri() . '/style.css',
array( $parent_style ),
wp_get_theme()->get('Version')
);
}
add_action( 'wp_enqueue_scripts', 'kerge_child_theme_enqueue_styles' );
The child theme is up and running.
Some suggestions?
How to implement interface that uses another interface that uses the first one, and whose child classes use the concrete classes of those interfaces
For example, there are 2 interfaces:
interface IParser {
function toObject(string $str): IEntity;
}
interface IEntity {
static function getParser(): IParser;
}
And each child class implements interface methods with concrete objects of that class:
class Entity implements IEntity {
static function getParser(): Parser {
return new Parser();
}
}
class Parser implements IParser {
function toObject(string $str): Entity {
return new Entity();
}
}
How to restrict menubar according to users role login in codeigniter?
Hey guys im new to codeigniter i need to restrict menubar according to users role i have 2 table roles and users i have role_id as foreign key in table users how to implement this any sample codes will be helpfull Thanks
Implement website application with CNAME as a unique user
I am currently building a product configurator on a website (example.com). The configurator will consist of products that you as a customer can put together to form a bundle.
This configurator will be available for dealers and on the website I will create a backend for them on the configurator website to login and style the configurator with their own logo, colors, etc.
I would like for the dealers to be able to implement their styled configurator on their own website and a way could be them setting up a subdomain (for example configurator.dealer.com) via a CNAME. The question is, how can I set this up, so each dealer gets their styled configurator shown on their own subdomain?
The CNAME setup has a name and a value. Name should be the subdomain name and the value somehow linking to the configurator with the dealer ID, key or alike. Can it be done by simply using an URL-parameter like example.com?userID=123 in the value and then use this parameter as GET on example.com to show the dealers configurator? Or can we setup a CNAME value in dealer backend that they should use when setting up DNS?
Does anyone know how this is done?
How to use $sample with geo near in mongodb with PHP
I am trying to run a query that allows to find nearby users given a certain maximum distance. I would like that after finding them, it would randomly take 10 documents among those found and I don’t know how to do it.
i tried using $sample but i got several misuse errors. how should i do?
code:
$result = ["coordinate"=> [
'$near'=> [
'$geometry'=> [
"type"=> "Point" ,
"coordinates" => [ 12.099700 , 45.267670 ]
],
'$maxDistance'=> 40000
]
]];
thanks!
Agolia “restrictSearchableAttributes” does not work with too many searchable attributes
I have a search index (for a b2b webshop) with about 200,000 products. For each product, the customer number of the product is stored per customer in a key-value array (key = customer number, value = article number).
Below an example of an item in my search index
{
"id": 45782,
"sku": "12.34.56",
"title": {
"nl": "Accu 12V 230Ah Bosch semitractie"
},
"brand_id": 184,
"brand_name": "bosch",
"customer_references": {
"101028": "ABC-123",
"101029": "DDD-34433",
"101030": "4-243345",
"101031": "4-33333",
},
"category_ids": [
5100,
5091,
5070,
5000
]
}
I have added all these fields to the “searchableAttributes” setting of the index and now I want to indicate per query in which fields can be searched using the restrictSearchableAttributes parameter (because I only want to search in the field corresponding with the customer number of the logged in user). This works fine if I don’t have more than 64 searchable attributes, but in my case I have hundreds of different customer numbers. It still works fine if I add one of the first 64 searchable attributes to the restrictSearchableAttributes parameter, but when I add searchable attribute number 65 or higher to the restrictSearchableAttributes parameter I get no results at all. Anyone an idea how I can fix this?
How to count pages of PDF file with FPDF in magento 2?
I have file pdf already. Now, I want to split file PDF (multi page) to multi file PDF (1 page) using fpdf.
Any solution for this? Or something library php could help this issue.
I am working with magento 2.
Get in-stock product count in a category
I’m using a custom query to get product categories and I want the in-stock product count with them too, I managed to get the count but it shows out-of-stock count too which I don’t want 🙁
Any idea how we can exclude the out-of-stock product count from the in stock?
I did some research and found out we can exclude out-of-stock products https://prnt.sc/8wpCstT_-jrf but it removes the products from the shop page too, I just want to remove them from the count, here is my code:
Thanks in Advance 🙂
function newcats_shortcode() {
$taxonomy = 'product_cat';
$orderby = 'name';
$show_count = 1; // 1 for yes, 0 for no
$pad_counts = 1; // 1 for yes, 0 for no
$hierarchical = 1; // 1 for yes, 0 for no
$title = '';
$empty = 0;
$args = array(
'taxonomy' => $taxonomy,
'orderby' => $orderby,
'show_count' => $show_count,
'pad_counts' => $pad_counts,
'hierarchical' => $hierarchical,
'title_li' => $title,
'hide_empty' => $empty
);
$all_categories = get_categories( $args );
foreach ($all_categories as $cat) {
if($cat->category_parent == 0) {
$category_id = $cat->term_id;
echo '<br /><a href="'. get_term_link($cat->slug, 'product_cat') .'">'. $cat->name .' '. $cat->count .'</a>';
// echo "<pre>", var_dump($cat) ,"</pre>";
}
}
}
add_shortcode( 'newcats', 'newcats_shortcode' );
Anyone let me know how do i create a line chart using PHP and JS with the my code mentioned below? (fix the errors) [closed]
Here’s My DB connection
connection is stable and working
<?php
$servername= "localhost";
$username="root";
$password="";
$dbname="linechart";
$conn=new mysqli($servername, $username, $password, $dbname);
if ($conn){
}
else{
echo "Connection Failed";
}
Here I mentioned the code that need to be fixed
whenever i tried to get the run the code; i met with the blank screen having no output…
<?php include "db.php";?>
<html>
<head>
<script type="text/javascript" src="https://www.gstatic.com/charts/loader.js"></script>
<script type="text/javascript">
google.charts.load('current', {'packages':['corechart']});
google.charts.setOnLoadCallback(drawChart);
function drawChart() {
var data = google.visualization.arrayToDataTable([
['dates', 'sources', 'magnitude'],
<?php
$query="select * from linechart";
$res=mysqli_query($conn, $query);
while ($data=mysqli_fetch_array($res)){
$dates=$data['dates'];
$sources=$data['sources'];
$magnitude=$data['magnitude'];
?>
['<?php echo $dates;?>',<?php echo $sources;?>,<?php echo $magnitude;?>]
<?php
};
?>
]);
var options = {
title: 'SUMMARY',
curveType: 'function',
legend: { position: 'bottom' }
};
var chart = new google.visualization.LineChart(document.getElementById('curve_chart'));
chart.draw(data, options);
}
</script>
</head>
<body>
<div id="curve_chart" style="width: 900px; height: 500px"></div>
</body>
</html>
Thanks in advance …
Check Coockies created by the server not by the user
I was creating a login system but I ran into an issue. I have to use PHP COOKIES. A cookie is created when a user enters the correct username and password. “user=22” or “user=23” etc. But a user can go to the console panel and create this cookie themselves with document.cookie.
isset($_COOKIE[“user”]) returns true even if the cookie is created by user in console panel. So, I have to check the cookies created by the server. Is there a way to do it? Let me know if there is a better way to fix this problem 🙂
PHP & MySQL – Distributing Ticket on Every user [closed]
Is it possible to make a code for Distributing a ticket on user using PHP and MySQLi? Example below.
There is 10 Ticket:
1234
3214
2311
6778
1233
2218
9092
9311
9300
5881
Then 3 User or more:
Juan
Maria
Quibs
I want to distro the 10 ticket on 3 users.
Output is
Juan has : 1234 6778 9092 5881
Maria has : 3214 1233 9311
Quibs has : 2311 2218 9300
i’m fetching data from a table through AJAX and want to convert an element into php variable like-id(so that i can determine whose data is this)
JQuery
i’m fetching data from a table through AJAX and want to convert an element into php variable like-id(so that i can determine whose data is this).
```html
PHP
here is my php code which sending me data after fetch
if (isset( $_POST['sellerid']))
{
// code...
$get = search_ajax($_POST['sellerid']) ;
echo $get ;
}
function search_ajax($seller_id){
global $con ;
$output = '';
$query = "SELECT * FROM dist_register WHERE ( name LIKE '%".$_POST["query"]."%' OR farm_name LIKE '%".$_POST["query"]."%' OR address LIKE '%".$_POST["query"]."%' OR mob_no LIKE '%".$_POST["query"]."%') AND seller_id = '$seller_id'";
$result = mysqli_query($con, $query);
$output = '<ul class="list-unstyled">';
if (mysqli_num_rows($result) > 0)
{
// code...
while ($row = mysqli_fetch_array($result))
{
// code...
$output .='<divv> <li id="add_s">'.$row["farm_name"].", ".$row["address"].'</li>';
$output .='<sup class="ml-4 bg-white mt-0 pt-0" style="font-size:13px;"> Country -: '.$row["country"]. ", Mob.No -: ".$row["mob_no"];
$output .='</sup></divv>';
// $output .='<li>'.$row["property_add"].'</li>';
// $output .='<li>'.$row["property_name"].'</li>';
$output .= '<spann class="text-primary sr-only" id="ss">'.$row["dist_id"].'</spann>';
}
}
else
{
$output .='<divv><li>No data available</li></divv>';
// $output .='';
}
$output .= '</ul>';
// echo $output;
return $output;
}
Laravel test kept failing due to wrong method
I have the following test to check my simple crud application in laravel.
I have my SalesManagersTest.php in tests/features
<?php
use AppProvidersRouteServiceProvider;
use IlluminateFoundationTestingRefreshDatabase;
use TestsTestCase;
class SalesManagersTest extends TestCase
{
use RefreshDatabase;
public function test_can_see_index_screen()
{
$response = $this->get('/salesmanagers');
$response->assertStatus(200);
}
public function test_can_see_add_record_screen()
{
$response = $this->get('/salesmanagers/create');
$response->assertStatus(200);
}
public function test_can_add_new_record()
{
$response = $this->POST('/salesmanagers/create', [
'_token' => csrf_token(),
'full_name' => 'Test User',
'email' => '[email protected]',
'telephone' => '0775678999',
'current_route' => 'Negombo',
'joined_date'=>'2022/09/12',
'comments' => 'Test comment'
]);
$response->assertStatus(200);
$response->assertRedirectedTo('salesmanagers');
}
}
The first two tests work well but the third test is giving me an error
but since I’m trying to insert new record the method has to be POST
this is my web.php
Route::get('/', [ SalesManagersController::class, 'index' ]);
Route::resource('salesmanagers', SalesManagersController::class);
Route::get('salesmanagers.create', [ SalesManagersController::class, 'create' ]);
Route::post('salesmanagers.create', [ SalesManagersController::class, 'store' ]);
What could be the the issue with my test?
