How to get Invoice data in magento? - magento

i am trying here ,
see i am getting order data but, i am not getting any $order->hasInvoice()
$orderID = 100000062;
$order = Mage::getModel('sales/order')->load($orderID);
if ($order->hasInvoices()) {
$invIncrementIDs = array();
foreach ($order->getInvoiceCollection() as $inv) {
$invIncrementIDs[] = $inv->getIncrementId();
} Mage::log($invIncrementIDs);
}

Could you please try the following code:
$orders_invoice = Mage::getModel("sales/order_invoice")->getCollection();
foreach($orders_invoice as $val) {
print_r($val->getData());
}

Related

Access the cart session - Laravel 5.8

Hi i am using sopping cart in laravel 5.8. I want to access the array to be able to store the order in the database. I was able to access the data in the session cart. But to the part of options -> marca y medida. Also I do not know how to bring the total cart.
My controller is as follows
public function transferencia(Request $request)
{
$cart = Session::get('cart');
foreach ($cart as $key => $order) {
$data = json_decode($order, true);
foreach($data as $item){
$opt = new Order;
$opt->id_cliente = $request->input('idusuario');
$opt->fecha = date('j/n/Y');
$opt->cliente = $request->input('persona');
$opt->dni = $request->input('dni');
$opt->producto = $item['name'];
$opt->medida = 'medida'; //how to access this data
$opt->marca = $item['marca']; //how to access this data
$opt->precio = $item['price'];
$opt->cantidad = $item['qty'];
$opt->total = 'total';
$opt->factura = 'factura';
$opt->idpedido = 'idpedido';
$opt->save();
}
}
//dd($item);
//print_r($cont);
}

How to get Shipping data in magento

I am trying to get shipping data but getting blank
$orderID = 100000062;
$order = Mage::getModel('sales/order')->load($orderID);
foreach ($order->getShipmentsCollection() as $shipment) {
Mage::log($shipment->getData());
}
You can try this way :
$shipmentCollection = Mage::getResourceModel('sales/order_shipment_collection')
->setOrderFilter($order)
->load();

How to get Product listing filters through custom module of magento?

I want to create product filters in listing pages of category using our own custom apis i have tried many things like
$layer = Mage::getModel("catalog/layer");
$category = Mage::getModel("catalog/category")->load($categoryid);
$layer->setCurrentCategory($category);
$attributes = $layer->getFilterableAttributes();
But this only loads the Filterable atrribute code for the category But we want the Filters values and count for the product collection available in that category.
Below code will load all the available options of that attribute but I want it for product collection specific
foreach($attributes as $attribute){
$options = $attribute->getSource()->getAllOptions(false);
}
Like we have Mobiles category having 1000s of mobiles and having filterable attribute Brand so i need
Brand
Brand A (100 products)
Brand B (500 products)
Brand C (400 products)
How can this be achived if i don't want to load whole product collection as loading 1000s of product will take too much time to response.
This code works for me :
public function ws_getfiter($store_id,$categoryid){
Mage::app()->setCurrentStore($store_id);
$layer = Mage::getModel("catalog/layer");
$category = Mage::getModel("catalog/category")->load($categoryid);
$layer->setCurrentCategory($category);
$attributes = $layer->getFilterableAttributes();
$filter = array();
$count = 0;
foreach ($attributes as $attribute)
{
if ($attribute->getAttributeCode() == 'price') {
$filterBlockName = 'catalog/layer_filter_price';
} elseif ($attribute->getBackendType() == 'decimal') {
$filterBlockName = 'catalog/layer_filter_decimal';
} else {
$filterBlockName = 'catalog/layer_filter_attribute';
}
$filter[$count]["code"] = $attribute->attribute_code;
$filter[$count]["type"] = $attribute->frontend_input;
$filter[$count]["label"] = $attribute->frontend_label;
$result = Mage::app()->getLayout()->createBlock($filterBlockName)->setLayer($layer)->setAttributeModel($attribute)->init();
$innercount = 0;
$filter_data = array();
foreach($result->getItems() as $option) {
$filter_data[$innercount]["count"] = $option->getCount();
$filter_data[$innercount]["label"] = $option->getLabel();
$filter_data[$innercount]["id"] = $option->getValue();
$innercount++;
}
$filter[$count]["values"] = $filter_data;
$count++;
}
return $filter;
}
But using this we are only getting single level of filter but i want it for multiple level.

How to get invoice id from order increment id

I have order increment id like 100000096 and i want to get its invoice id, please help me to achieve this in magento, i have tried with
$incrementId = '100000096';
$order = Mage::getModel('sales/order')->load($incrementId);
$invIncrementIDs = array();
foreach ($order->getInvoiceCollection() as $inv) {
$invIncrementIDs[] = $inv->getIncrementId();
}
But it returns an empty array.
You are using order increment id in load() function, you have to use loadByIncrementId().
Try to use this -
$orderid = '100000096'; // order increment id
$order = Mage::getModel('sales/order')->loadByIncrementId($orderid);
if ($order->hasInvoices()) {
$invIncrementIDs = array();
foreach ($order->getInvoiceCollection() as $inv) {
$invIncrementIDs[] = $inv->getIncrementId();
}
}
echo "<pre>";
print_r($invIncrementIDs);
echo "</pre>";
Try this :
$orderIncrementId = '100000004'; // your order increment id
$order = Mage::getModel('sales/order')->loadByIncrementId($orderIncrementId);
if ($order->hasInvoices()) {
$invIncrementId = array();
foreach ($order->getInvoiceCollection() as $invoice) {
$invoiceIncId[] = $invoice->getIncrementId();
}
}
echo "<pre>";print_r($invoiceIncId);echo '<br>';
In order to get Invoice id from Invoice incrementId
$incrementId = $invoiceIncId[0];
$invoive = Mage::getModel('sales/order_invoice')->loadByIncrementId($incrementId);
$invoiceId = $invoice->getId();
echo "<pre>";print_r($invoiceId);exit;
try this you will not regret
$order_id = "type_here_your_orderid";
$invoices = Mage::getResourceModel('sales/order_invoice_collection')
->setOrderFilter($order_id)
->load();
$invoice_id = $invoices->getData()[0]["increment_id"];
echo $invoice_id;
thats all.

remove certain state/province from magento checkout

I want to remove certain state/Province from magento 1.12.0.2 checkout (onestepcheckout) page like "American Samoa"
I tried changing the Data.php file in "/app/code/local/Mage/Directory/"
public function getRegionJson()
{
$exclude_regions = array ('AS','FM');
Varien_Profiler::start('TEST: '.__METHOD__);
if (!$this->_regionJson)
{
$cacheKey = 'DIRECTORY_REGIONS_JSON_STORE'.Mage::app()->getStore()->getId();
if (Mage::app()->useCache('config')) {
$json = Mage::app()->loadCache($cacheKey);
}
if (empty($json))
{
$countryIds = array();
foreach ($this->getCountryCollection() as $country)
{
$countryIds[] = $country->getCountryId();
}
$collection = Mage::getModel('directory/region')->getResourceCollection()
->addCountryFilter($countryIds)
->load();
$regions = array();
foreach ($collection as $region) {
$rg = $region->getCode();
//if ($rg!='AL'){
if(!in_array($rg, $exclude_regions)) {
if (!$region->getRegionId()) {
continue;
}
$regions[$region->getCountryId()][$region->getRegionId()] = array(
'code' => $region->getCode(),
//'name' => $region->getName()
'name' => $this->__($region->getName())
);
}
}
$json = Mage::helper('core')->jsonEncode($regions);
if (Mage::app()->useCache('config')) {
Mage::app()->saveCache($json, $cacheKey, array('config'));
}
}
$this->_regionJson = $json;
}
Varien_Profiler::stop('TEST: '.__METHOD__);
return $this->_regionJson;
}
but did not have any luck, any help will be greatly appreciated on how to do this
Thank you in advance
The above code works fine, i just needed to flush the Magento cache storage.

Resources