So I am working on \app\code\core\Mage\Checkout\Helper\Data.php at the moment. And I am trying to call a variable but it doesn't seem It's working.
UPDATE 1
I have been able to pass the variable by method like this, but I need to declare the product ID manually, is there anything allows the method get the product id base on the product i added into cart?
$_productId = Mage::registry('current_product')->getId();
is not working in my case.
My test as below:
public function formatPrice($price)
{
$_productId = 463089; // need to call the current product by the enter the ID manually
$_product = Mage::getModel('catalog/product')->load($_productId);
$oldPrice = $_product->getFinalPrice(); //should be the original product price
return $this->getQuote()->getStore()->formatPrice($oldPrice);
}
The result after i refresh my page :
everything turns to 670
Many thanks
You're "working on \app\code\core\Mage\Checkout\Helper\Data.php", which is the first problem. Never edit the Magento core.
Assuming you move this to your own event observer to modify the data, you are loading the product ID with a static variable set to 463089, then doing nothing to calculate a new price, then displaying the products price.
From your code it makes perfect sense that the price would always remain the same since you are manually setting which product to pull the price from.
It could be a number of reasons why the quantity of the item is not changing the price. It might have something to do with other core edits you may have made.
Related
After I refresh my browser to retrieve data from localstorage and update that data, it's not updated. But when I add new items and update it, it is updating. What's seems to be the problem here?
//----- update existing item's subtotal in localstorage
changeSubtotalOfExisting(qty ) {
let updateQty = JSON.parse(localStorage.getItem('cart_items'));
updateQty['qtyTotal'] = qty;
localStorage.setItem("cart_items", JSON.stringify(updateQty));
console.log('updateQty: ', updateQty );
}
Here's a stackblitz sample:
https://stackblitz.com/edit/angular-ivy-i8kpub?file=src/app/app.component.ts
There were several problems with your implementation. Failing to save to local storage was only one of them. I ended up rewriting a lot of it, and actually simplifying considerably. I apologize if this was not your intention in your question. Here is the resulting project: https://stackblitz.com/edit/angular-cart-local-storage. You can compare the 2 projects.
I'm listing here some key issues:
Accessing local storage should be done only from the service, not from the component. The service is in charge of saving and retrieving data. The component is in charge of interacting with the user.
You saved to local storage the wrong objects (and maybe this is the answer to your original question). Local storage should store the cart (a list of items). Here for example you're trying to save to local storage as if it stores only one item at a time:
updateQty['qtyTotal'] = qty;
localStorage.setItem("cart_items", JSON.stringify(updateQty));
Your event handlers are called with the wrong arguments. You need to call them with the item as an argument, not the HTML element. Instead of changeSubtotal($event.target, addedItem.variationCost,i) I call changeSubtotal(item ,i)
You did not prevent the user from adding the same item to the cart multiple times.
The initial quantity of an item you add to the cart should be 1 and not 0, as you set the minimum of the quantity control to 1
I'm running into a little problem with woocommerce's cart.
Description of the issue:
Say I am logged in, I have 3 products in the cart. If I log out, I have 0 products in the cart. I add a product and log back in. I'm now still having that product I added while being logged out. That is fine, as I suppose when you navigate and log in just at the checkout, you don't want old cart items to pop up suddenly. Now, if I log out, I have 0 products, which is also fine, as suddenly you become nobody and you can assume a new user will take on. But, if, with an empty cart I log back in, I now have the 3 products from the beginning, instead of having the 1 I had during my previous visit.
What I'd like to achieve. By default, in the above story, woocommerce would show a cart with 1 item like expected. But in the theme I build, I load the whole cart via ajax. I have a little function that basically just does this :
function sp_get_cart() {
$cart = WC()->cart->get_cart();
wp_send_json($cart);
}
add_action('wp_ajax_get_cart', 'sp_get_cart');
add_action('wp_ajax_nopriv_get_cart', 'sp_get_cart');
I also have the whole signon/signout part working with ajax. I tried to find in the woocommerce code things I may have missed, but I couldn't find anything. Should I do something specific when processing the signon or signout ? I thought I could just rely on the default behavior of woocommerce's session, but something seems broken, and when I log in with items in the cart, it seems these new cart items don't get added to the session stored in the database and when the next signon happens, the previous version is being loaded. Any help would be much appreciated.
edit: here is the logout function
function sp_logout() {
WC()->session->destroy_session();
wp_logout();
ob_clean();
// $_SESSION = array();
http_response_code(200);
wp_send_json(array('status' => 'OK'));
die();
}
add_action('wp_ajax_logout', 'sp_logout');
add_action('wp_ajax_nopriv_logout', 'sp_logout');
Try clearing $_SESSION global variable, on your log out function
$_SESSION = array();
I have a wishlist page which shows all saved products. Products are saved in a cookie and that can be done through a click of a button when viewing a single product.
On that single product, there is an icon with two states, selected or unselected. The purpose is "Save for later". If the specific product is already in the cookie list then i add "selected" class, so the icon changes properly in order to let the user know that he already had "save for later" this product.
An example of cookie with 3 products : 185-589-382
That means we have three products with the ID's 185, 589, 382.
Every product has different ID for each language. That means a product in "EN"(english) has ID 100, but in the other language the ID may be 252.
Example :
Let's suppose i have only one product which has the ID 100 in "EN". That product, in the other language has the ID 200.
When visiting mysite.com/wishlist it shows the product in "EN" (defualt language)
When visiting mysite.com/el/wishlist it shows the product in "GR".
It works just fine even though they have different ID's. (probably because there is a connection between them through the plugin i am using)
My problem
When viewing a single product in "EN", which has the id 100, supposing that id is already in the cookie list - the icon has the selected state. When i press the language switcher, it switches to the other language showing the product but the icon is not in the selected state. I know this happens because in the cookie list i have saved the product with the id 100 (which is in "EN" only) and not 200 which is the other's language ID.
Is there any workaround?
Using WPML Plugin.
Didn't post any code because i don't have a problem with the coding but if that's going to help you then feel free to ask.
Currently searching a way to find how these posts are connected so maybe i change what i save into my cookie list. One way would be to save all the id's of each language but i would like to keep it clean - find the best way.
Found a solution using the below WPML function :
icl_object_id(get_the_ID(), 'post', false, ICL_LANGUAGE_CODE);
This function returns the post id of "ICL_LANGUAGE_CODE" - which means current language.
So, i stored in an array $mLanguages all the available languages. Then, used a for loop to store in $mIDArray all the ID's in every language of current product :
foreach($mLanguages as $language) {
$mIDArray[] = icl_object_id($mCurrentPostID, 'post', false, $language);
}
Below is the code block which was checking if post id was in the cookie list before :
if(isset($_COOKIE['mSavedList'])) {
$mListOfSavedItems = $_COOKIE['mSavedList'];
$mListOfSavedItems = explode('-', $mListOfSavedItems);
if(in_array(get_the_ID(), $mListOfSavedItems))
$isCurrentProductSaved = true;
}
$isCurrentProductSaved is the "selected" statement i was talking about. So i changed it to :
if(isset($_COOKIE['mSavedList'])) {
$mListOfSavedItems = $_COOKIE['mSavedList'];
$mListOfSavedItems = explode('-', $mListOfSavedItems);
foreach($mListOfSavedItems as $item){
if($mCurrentPostID == $item)
$isCurrentProductSaved = true;
else if(in_array($item, $mIDArray))
$isCurrentProductSaved = true;
}
}
In other words :
Before i was checking if current post id exists in my cookie list. Now i am checking if current post id ( or all translatables ID's of this post) exists in my cookie list.
Found a bug though :
I was saving current post's id into the cookie list no matter the language. To make it work, i always save the posts id of "EN" which is the default language.
I have customized the default promotion form in which if a user clicks on a particular promotion the form will show dynamic elements using jquery ( as we have not created the fields or lists/records for this requirement).
so based on the data we may need to create multiple records while submitting the form. I have created the saveRecord() function in js file which is already mapped with the form. In that am trying to create promotionRecord dynamically. But cant save the record I am getting "the items you requested in the record have been deleted since you retrieved the form" error. What could be the problem and is it possible to save multiple record in single form submit?
departments = Object.keys(samplePromotions);
$.each(departments, function(key,value){
console.log(samplePromotions[value]);
promotion = nlapiCreateRecord('customrecord_promotion');
console.log(promotion);
//required
promotion.setFieldValue('name','jAVASCRIPT pROMOTION cREATION_'+value);
promotion.setFieldValue('custrecord_px_promotion_id','js_prom_creation_'+value);
id = (Math.round(new Date().getTime()/1000));
console.log(id);
promotion.setFieldValue('id',id);
var id = nlapiSubmitRecord(promotion);
Not sure if this is the problem in your code, but to answer your question you can only submit one record with the API.
I would just create an array and loop through the length of it and call nlapiCreateRecord and the nlapiSubmitRecord for each one.
-- Edit
Not sure about this, but this looks weird to me to. You are setting the id using setFieldValue method, which I believe is the external Id. Then you are setting setting id again with the nlapiSubmitRecord call. This returns the internal Id. Maybe that is causing issues as well?
Must be this line
promotion.setFieldValue('id',id);
The id field on the record object contains the internal id of the record. This is generated by NetSuite when you create a record.
I need to get the order_id variable and price variable without tax and shipping to put into a script on affiliate pixel.
How can i get this variables to set in this script?
e.g. something like the following:
//apypxl.com/ok/7077.png?actionpay={{Cookie_actionpay}}&apid={{transactionId}}&apprice={{transactionTotal}}&width=1&height=1
Regarding Order id, Each time you select Payment method (Checkout) the order id is changed and inserted in to database as order_status_id=0(Missing Order)
If the customer confirms checkout then order_status_id is changed to Default Order Status
to see the session data (current order_id)
//system/library/session.php
print_r($this->session->data)
to see the cart info
//system/library/cart.php:319
print_r($this->cart->getSubTotal());