Research
Security News
Malicious npm Packages Inject SSH Backdoors via Typosquatted Libraries
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
gatsby-plugin-snipcart-advanced
Advanced tools
This plugin includes a Context for quantity in cart and detects if user is logged in or not
npm install gatsby-plugin-snipcart-advanced
Set "GATSBY_SNIPCART_API_KEY" variable in environment
The plugin use :
process.env.GATSBY_SNIPCART_API_KEY
In your gatsby-config.js
file, add:
module.exports = {
plugins: [
{
resolve: `gatsby-plugin-snipcart-advanced`,
options: {
version: '3.0.12',
defaultLang: 'fr',
currency: 'eur',
openCartOnAdd: false,
locales: {
fr: {
actions: {
checkout: 'Valider le panier',
},
}
},
innerHTML: `
<billing section="bottom">
...
</billing>`,
},
},
],
}
Read the snipcart document https://docs.snipcart.com/v3
Default values :
Use the context of the Snipcart plugin. You have 2 values in the context :
When you use the changeLanguage function, it use the locales string define in config of plugin.
import {SnipCartContext} from 'gatsby-plugin-snipcart-advanced/context';
const {state, changeLanguage} = useContext(SnipCartContext);
changeLanguage('en');
import {SnipCartContext} from 'gatsby-plugin-snipcart-advanced/context';
const MyComponent = () => {
const {state} = useContext(SnipCartContext);
const {userStatus, cartQuantity} = state;
return (
<div>
{userStatus === 'SignedOut' ? (
<button className="snipcart-customer-signin">
<span>Se connecter</span>
</button>
) : (
<button className="snipcart-customer-signin">
<span>Mon compte</span>
</button>
)}
<button className="snipcart-checkout">
<span>{cartQuantity}</span>
</button>
</div>
);
}
The values come from where you want : markdown files, api...
Example of button for your product component:
<button
className="snipcart-add-item"
data-item-id={id}
data-item-price={price}
data-item-url={slug}
data-item-description={product.excerpt}
data-item-image={image && image.publicURL}
data-item-name={title}
data-item-quantity="1"
data-item-taxes={tva}
disabled={_stock === 0 ? true : false}
>
Add to cart
</button>
import styles from './styles.module.css';
const AddCartModal = () => {
const [open, toggleOpen] = useState(false);
const [item, setItem] = useState({});
// hidden button for open the cart
const bt_cart = useRef();
// mask under modal
const mask = useRef();
useEffect(() => {
const {Snipcart} = window;
if (!Snipcart) return;
// open modal on snipcart event add item on cart
Snipcart.events.on('item.adding', _item => {
setItem(_item);
toggleOpen(true);
});
}, []);
return (
<>
<div
ref={mask}
className={`${open === true ? styles.show : ''} ${styles.mask}`}
>
<div
className={styles.add__cart}
role="alertdialog"
>
<button className={styles.close} onClick={() => toggleOpen(false)}>
<span>Close</span>
</button>
<div className={styles.confirm}>
{item.name && (
<span>
<strong>
{item.quantity} {item.name}
</strong>{' '}{'added to your cart'}
</span>
)}
</div>
<div className={styles.actions}>
<button onClick={() => toggleOpen(false)}>
Continuer les achats
</button>
<button
className={styles.got_cart}
onClick={() => {
toggleOpen(false);
bt_cart.current.click();
}}
>
Voir le panier
</button>
</div>
</div>
</div>
<button
ref={bt_cart}
style={{height: 0, opacity: 0}}
className="snipcart-checkout"
></button>
</>
);
};
export default AddCartModal;
FAQs
Gatsby JS Plugin for Snipcart V3
The npm package gatsby-plugin-snipcart-advanced receives a total of 14 weekly downloads. As such, gatsby-plugin-snipcart-advanced popularity was classified as not popular.
We found that gatsby-plugin-snipcart-advanced demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
Security News
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
Security News
MITRE's 2024 CWE Top 25 highlights critical software vulnerabilities like XSS, SQL Injection, and CSRF, reflecting shifts due to a refined ranking methodology.
Security News
In this segment of the Risky Business podcast, Feross Aboukhadijeh and Patrick Gray discuss the challenges of tracking malware discovered in open source softare.