How to get the order id from $observer in magento - magento-1.7

i am developing a magneto component. I need to get the order id from the observer. I am using magneto 1.7.0.2. I have tried several methods already which found from Google. But non of them helped me. I can get order number description, name, price, etc..
the code i was finally testing was this,
$order = $observer -> getEvent()-> getOrder();
$id = $order -> getName();
Thank you very much....
this is the config of the observer : it is placed under globel
<events>
<sales_order_invoice_save_after>
<observers>
<ModuleName>
<class>CompanyName_ModuleName_Model_Observer</class>
<method>afterSalesOrderSaveCommitAfter</method>
</ModuleName>
</observers>
</sales_order_invoice_save_after>
</events>

Try this
$invoice = $observer->getEvent()->getInvoice();
$order = $invoice->getOrder();
$id = $order -> getId();
This would work. Worked for me. Actually you were passing invoice to event and checking for order. :)

Try
order->getData('increment_id')
or
$order->getData('entity_id')

Payex payment gateway is clearing the session after it does the payment. It also captures same event that i have used, this is the code which worked for me. Actually Sandeep is right.
$session->setPayexQuoteId($session->getQuoteId());
$session->getQuote()->setIsActive(false)->save();
$session->clear();
thank you!!!

Related

Magento 2 with Full Page Cache: How to get product ID from a product page?

I am trying to find a solution to what seems to be a FPC-linked issue.
In my code I am using the following method in order to get the current product ID from a Product page.
$this->catalogSession->getData('last_viewed_product_id')
This worked just fine until I tried it on a website with Full Page Cache: in this case, it returns an empty value (maybe because the session data cannot be accessed from cache).
Does anyone know an alternative method to get the product ID from the current context?
I have tried this alternative synthax:
$_SESSION['catalog']['last_viewed_product_id'];
While not the best solution and definitely not best practice, you can use objectmanager:
$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
$product = $objectManager->get('Magento\Framework\Registry')->registry('current_product');
$id = $product->getId();
This will get you the id but, as stated above, it's not suggested and you should create a block and inject the registry there and call it in your code.
You can see this post https://meetanshi.com/blog/get-current-product-id-in-magento-2/

SilverStripe 3.1 - Wrong $BaseDir after porting to XAMPP

after porting my fully working SS3.1 Page from my Webserver http://mydomain.de to my locally installed XAMPP http://intranet/silverstripe I've got the problem that the Base Directory is now wrong in SS. It's the old one from the webserver / but it need to be /silverstripe
I already changed it in the .htaccess so that mod_rewrite works but $BaseDir returns / and if I try to use the SS Sitesearch than I get redirected to home/SearchForm?Search= instead of silverstripe/home/SearchForm?Search= after submitting the form.
Can someone please help me to fix this problem.
Thank you in advance
EDIT:
I just call $SiteSearch in my Template.
But the function is modified in my Page.php to search also through a dataobject.
public function results($data, $form){
$results = $form->getResults();
$query = htmlspecialchars($data['Search'], ENT_QUOTES,'UTF-8');
$objects = ListingObject::get()->where("MATCH (Title, Link, Company, Category) AGAINST ('$query' IN BOOLEAN MODE)");
$results->merge($objects);
$data['Results'] = $results;
$data['Title'] = _t('SearchForm.SearchResults', 'Search Results');
$data['Query'] = $query;
return $this->customise($data)->renderWith(array('Page_results','Page'));
}
without this code it also doesn't work
SOLUTION:
I'm sry. I found the Problem. I didn't call $SiteSearch, because when I created the Page, I had to edit the form, so I hardcoded it... because of that, the submitted url is wrong now. I'm so sorry!
$BaseDir should be $BaseHref in your template.
You might have to set an alternate base url in the SS config. Add this to your config.yml:
Director:
alternate_base_url: '/silverstripe'

CakeEmail- Is there a way to send an array instead of var

I am usinf the cakeEmail fonction.
I am used to do like this (see viewVar)
$mail->from(authComponent::user('email'))
->to($this->Session->read('Site.email'))
->subject($this->Session->read('Site.name').' : New order No. '.$this->Basket->id)
->emailFormat('html')
->template('orderconfirmation')
->viewVars(array('title'=>'vlaue'))
->send();
I nedd to send a lot of data as the data of several boght product. It can have one product but it can have 10 product.
Then, I would like to send an array $detailOfProducts, in that way, in my mail template, I am going to use a loop to display the content.
I tried to change like this but without success
$mail->from(authComponent::user('email'))
->to($this->Session->read('Site.email'))
->subject($this->Session->read('Site.name').' : New order No. '.$this->Basket->id)
->emailFormat('html')
->template('orderconfirmation')
->viewVars($detailOfProducts)
->send();
Do you know a solution?
Thank a lot
Send them like u send the vars to your view ..
$mail->from(authComponent::user('email'))
->to($this->Session->read('Site.email'))
->subject($this->Session->read('Site.name').' : New order No. '.$this->Basket->id)
->emailFormat('html')
->template('orderconfirmation')
->viewVars(array('details'=>$detailOfProducts))
->send();
Your view code will be ..
<?php echo $detail[0]['Model']['field']; ?>
Ok, I got the answer!!!
Sorry, I should have tried before.
echo count($basketItems);
echo $basketItems[0]['name'];
then with the result of count(), I can make a loop to display all. I am going to try this now.
Many thank for you help!!!!
Here is the answer: (It's into a loop)
<?php echo $basketItems[$i]['name']; ?>
Thank for your help!!!!

How to get all courses on moodle?

I need to show all moodle courses in menu listing.
Can anyone suggest me that how can I get all courses using php code or moodle inbuilt functions.
Thanks
Assuming you are writing code to be run within Moodle, you can use the get_courses() function defined within lib/datalib.php. For example:
<?php
require_once(PATH_TO_MOODLE_ROOT . '/config.php');
$courses = get_courses();
print_r($courses);
will print out a data-dump of the returned array, showing details of all the courses in your Moodle site. This example is obviously not appropriate to use on a production site!
If you check the function definition in lib/datalib.php you will see the options available for restricting the result set to particular fields or controlling the sort order.
Include this file
require_once($CFG->dirroot . '/lib/coursecatlib.php');
Use this function to get all courses in menu listing.
$allcourses = coursecat::get(0)->get_courses(array('recursive' => true));
var_dump($allcourses);exit;
If you want to show only enrolled course to student you can use following method.
require_once($CFG->dirroot.'/blocks/course_overview/locallib.php');
global $USER,$DB;
$courses = enrol_get_users_courses($USER->id, true);
OR
If you want list all courses..
global $DB;
$query = "SELECT id, fullname, shortname from {course}";
$courselist = $DB->get_records_sql($query);
foreach ($courselist as $course) {
echo $course->fullname;
}
Thanks

Render comments form in any page

I want to know how to render a comments form of a specific node in any page (ex. user profile). I've trying with drupal_get_form but it shows an error.
drupal_get_form('mytype_node_form', array('nid' => $nid));
Solutions & clues are welcome :)
First of all, you should use the proper ID of the comment form: 'comment_form' instead of 'mytype_node_form'.
The code
drupal_get_form('comment_form', array('nid' => $nid));
used to work for me in Drupal 6. In Drupal 7, function comment_form() is expecting an object parameter instead of array. This code should work for you:
$comment = new stdClass;
$comment->nid = $nid;
$form = drupal_get_form('comment_form', $comment);