Best way to add eCommerce solution to a wordpress website and tools I can use to add custom business card designing [closed]

I have build a website for a printing business using wordpress with basic pages like About us, Contact and Services Information. Now the owner wants to add features something similar to VistaPrint (Not all only some) like to be able for users to Design their own Business Cards and then Order it using an eCommerce Store.
I know a bit of javascript and React but not that much experienced.I am looking for some good suggestions on two things

  • Either I use Node js and React to build such a solution (Ofcourse i still have to learn more) and then figure out how to integrate React application with existing wordpress website
  • OR I need some ideas on Plugins to use on wordpress to do this (I don’t want to go this way as i want to experience React)

If someone has done something similar please share your experience . Rebuilding the entire website is not an option as its not cost effective.

Replace elements of array

I have two arrays as follows:

array1 = [
 {
  "id":"1",
   "name":"George",
   "City":"california"
 },
 {
  "id":"2",
   "name":"James",
   "City":"Paris"
 },
  {
  "id":"3",
  "name":"Julie",
  "City":"rome"
 }
]

array2 = [
 {
  "id":"2",
   "name":"jonty",
   "City":"wales"
 },
 {
  "id":"5",
   "name":"kite",
   "City":"mumbai"
 },
  {
  "id":"3",
  "name":"neha",
  "City":"pune"
 }
]

I want to check if any element with particular id in array2 exist in array1. If element with that id exist, then replace that element in array1 else push that element in array1. Final array will look as follows:

finalArray = [
{
  "id":"1",
   "name":"George",
   "City":"california"
 },
 {
  "id":"2",
   "name":"jonty",
   "City":"wales"
 },
  {
  "id":"3",
  "name":"neha",
  "City":"pune"
 },
 {
  "id":"5",
   "name":"kite",
   "City":"mumbai"
 }
]

How can I do that?

Why Jest .toHaveBeenCalled() returns 0

In component I have a button which redirects to another page

        const handleAddButton = () => {
        navigate('url');
    };

I try to testing the case when function calls after clicking on a button. But test returns 0.

        it('lick on a button', async () => {

        const onClick = jest.fn()
            render(
            <Wrapper >
                <Component onClick={onClick} />
            </Wrapper>
        );
        fireEvent.click(screen.getByText('Add Button'))
    });
})

I use jest + react testing library. Could you please explain to me why it happens?

Is there a method to enlarge/upscale image without increasing the pixel thickness of the edge

I have a image need to upscale, I use sharp(node.js) to execute this action. the pixel count of the original image edge in a line of the vertical direction is about 3, after upscaling by 4 times, the result pixel count is more than 10. how can I keep the pixel thickness of the edge after scaling operation. I tried many methods and failed, the only ideal result is from the webpage service (AI Image Enlarger). can I reach this on my local machine? any help would be great appreciated.
Below is my code

sharp_resize(`/Users/cc/Desktop/alpha.png`, `/Users/cc/Desktop/alpha_x4.png`)
function sharp_resize(srcPath, targetPath) {

    const dimensions = sizeOf(srcPath)
    let width = dimensions.width
    let height = dimensions.height

    sharp(srcPath)
        .resize(width*4,height*4,{
            kernel: sharp.kernel.lanczos3,
        })
        .toFile(targetPath, (err, info) => { 
            console.log(`sharp resize ${targetPath}`);
        });
}

the upscaling effects

Cannot read properties of undefined (reading ‘DateTime’) even I check there is a data in React.js

I’m just getting learning React a few weeks ago. So, If I ask a pretty general question, I am sorry. But, It would be really appreciated if you help me out!

  • Issue
    : Cannot read properties of undefined (reading ‘DateTime’)

  • What I try to solve it
    : Firstly, I tried to solve it generally. I mean I add the condition to progress my code and re-render. Also, I check the data exist or not.

  • Code

  const changeWeekendDateColor = () => {
    let eventArray = [];
    let weekendArray = [];
    if (weekendData && weekendData.event && weekendData.schedule) {
      let status = false;
      const dataEventLength = weekendData.event.length;
      const dataWeekendLength = weekendData.schedule.length;

      for (let i = 0; i <= dataEventLength; i++) {
        eventArray.push(weekendData.event[i].DateTime.split("T")[0]);
      }

      for (let i = 0; i <= dataWeekendLength; i++) {
        weekendArray.push(weekendData.schedule[i].split(" ")[0]);
      }
    }

    for (let i = 0; i <= eventArray.length; i++) {
      if (weekendArray.includes(eventArray[i])) return (status = false);
    }

    return status;
  };
  console.log(changeWeekendDateColor(weekendData));

WeekendData is this one

enter image description here

  • What I expect
    : I add if statement
if (weekendData && weekendData.event && weekendData.schedule)

So, I think this should be work because if there is no data, it shouldn’t do the next line. I am not sure why my code couldn’t approach the weekendData.event.DateTime…

enter image description here

Intersection observer – How do you remove a class after leaving the view port

I am adding a class when a div gets into the viewport using Intersection Observer. I just can’t figure out how to remove the class when the div leaves the viewport. This is what I have so far:

const callback = function (entries) {
    entries.forEach(entry => {
        if(entry.isIntersecting)
        {
            entry.target.classList.add('animate1');
          observer.unobserve(entry.target)
          }
    });
}
const observer = new IntersectionObserver(callback);
const targets = document.querySelectorAll('.overlay');
targets.forEach(target => {
    observer.observe(target);
})

How to add legend in Google Map JavaScript in code behind?

I am creating a amp project with the coordinates from database. I put my javascript in server side code in asp.net C#. I have created the map successfully but I can not show legend in the map.
I have get the marker from custom image file.

Please take a look at my code and advice me to solve my problem.

private void BuildScript(DataTable tbl, DataTable dtableCHT)
    {
        int i = 0;
        String Locations = "", Location = "", Latitude = "", Longitude = "", District = "", Total_Upazila = "", Img = "", ISA_NameB = "", DPM_NameB = "", DPM_Contact="", DistrictID="";
        foreach (DataRow r in tbl.Rows)
        {
            // bypass empty rows        
            if (r["Lat"].ToString().Trim().Length == 0)
                continue;

            Latitude = r["Lat"].ToString();
            Longitude = r["Long"].ToString();
            District = r["DistrictB"].ToString();
            Total_Upazila = r["Total_Upazila"].ToString();
            ISA_NameB = r["ISA_NameB"].ToString();
            DPM_NameB = r["DPM_NameB"].ToString();
            DPM_Contact= r["ContactNo"].ToString();
            DistrictID = r["DistrictID_DPE"].ToString();
            Img = "/img/icons/mapicon1.png";



            // create a line of JavaScript for marker on map for this record
            Locations += "['" + District + "'," + Latitude + " , " + Longitude + " , " + i + ",'" + Total_Upazila + "','" + ISA_NameB + "','" + Img + "','" + DPM_NameB + "','" + DPM_Contact + "','" + DistrictID + "'],";
            i++;
        }
        foreach (DataRow r in dtableCHT.Rows)
        {
            // bypass empty rows        
            if (r["Lat"].ToString().Trim().Length == 0)
                continue;

            Latitude = r["Lat"].ToString();
            Longitude = r["Long"].ToString();
            District = r["DistrictB"].ToString();
            Total_Upazila = r["Total_Upazila"].ToString();
            ISA_NameB = r["ISA_NameB"].ToString();
            DPM_NameB = r["DPM_NameB"].ToString();
            DPM_Contact = r["ContactNo"].ToString();
            DistrictID = r["DistrictID_DPE"].ToString();
            Img = "/img/icons/mapicon2.png";



            // create a line of JavaScript for marker on map for this record
            Locations += "['" + District + "'," + Latitude + " , " + Longitude + " , " + i + ",'" + Total_Upazila + "','" + ISA_NameB + "','" + Img + "','" + DPM_NameB + "','" + DPM_Contact + "','" + DistrictID + "'],";
            i++;
        }

        //JavaScript for Google api

        js.Text = @"<script>
                        function initMap() {

                            var locations = [ " + Locations + @"
                            ];

                            var map = new google.maps.Map(document.getElementById('dvMap'), {
                                zoom: 7,
                                center: new google.maps.LatLng(23.6850, 90.3563),
                                mapTypeId: google.maps.MapTypeId.ROADMAP
                            });

                            var infowindow = new google.maps.InfoWindow({});

                            var marker, i;

                            for (i = 0; i < locations.length; i++) {
                                marker = new google.maps.Marker({
                                    position: new google.maps.LatLng(locations[i][1], locations[i][2]),
                                    map: map,
                                    icon: locations[i][6]
                                });

                                google.maps.event.addListener(marker, 'click', (function (marker, i) {
                                    return function () {
                                        var html = ('<p><b>জেলা: </b>'+ locations[i][0]+'<br>'+'<b>মোট উপজেলার সংখ্যা: </b>'+locations[i][4]+'<br>'+'<b>বাস্তবায়ন সহায়ক সংস্থা: </b>'+locations[i][5]+'<br>'+'<b>জেলা প্রোগ্রাম ম্যানেজারের নাম: </b>'+locations[i][7]+'<br>'+'<b>মোবাইল নং: </b>'+locations[i][8]+'<br>'+'<a href=map_detail.aspx?param='+locations[i][9]+'>Click for Detail</a><br>'+'</p>')
                                        infowindow.setContent(html);
                                        infowindow.open(map, marker);
                                    }
                                })(marker, i));
                            }
                            map.controls[google.maps.ControlPosition.LEFT_BOTTOM].push(legend);
                        }
                </script>";

    }      

Thanks

How to setup Physicsjs with CoffeeScript?

Firstly,I’m disappointed that physicsjs is no longer maintained. As I am new to coffeescipt.I would like to setup coffeescipt with physicsjs.

I have written some code in a gulp file for automation:
Here it is:

const gulp = require("gulp")
const less = require("gulp-less")
const sourcemaps = require("gulp-sourcemaps")
const coffee = require("gulp-coffee")
const inject = require("gulp-inject")
const sources = {
    js: 'public/js/*.js',
    css: 'public/css/*.css'
}
gulp.task("inject", function (done) {
    gulp.src('./public/*.html')
        .pipe(inject(gulp.src([sources.css, sources.js], {
            read: false
        }), {
            relative: true
        })) // This will always inject vendor files before app files
        .pipe(gulp.dest('./public'));
    done()
})


gulp.task('less', function (done) {
    gulp.src(['src/less/**/*.less', 'src/less/*.less'])
        .pipe(sourcemaps.init())
        .pipe(less({
            base: true,
            paths: ['src/less/include']
        }))
        .pipe(sourcemaps.write('./maps'))
        .pipe(gulp.dest('public/css'))
    done()
})
//  
gulp.task('coffee', function (done) {
    gulp.src(["src/coffee/*.coffee",'src/coffee/**/*.coffee'])
        .pipe(sourcemaps.init())
        .pipe(coffee({
            base: true
        }))
        .pipe(sourcemaps.write('./maps'))
        .pipe(gulp.dest('public/js'))
    done()
})

gulp.task('watch', gulp.series(['less', 'coffee', 'inject'], function (done) {
    gulp.watch(["src/coffee/*.coffee", "src/coffee/**/*.coffee"], gulp.series(['coffee']))
    gulp.watch(["src/less/*.less", "src/less/**/*.less"], gulp.series(['less']))
    // gulp.watch(["public/**/*.html", "public/*.html"], gulp.series(['inject']))
    done()
}))
gulp.task('default', gulp.series(['watch']))

How can I integrate coffeescript with physicsjs?
I would like to make coffeescript work with physicsjs as I cannot find any coffeescript and physicsjs documentation online.

Material UI List Item Text: Primary Text Overflow

Sorry if this has been asked, I looked and couldn’t find the answer!

I have a Material UI listview that has a set width (it’s in a sidebar). I am trying to render the titles of some options, and the Primary text of ListItemText is wrapping past its container. Why is it not simply extending the container’s height and going multi-line?

Thanks so much in advance!

return (
            <ListItem
              key={network._id}
              selected={user.network && user.network._id === network._id}
            >
              <ListItemText
                primary={network.name}
                sx={{ maxWidth: '100%' }}
              />
              <IconButton>
                <DoubleArrowIcon />
              </IconButton>
            </ListItem>
          );

See the text in the ListItemText element overflowing.

Javascript Array Array.push JSON.parse(jsonobject) gives back weird array [duplicate]

<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js" type="text/javascript"></script>
<script type="text/javascript">
 function DrawGraph(CanvasIdName/*text*/,proxyUrl/*proxy to pull data from herefor there needs to be a proxy server set up with a json format*/,dataName/*name of object in the json*/,height/*number*/, width/*number*/,spacing/*ammount of data points in lefttable*/,lineWidth/*float*/, lineColor/*text/rgb(r,g,b)/rgba(r,g,b,a)/hex*/,drawGuidingLines/*boolean*/) {

    let data = [];
    $.ajax({type: "GET", url: proxyUrl, datatype: "json",success: function(json){
    var obj = JSON.parse(json);
    for(var k in obj)
    data.push(obj[k][dataName]);
    }});

    console.log(data); /*this is important!!!!!!!!!!!!!!!!!!!!! FOR THE STACKOVERFLOW POST*/
    
    const canvas = document.getElementById(CanvasIdName);   //get the canvas
    const ctx = canvas.getContext("2d");                    //set canvas to ctx and define it as 2d
    ctx.strokeStyle = "rgb(255,0,0)";                       //set color of line to chosen value
    
    let maxHeight = height/Math.max(...data);               //set height stepvalue
    let maxWidth = width/data.length;                       //set width stepvalue
    
    let x = 0;                                              //set startvalue to 0
    let ydata = 0;                                          //set startvalue to 0
    
    console.log(data[3]);   //debug line
    
    if(drawGuidingLines == false) {                         //if you don't want to draw guidinglines draw the graph instead
        for(dataIndex in data) {
            ydata = height-(maxHeight * (data[dataIndex])); //get height position
            ctx.lineTo(x, ydata + maxHeight * 2.5);         //draw draw the line
            x += maxWidth;
            console.log(data[dataIndex]);   //debug line
        }
        ctx.stroke();
    }
    
 }
    DrawGraph("canvasTest","proxy.php?q=lastday","TempertureS01",350,450,5,0.5,"rgb(255,0,0)",false);
</script>

Here you have a snippet of the proxy reply

[{"LocationId":"1","TempertureS01":"11.870","TempertureS02":"11.700","PressureS01":"102204.234","HumidityS02":"60.500","HeatIndexS02":"10.505","LightS00":"0.002","TimeStamp":"2021-12-21 20:29:44"},{"LocationId":"1","TempertureS01":"12.390","TempertureS02":"12.300","PressureS01":"102192.164","HumidityS02":"57.400","HeatIndexS02":"11.084","LightS00":"0.002","TimeStamp":"2021-12-21 20:01:13"},{"LocationId":"1","TempertureS01":"13.000","TempertureS02":"13.100","PressureS01":"102185.297","HumidityS02":"55.700","HeatIndexS02":"11.920","LightS00":"0.002","TimeStamp":"2021-12-21 19:32:45"},

Here is the Imgur link of the output for the devtools console

enter image description here

My biggest problem with this is the array, since the array doesn’t “contain” any items, I’ve never seen this problem before, I have looked for hours through the web, but maybe just can’t find the solution I’m looking for.

How can I get this to work, I’m trying to import a git command

git : The term ‘git’ is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again.
At line:1 char:1

How to include Tailwind CSS styles from React component library into the app CSS bundle?

G’day,

I am building a React component library with TailwindCSS and ViteJS. The library outputs each component as a separate JS file, for example:

// @components-library/src/ComponentA.jsx

export default function ComponentA() {
  return <div className="flex justify-center">Component A</div>;
}
// Bundle Output: @components-library/dist/ComponentA.js

import { j as jsx } from "./jsx-runtime.js";
import "react";
function ComponentA() {
  return /* @__PURE__ */ jsx("div", {
    className: "flex justify-center",
    children: "Component A",
  });
}
export { ComponentA as default };

The app that is consuming this components library is also using Tailwind. However, the styles are not applied to the imported component. App-specific styles are working fine.

/* app/src/index.css */

@tailwind base;
@tailwind components;
@tailwind utilities;
// app/src/App.jsx

import CompoenntA from "@component-library/ComponentA";
export default function App() {
  return (
    <div className="p-10">
      <ComponentA />
    </div>
  );
}

Awaiting expert advice.

Thank you!