product price for customer group - php

I hope someone can help me with this, I am trying to extract the product prices from magento based on customer group.
I am not using tier pricing, I simply have a product with a standard price and I have specified different prices for each customer group. For some reason I have been unable to extract this information.
I can see that the price mappings seems to be held in the table 'catalog_product_index_group_price' so I guess I could write direct SQL to extract these but I would much rather use the PHP Mage model to do this, or the V2 SOAP API.
I have tried many methods, currently im using something like below, but without success the price variable is always empty.
$rules = Mage::getResourceModel('catalogrule/rule');
$price = $rules->getRulePrice($now, $websiteId, $customer_group_id, $productID);

Please try the following
$product = Mage::getModel('catalog/product')->load($productId);
$groupPrices = $product->getData('group_price')
$groupPrices should now be an array with the data you are looking for.

the code didnt format well in the comment so here it is again!
<?php
include_once '../App/Mage.php';
Mage::app();
$productID = $_GET["id"];
$pd = Mage::getModel('catalog/product')->load($productID);
$groupPrices = $pd->getData('group_price');
echo json_encode($groupPrices);
?>

Related

Retrieve name of vendor - WooCommerce & The official product vendors plugin

I'm using the Product Vendors plugin for WooCommerce (https://woocommerce.com/products/product-vendors/).
I'm also creating a custom loop for a page builder module, which pulls products by ID.
Using the above, I'm able to pull the WC_Product data using:
$thisProduct = new WC_product($id);
From there, I can get the price/product image etc using
$image = $thisProduct->get_image();
$price = $thisProduct->get_price();
Does anyone know how I would be able to pull the Vendors name? I've one a var_dump on the full $thisProduct, and it doesn't contain the vendor name anywhere within.
Any help would be much appreciated!
Thanks guys.
If that product is having a vendor mostly it will be saved under 'post_author'; You can retrieve Vendor by that author id.
$author = get_user_by( 'id', $product->post->post_author );
This variable $author will have all the info like name.
I figure this out, In order to retrieve the vendor information, we can use the following ($id being the product ID)
$sold_by = WC_Product_Vendors_Utils::get_sold_by_link( $id );
$sold_by will then contain an array of the vendor info, such as the store name and the link to the vendor store, which we can retrieve such as:
$vendor_link = esc_url( $sold_by['link'] );
$vendor_name = $sold_by['name'];
Thanks guys, hopefully this can be of assistance with someone in the future.

Magento - How to get the Order ID and 2-letter state abbreviation of an order

So I have to send variables to an affiliate website and they need the order id, price, 2-letter state abbriviation, and the country abbreviation. I have already got the price and country abbr. but I still need the order id and the 2-letter state abbreviation. The code I have right now is as follows:
$order = Mage::getSingleton('checkout/session')->getLastRealOrderId();//doesnt work
$amount = Mage::getModel('checkout/cart')->getQuote()->getSubtotal();//works
$stateId = Mage::getSingleton('checkout/session')->getQuote()->getShippingAddress()->getData('region');//Gives full name of State
$countryId = Mage::getSingleton('checkout/session')->getQuote()->getShippingAddress()->getData('country_id');//works
echo " display: $order $amount $stateId $countryId";//prints out the variables
I have been looking on all the code on here for the order id but nothing has returned anything. So I'm wondering what I am doing wrong with that/why it is not printing out anything.
The second thing is that I am wondering if there is an easy way to get the 2-leter state abbreviation? I have also tried 'region_id" instead of 'region' but that just gives me the number code (not the letter code).
Answers to either of these problems would be greatly appreciated.
Once you have the order loaded you can call 'region_code' or getRegionCode(). I'm using magento 1.9. Not sure if it is available in previous versions.
The best way is to send this information through the success.phtml file as only in that file you will get that info and avoid sending order ids for uncompleted orders (failed paypal transactions etc.)
1) depending on your checkout method, you may or may not have the state code in your data.
So if you get the name of states by
$stateId = Mage::getSingleton('checkout/session')->getQuote()->getShippingAddress()->getData('region');
then add this code afterwards:
$states = Mage::getModel('directory/country')->load('US')->getRegions();//get list of states
foreach($states as $state){
if($state[default_name] == $stateId){ //check if the names match
echo $state[code]; //get code
}
}
2) On success page
$orderId = $this->getOrderId();
should work.

Bigcommerce API Update Inventory Levels (both normal inventory tracking and tracking by options)

Update 11/11/13:
After doing some testing I'm running into some more problems using the bigcommerce php api. Searching a sku's property works fine for SKU's that are attached to options, but updating them I seem to be running into some problems...
Here is a sample snippet:
$filter = array('sku' => '230000120078');
$skus = Bigcommerce::getSkus($filter);
foreach($skus as $sku){
$options = array('inventory_level' => 3);
Bigcommerce::updateSku($sku->id, $options);
}
I must be missing something but I can't find to much documentation online. BigCommerce Documentation for updating sku makes it seem as if I have this right, but it doesn't seem to be working. Any suggestions?
Original Post:
This is more of a general question before I look to deep into solutions...
I read this post about updating inventory levels by SKUs and the answer suggests you can only update levels by product ids. Does this mean if you have a store with some products that track inventory by option sets (with SKUs attached to each option) you cannot update the inventory levels for each of these options?
Currently I just wrote a script that connects to our RFID database and grabs the current inventory levels and throws them into a csv file which I then upload every morning, but I'm trying to fully automate the process so I don't have to worry about selling out of items in between the 24 hours of new inventory.
Does anyone have any experience with this using the Bigcommerce api?
So...
This requires a hybrid solution; if you look at the quick start guide (not very helpful) you'll find this
Currently, there are two ways to search for SKUs - GET
/products?sku="something" or GET /products/skus?sku="something". The
first call only returns product level SKU and not option level SKUs.
What they neglect to mention is that to get the product level SKU, the only method that works is the top one.
My solution was to include another function in the library that adjusted the path to just /products?skup=xxxxx
public static function getSkuTop($filter = false)
{
$filter = Filter::create($filter);
return self::getCollection('/products' . $filter->toQuery(), 'Sku');
}
and in my call I have a few simple bits of logic
$filter = array('sku' => '10026');
$skus = Bigcommerce::getSkus($filter);
if(is_array($skus)){
foreach($skus as $sku){
$sku->inventory_level = 27;
$sku->update();
}
} else {
$skus = Bigcommerce::getSkuTop($filter);
if(is_array($skus)){
foreach($skus as $sku){
$options = array('inventory_level' => 28);
Bigcommerce::updateProduct($sku->id, $options);
}
}
}
May not be so great, but it's the only way I can get it to work!
Yes, I have been working on that same issue and the solution I came up with was to check if the SKU on the product level is blank. If so, the the inventory_level is managed by in the SKU resources underneath the product.
As far as actually updating the SKU I figured out the easiest way and that is the following. Instead of trying to run the updateSku function I do this...
$filter = array('sku' => '230000120078');
$skus = Bigcommerce::getSkus($filter);
foreach($skus as $sku){
$sku->inventory_level = 4;
$sku->update();
}
This does update the inventory for the associated sku.
As far as Paul's response, he is absolutely correct, and it lead me to this answer.

How to get product url by SKU? [duplicate]

The question is simple.
If I know the sku of my product and nothing else, how can I retrieve the url to that item. This is commonly useful for third party integration where the unique id at the remote service wont match a product id. Or maybe you want to make a search box to search by sku only.
You can just do this:
$sku = 'ecco'; // SKU you want to load. 'ecco' is a sku in the Magento demo data
$url = Mage::getModel('catalog/product')->loadByAttribute('sku',$sku)->getProductUrl();
echo $url;
Also.... You could add this to a file named 'geturlbysku.php' in magento root dir. This code enables a small amount of json representing the product to be pulled easily, enabling small javascript integration. Product URL is part of the dataset
<?php
require_once '/app/Mage.php';
umask(0);
Mage::app('admin');
$actual_link = "http://$_SERVER[HTTP_HOST]";
$sku = $_GET['sku'];
$product = Mage::getModel('catalog/product')->loadByAttribute('sku',$sku);
$fullUrl = "/catalog/product/view/id/" . $product->getId();
header("Content-Type: application/json");
echo $_GET['callback'] . '('.json_encode($product->getData()).')';
?>
Use like this...
www.yoursite.com/geturlbysku.php?sku=theskuoftheproduct
Part of the data returned includes "url_path":"your-product-name.html" which corresponds to the real url.
You can use the load method. This is quicker and easier than all other solutions.
Mage::getModel('catalog/product')->load('sku', 'sku');
For more information on loading products Click Here
$product = Mage::helper('catalog/product')->getProduct($this->getData('sku'), Mage::app()->getStore()->getId(), 'sku');
$url = Mage::getUrl($product->getUrlPath());
You can access the full url of the product based on its sku by adding this to a method and then setting the sku attribute on the class to the sku that you wish to search by.

Get Order Increment Id in Magento

I'm trying to get the Order Increment Id in Magento, on the success.phtml page so that I can use this for affiliate tracking.
I'm using the following code, but it is giving an error on the second line;
$order = Mage::getSingleton('sales/order')->getLastOrderId();
$lastOrderId = $order->getIncrementId();
The error reads:
Fatal error: Call to a member function getIncrementId() on a non-object on line 34: $LastOrderId = $order->getIncrementId();
I was wondering if anyone has any ideas on how to get the Order Increment Id? This is the reference number seen in the admin, usually something like: #1000123
If you're specifically doing this on the checkout success page - in success.phtml - then the code to get the order increment ID is already available in the template, since it is displayed to the customer.
You just need the following:
$orderId = $this->getOrderId();
Note that this won't work on other pages so, for those, you'd need to use:
$orderId = Mage::getSingleton('checkout/session')->getLastRealOrderId();
$order in your code is the last order ID...as the function name implies. If this isn't the value you want, then use it to load an order, and then use the getter on that:
$order = Mage::getModel('sales/order');
$order->load(Mage::getSingleton('sales/order')->getLastOrderId());
$lastOrderId = $order->getIncrementId();
This will work perfectly, I m running this one in my module now.
$last_order_increment_id = Mage::getModel("sales/order")->getCollection()->getLastItem()->getIncrementId();
Hope it helps thanks. :)
Your call to
Mage::getSingleton('sales/order')
isn't returning an object. Try
var_dump(Mage::getSingleton('sales/order'));
to confirm.
I haven't dived into the checkout code recently, but I'm pretty sure that's because sales/order will get you the order in progress. Once the order's been placed it's no longer in progress.
The "right" way to do this would be to create an observer for one of the events that Magento fires during checkout. The
checkout_onepage_controller_success_action
event should be sufficient, assuming you haven't done too much customization of the checkout process.
There's a terse explaination of how to do this on the Wiki (for a different event)
Once you get your event setup and responding, do a
$event = $observer->getEvent();
var_dump($event->getData());
to see what kind of information you have available. Chances are there's an order object in there which will let you get the ID you're after.
I had to use...
$_order = Mage::getModel('sales/order')->loadByIncrementId($this->getOrderId());
While in the success.phtml template. Instead of load() I used loadByIncrementId - then my order object was no longer empty.
If you are in admin mode - try this:
$orderModel = Mage::getModel('sales/order');
$orders = $orderModel->getCollection()->setOrder('increment_id', 'DESC')->setPageSize(1)->setCurPage(1);
$orderId = $orders->getFirstItem()->getIncrementId();
getRealOrderId() appears to return the order number as presented in data grids. getId() will return the internal id of row in the database, which you probably don't want.
You can get the increment id using this code snippet:
$orderId = 12;
$order = Mage::getModel('sales/order')->load($orderId);
$Incrementid = $order->getIncrementId();
Now you can do an echo to the $Incrementid variable and see the increment id.
I hope this helps.
$lastOrderIncrementId = Mage::getModel("sales/order")->getCollection()->getLastItem()->getIncrementId();
$shipmentID = $shipment->increment_id;
$order = $shipment->getOrder();
$orderID = $order->increment_id;

Categories