How to adjust litespeed cache on woocommerce product update? - caching

Currently I'm using litespeed on woocommerce and everything's goes up to the time of updating one single products, I want to update my single products without purging other products cache, just shop-page and updated product purge is ok.
Please guide...

add_action('woocommerce_update_product', 'lscwp_suppress_purge_product_update', 10, 2);
function lscwp_suppress_purge_product_update($product_id, $product) {
ob_start( function($buffer) use ($product_id) {
#header("X-LiteSpeed-Purge: " . LSWCP_TAG_PREFIX . "_Po." . $product_id . "," . LSWCP_TAG_PREFIX . "_WC_S");
return $buffer;
} );
}
try this , it will override the purge header upon product edit (by woocommerce_update_product )and then call purge to product page itself by $product_id , and shop page

Related

woocomerce view order images not displayed when product deleted

Hi I have built a site with woocomerce and to display the images of the products on the view order page I have added the following code in the functions.php file. It works fine, however often time I need to delete some products and even though I dont delete the media (pictures), if I do that for a product that was ordered I get a fatal error on the view order page, as it is missing the product and the reference to the product and picture. Is there any way to display the images using some sort of reference only to the media and not the product to avoid this issue? any idea or suggestion.
// Display the product thumbnail in order view pages
add_filter( 'woocommerce_order_item_name', 'display_product_image_in_order_item', 20, 3 );
function display_product_image_in_order_item( $item_name, $item, $is_visible ) {
// Targeting view order pages only
if( is_wc_endpoint_url( 'view-order' ) ) {
$product = $item->get_product(); // Get the WC_Product object (from order
item)
$product_image = $product->get_image(array( 36, 36)); // Get the product thumbnail
(from product object)
$item_name = '' . $product_image . '' . $item_name;
}
return $item_name;
}

Is there a way to prime the cache for all pages in Prestashop?

I trying to make my prestashop site faster. My question is: is there a way to get all products pages cached AT ONCE. I already enabled the cache. But if you visit a page for the first time it take too much time to load. Then, the second visit is much faster.
I don't see any feature in the admin page to get this.
Thanks.
There is no but you can create a script which will load every product pages on your website.
Put this script at the root of your Prestashop installation /test.php. and call it from your browser www.mywebsite.com/test.php:
<?php
// The script will not timeout for 10 hours
set_time_limit(36000);
// Set the right path to config.inc.php
include_once (__DIR__ . '/config/config.inc.php');
// Set a default controller to remove unwanted warnings.
$context = Context::getContext();
$context->controller = new FrontController();
// Get all products
$products = Product::getProducts(1, 0, 1000000, 'id_product', 'DESC', false, true, $context);
foreach ($products as $product)
{
// Load the product page
$link = $context->link->getProductLink($product['id_product']);
file_get_contents($link);
// Print this to screen right away
print "loaded: " . $link . "<br />";
ob_flush();
flush();
// Stop for 0.2 seconds
usleep(200000);
}

Magento custom API for adding product wishlist

I am implementing the magento custom API for wishlist.
Can anybody know, how to add the wishlist.
I tried using the magento 'wishlist' module, but the product is not saving in to wishlist.
I am using the following function to save.
public function addNewItem($product, $customer_id, $buyRequest = null, $forciblySetQty = false)
{
}
I can able to get the wishlist using this post.
http://pastebin.com/G7ci0Mhu
This may help you
<?php $wishlist = Mage::getModel('wishlist/item')->load($_product->getId(),'product_id');
if($wishlist->getId())
//product is added
echo "Added! - Product is in the wishlist!";
else
//add product to wishlist
echo "<a href='".$this->helper('wishlist')->getAddUrl($_product) ."'>Add This?</a>";
;?>
Mage::getModel('wishlist/item')->load($id)->delete();
http://abhijitberadeveloper.blogspot.in/2012/07/product-add-wishlist.html
http://docs.magentocommerce.com/Mage_Wishlist/Mage_Wishlist_Helper_Data.html#methodgetWishlistItemCollection
http://docs.magentocommerce.com/Mage_Wishlist/Mage_Wishlist_Helper_Data.html#methodgetWishlistItemCollection

magento update attribute1 = attribute2

I have 800 products in my magento store and im trying to change all SKUs, but keep the old ones to another text field. I have found a script that changes all SKUs at once but the problem is that first, i have to insert the text of attribute field SKU, to a new attribute field "old_sku".
How can i update old_sku = sku?
Thanks for any help!
If you do have some PHP knowledge, you could use it to create a PHP script that runs once and replaces all the attribute values. For example, i would do that like so:
<?php
// Magento initialization code; taken from here: http://www.ecomdev.org/2010/06/01/application-bootstrap-in-magento.html
require 'app/Mage.php';
if (!Mage::isInstalled()) {
echo "Application is not installed yet, please complete install wizard first.";
exit;
}
$initializationCode = 'admin';
$initializationType = 'store';
$scope = 'frontend';
Mage::app($initializationCode, $initializationType);
Mage::getConfig()->init();
Mage::getConfig()->loadEventObservers($scope);
Mage::app()->addEventArea($scope);
// Update products
try
{
$products = Mage::getModel('catalog/product')->getCollection();
foreach ($products as $product) {
$product->setOldSku($product->getSku())->save();
}
} catch (Exception $e)
{
echo "Something bad happened: {$e->getMessage()}. Shutting down...";
exit;
}
?>
Just create, let's say, a update_skus.php file within the root directory of your Magento setup (near the index.php file), fill it with the code i've provided and navigate your browser to that file (e. g. http://magento.local/update_skus.php). You should get all the products having their old_sku attribute set exactly to their sku attribute' values.
If you want to keep it really simple then the solution is
a) Add an attribute "old_sku"
b) Export all products
b) Change the CSV - Copy & paste the "sku" column values in "old_sku" and,
d) Import all products
that's it
Hope this helps!!!

Magento Auto Add Items Based on Quantity

I'm designing a custom product page with a button that when clicked I need to have an alert come up with a "Yes" or "No" option.
If "Yes" is selected I then need the following to happen.
Add another product into the cart based on the products quantity i.e. between 1 & 2 items add product A between 3 & 4 Items product B, between 5 & 12 product C and so on.
Any idea of the best way to accomplish this?
It has to be a alert style popup (ajax popup preferred) cannot be a checkbox on the product page.
Thanks!
So I've come across a solution to my problem... I'm using a Simple Modal (That TheBlackBenzKid hinted me to) that I'm either going to call from a custom button or with the add to cart button. This in turn will redirect to a php page that will redirect to the cart. For the php page I'll just include the code to put a item into the cart from there anyone could figure out how to customize it to there own needs.
<?php
// Include Magento application (URL to Mage.php)
require_once ( "app/Mage.php" );
umask(0);
//specified quantity my own variable I'm using for quantities
$spqty = 9;
// Initialize Magento
Mage::app("default");
// You have two options here,
// "frontend" for frontend session or "adminhtml" for admin session
Mage::getSingleton("core/session", array("name" => "frontend"));
$session = Mage::getSingleton("customer/session");
// get the current Magento cart
$cart = Mage::getSingleton('checkout/cart');
if ($spqty <= 2) {
// insert item to cart where "98" is the product ID (NOT SKU!) Where "2" is the quantity
$cart->addProduct(98, array('qty' => 2));
} elseif ($spqty >= 4 ){
// you can add multiple products at the same time by adding this line multiple times
$cart->addProduct(96, array('qty' => 3));
}
// save the cart
$cart->save();
// very straightforward, set the cart as updated
Mage::getSingleton('checkout/session')->setCartWasUpdated(true);
// redirect to index.php
header("Location: index.php/checkout/cart");
I also found some of this information from this guys blog I'll link to the article
How to add a product from an external site into Magento
I'm happy to answer any questions on this...
This is not the best answer, but code to get you started:
You could make the cart function use:
<input type="button" onClick="javascript:nValidateForm();"/>
And your form code:
<form name="m2mform" id="m2mform" method="post" onSubmit="javascript:nValidateForm();">
And then just call an external JavaScript in your page XML headers and add it to cart so that JS file will always be checked and validate the popup.

Resources