How to disable automatic invoice generation in magento? - php

I am only a beginner in Magento. I need your help to solve this issue.
My Magento store is automatically generating invoice mail after the payment. The payment is made through PayPal (standard). Also the order status is changed to 'complete' not 'pending'. So I am not able to generate invoice manually. I need to generate the invoice manually from the admin side ,only after viewing the product orders. The order status should be 'complete' only after the manual invoice generation. Can any one please help me to solve this issue.
Thanks in advance

It's pretty simple. Just go to System->Configuration->Sales Emails and under the tab "Invoice" set Enable to NO.
Cheers,

If you wanted to disable auto invoice invoice programatically then plese follow below steps
In your custom module create di.xml file and add preference
<preference for="Magento\Sales\Model\Order\Payment\Processor" type="Vendor\Module\Model\Express\Processor"/>
Create new file at Vendor\Module\Model\Express\ with Processor.php and add below code:
<?php
declare(strict_types = 1);
namespace Vendor\Module\Model\Express;
use Magento\Sales\Api\Data\OrderPaymentInterface;
class Processor extends \Magento\Sales\Model\Order\Payment\Processor
{
const PAYMENT_METHOD_PAYPAL_EXPRESS = "paypal_express";
/**
* Process capture operation
*
* #param OrderPaymentInterface $payment
* #param InvoiceInterface $invoice
* #return OrderPaymentInterface|Payment
* #throws \Magento\Framework\Exception\LocalizedException
*/
public function capture(OrderPaymentInterface $payment, $invoice)
{
if ($payment->getMethodInstance()
->getCode() != self::PAYMENT_METHOD_PAYPAL_EXPRESS)
{
return $this
->captureOperation
->capture($payment, $invoice);
}
}
/**
* Registers capture notification.
*
* #param OrderPaymentInterface $payment
* #param string|float $amount
* #param bool|int $skipFraudDetection
* #return OrderPaymentInterface
*/
public function registerCaptureNotification(OrderPaymentInterface $payment, $amount, $skipFraudDetection = false)
{
if ($payment->getMethodInstance()
->getCode() != self::PAYMENT_METHOD_PAYPAL_EXPRESS)
{
return $this
->registerCaptureNotification
->registerCaptureNotification($payment, $amount, $skipFraudDetection);
}
}
}
Note: It's for Magento 2X

Go to Store->Settings->Configuration->Sales->Sales Emails and under the tab "Invoice" set Enable to NO.
Happy coding :)

Use this:
http://www.magentocommerce.com/magento-connect/8870.html
I've used in few projects and it works nice.

Related

Woocommerce add_filter not working for woocommerce analytics order reports

The plugin I am trying to implement is to allow adding additional columns to the woocommerce analytics orders report csv file that gets exported. I've been following instructions from the answers to the question laid out here, however my success ends at the following code:
/**
* Add the phone number column to the CSV file
* #param $export_columns
* #return mixed
*/
add_filter('woocommerce_report_orders_export_columns', 'add_column_header' );
function add_column_header($export_columns){
$export_columns['customer_phone'] = 'Customer phone';
return $export_columns;
}
/**
* Add the phone number data to the CSV file
* #param $export_item
* #param $item
* #return mixed
*/
add_filter('woocommerce_report_orders_prepare_export_item', function ($export_item, $item) {
$export_item['customer_phone'] = $item['customer_phone'];
return $export_item;
}, 10, 2 );
The main issue is it seems the add_filter hook is not executing and I am not sure why. Any assistance would be greatly appreciated.

RESTful API: Data from multiple endpoints in one single view

I've started creating a RESTful API (well, I did my best, I'm trying to follow the patterns) and I have stumbled upon a scenario that I'm not really sure how to handle. I will explain the current structure:
My application has 4 controllers:
Customers
Payments
Log
Taking as example the Customers controller, I have defined the following actions:
GET /customers: returns a list of customers
POST /customers: creates a new customer
GET /customers/{id}: returns the customer with the provided id
PUT /customers/{id}: updates the customer with the provided id
DELETE /customers/{id}: destroys the customer
This is the full code of the Customer controller:
namespace App\Http\Controllers;
use App\Customer;
use Illuminate\Http\Request;
class CustomerController extends Controller
{
/**
* Display a listing of the resource.
*
* #return \Illuminate\Http\Response
*/
public function index()
{
return Customer::all();
}
/**
* Store a newly created resource in storage.
*
* #param \Illuminate\Http\Request $request
* #return \Illuminate\Http\Response
*/
public function store(Request $request)
{
$customer = Customer::create($request->all());
return response()->json($customer, 201);
}
/**
* Display the specified resource.
*
* #param \App\Customer $customer
* #return \Illuminate\Http\Response
*/
public function show(Customer $customer)
{
return $customer;
}
/**
* Update the specified resource in storage.
*
* #param \Illuminate\Http\Request $request
* #param \App\Customer $customer
* #return \Illuminate\Http\Response
*/
public function update(Request $request, Customer $customer)
{
$customer->update($request->all());
return response()->json($customer, 200);
}
/**
* Remove the specified resource from storage.
*
* #param \App\Customer $customer
* #return \Illuminate\Http\Response
*/
public function destroy(Customer $customer)
{
$customer->delete();
return response()->json(null, 204);
}
}
The code is very similar in the other controllers. It's also important to note that:
A Customer can have multiple Payments
A Customer can have multiple records in the Log
The problem starts here:
I need to display in the front-end a summary page with all customer data (name, email, registration date, etc) and a box showing the number of payments made and another box showing the number of entries in the Log.
Do I need to make 3 requests? (One to /customers/id, other to customers/id/payments and other to customers/id/logs)
If I return all the customer related data in the customers/id call, am I breaking the RESTful convention?
I am using apigility, but my answer still will be related to your question. According to the REST terminology (which could be find here https://apigility.org/documentation/intro/first-rest-service#terminology ) You are talking about entity and collection.
/customers/id - entity,
/customers/id/payments - collection,
/customers/id/logs - collection.
These are 3 different requests. So, yes, you need make 3 different requests.
But, to be honest, if you don't need pagination over payments and logs you can have only one request to /customers/id and within response you can have fields with array
{
"_links": {
"self": {
"href": "http://localhost:8080/status/3c10c391-f56c-4d04-a889-bd1bd8f746f0"
}
},
"id": "3c10c391-f56c-4d04-a889-bd1bd8f746f0",
...
_payments: [
...
],
_logs: [
...
],
}
Upd (duplicate from comment for future visitors).
Also, you should pay attention to DTO. I suppose this link will be interesting https://stackoverflow.com/a/36175349/1581741 .
Upd2.
At current moment I treat your collection /customers/id/payments like this:
/payments?user_id=123
where user_id is filtering field on payments table.
I think your problem that you confuse your REST API with your database. They don't have to follow the same structure. You can easily return the whole nested JSON for GET /customers/{id} if that's what you need from your REST API.

How to correct my design to avoid circular dependency

I'm banging my head to find a solution to this but still i'm unable, I'm looking for a design vice solution not a hack to fix the issue.
I have following classes
class CourseService{
public function getCourse($courceId){
$course = $this->courseRepo->getCourse($courseId);
$restrictions = $this->invoiceService->getRestrictions($course->courseid);
$course->restrictions = [];
if($restrictions != null){
$course->restrictions = $restrictions;
}
}
}
Now this course service is injected in the constructor of the StudentService because when students need to enroll to a cource i use this course service there.
also you can see that I have used CourseRepo to get Course object and then InvoiceService to say which fields are restricted to update, basically restrictions attributes gives an array of strings defining which fields are not allowed to edit and I expect UI developer will use it to disable those fields, and I had to inject InvoiceService because there are some processing to do to the raw db records that are fetched from the InvoiceRepo so invoice repo is encapsulated in the invoiceService
now lets look at the InvoiceService
Class InvoiceService{
public function getAmountToPay($courseid, $studentid){
//now I need to inject StduentService inorder to get student info which needed for the calculation
}
}
but I can't inject StudentService into here because StudentService -> CourceService -> InvoiceService
Options I see and the consequences
One option I see is to get rid of InvoiceService from the CourseService and use InvoiceService in the place where the getCourse() get called and then modify the result but the problem is, CourseService is used mainly in controllers and next thing is that getCourse() get called from many controllers and service and expects the restrictions to be there so if I want to get rid of the InvoiceService then I'll have many places to add the removing lines and it crates a code repetition.
I can move getAmountToPay() to student service but then that service has already doing many student related tasks and i'm happy to extract just the invoice part to another service so I have a clear place to look when I need to check for bugs on invoices.
Student service:
First of all you have to see - actually to decide - that a student service uses an invoice service, not the reciprocal. When I enroll myself as a history student, I go to the registration/students office first. They are calling the financial/invoice office to ask about how much should I pay. The financial office checks in the database and returns the response regarding the amount to be payed by me.
Course service:
...The time passed by. Now I'm a student. I don't need to go to the registration office anymore. If I have to know something about my courses I go to the secretariat/course service. They'll give me all the informations I need about my courses. But, if I want to visit some special archeology course, where one must pay something, the course service will call the financial/invoice service to ask about that for me. They, in turn, will return the infos. The same applies if the course service wants to know about some financial restrictions I should have: they call the financial/invoice service.
Invoice service - student service, invoice service - course service:
Now, what should happen, if the invoice service needs infos about a student or a course? Should it call the student service, or the course service for that? The answer is no. The invoice service should receive a student id, a course id, a domain object Student, or a domain object Course as constructor/methods dependencies, but not the corresponding service(s). And it will fetch the infos it needs by itself. More of it, the invoice service should work with its specific invoice/financial tables, not with the course tables or the student details tables (except their id's).
Conclusions:
To enroll a student is the job of the StudentService. Though the
CourseService can assist the enrollment process.
StudentService verifies the amount to be paid by a student by calling
the InvoiceService. I know you don't want to have getAmountToPay()
inside the StudentService, but it's a natural workflow. You may think
of separate the other many things, for which the StudentService is
responsible, to another services.
The CourseService is responsible for finding a course, together with
the course restrictions, for which it calls the InvoiceService. So,
the CourseService will be assisted by the InvoiceService.
Down under I passed you the PHP version of my vision. I renamed some functions, to give you a better perspective.
Good luck!
P.S: I hope I understood right, that the sense of "invoice sevice" is a "financial department" one. Sorry, but I'm not a native english speaker, so I can't know all the senses.
<?php
class StudentService {
protected $courseService;
protected $invoiceService;
/**
* Even if the course service uses the invoice service,
* doesn't mean that the student service shouldn't use it too.
*
* #param CourseService $courseService
* #param InvoiceService $invoiceService
*/
public function __construct(CourseService $courseService, InvoiceService $invoiceService) {
$this->courseService = $courseService;
$this->invoiceService = $invoiceService;
}
/**
* Enroll a student to a course.
*
* #param integer $studentId
* #param integer $courseId
* #return bool Enrolled or not.
*/
public function enrollToCourse($studentId, $courseId) {
//... Use here the CourseService too - for what you said regarding the enrollment.
$enrolled = $this->studentRepo->enrollToCourse($studentId, $courseId);
return $enrolled;
}
/**
* Get the amount to be payed by a student on the enrollment moment.
*
* #param integer $studentId
* #param integer $courseid
* #return integer Amount to be payed.
*/
public function getAmountToPayOnEnrollment($studentId, $courseid) {
$amount = $this->invoiceService->getAmountToPayOnEnrollment($studentId, $courseid);
return $amount;
}
}
class CourseService {
protected $invoiceService;
/**
* Invoice service is used to get the (financial) restrictions for a course.
*
* #param InvoiceService $invoiceService
*/
public function __construct(InvoiceService $invoiceService) {
$this->invoiceService = $invoiceService;
}
/**
* Get a course and its corresponding (financial) restrictions list.
*
* #param integer $courseId
* #return Course Course domain object.
*/
public function getCourse($courseId) {
$course = $this->courseRepo->getCourse($courseId);
$course->restrictions = $this->getRestrictionsForCourse($course->courseId);
return $course;
}
/**
* Get the (financial) restrictions for a specified course.
*
* #param integer $courseId
* #return array Restrictions list.
*/
public function getRestrictionsForCourse($courseId) {
$restrictions = $this->invoiceService->getRestrictionsForCourse($courseId);
return $restrictions;
}
}
Class InvoiceService {
/**
* No student service needed!
*/
public function __construct() {
//...
}
/**
* Again, no student service needed: the invoice service
* fetches by itself the needed infos from the database.
*
* Get the amount to be payed by a student on the enrollment moment.
*
* #param integer $studentId
* #param integer $courseid
* #return integer Amount to be payed.
*/
public function getAmountToPayOnEnrollment($studentId, $courseid) {
$amount = $this->invoiceRepo->getAmountToPayOnEnrollment($studentId, $courseid);
return $amount;
}
/**
* Get the (financial) restrictions for a course.
*
* #param integer $studentId
* #param integer $courseid
* #return array Restrictions list.
*/
public function getRestrictionsForCourse($courseid) {
$restrictions = $this->invoiceRepo->getRestrictionsForCourse($courseid);
return isset($restrictions) ? $restrictions : [];
}
/*
* Quote: "Some processing to do to the raw
* db records that are fetched from the InvoiceRepo".
*/
//...
}
I would change your invoiceService to not depend on student service. Pass in what you need to the invoiceService. The logic of what to do with those student details can stay in invoiceService, but the content can be passed in.

wordpress plugin WPdeposit, how to use the functions

I have installed the plugin WPdeposit on my wordpress site, it allows users to deposit into their account balance. I am trying to manipulate users balances when they press an anchor tag on the page.
In the directory plugins/models/user.php there are many functions, I think im interested in this one:
/**
* Update Regular balance to given amount (Will overwrite whatever value is in the db!)
*
* #param int $amount
* #return boolean
*/
public function updateRegularBalance($amount) {
if (floatval($amount)) {
return (bool) update_user_meta($this->_id, WPDEPOSIT_NAME.self::USER_AMOUNT, $amount);
} else {
throw new \Exception(__('Amount is not a number', WPDEPOSIT_NAME));
}
}
when I try to call this function to the page on the theme's index.php like so:
updateRegularBalance(5);
but I receive this error.
Fatal error: Call to undefined function updateRegularBalance()
is there a way to access the use of this function so I can pass in the value I want to update the balance to?
$class = new UserModel();
$class->updateRegularBalance(9999);
it was never a function I was trying to use, it was a method.

Magento Event Not Found

I have working on magento 1.6.1.0 version. I have not found any event to call after shipping generate or after order status completed.
Then i call our module observer when order status is completed.
After order status complete, i want to update a customer attribute value.
please give me answer of this problem.
I have search and do various things but they are not useful.
The first place to start would be the sales_order_save_after event. This certainly will work, but will be called any time the order is updated and saved. Therefore the logic must consider when the order is newly created & complete straightaway, or when the order is marked as complete later on (the latter being the most common). You may need to adjust logic and acceptable end-state values for orders based on cancellations, multiple orders, etc.
/**
* Update customer attribute when order is completed.
*
* Need to catch two conditions:
* 1) Order is new AND `status` = complete
* 2) Order exists but `status` is changed to complete
*
* #param $obs Varien_Event_Observer
*/
public function adjustCustomerAfterComplete($obs)
{
/* #var $order Mage_Sales_Model_Order */
$order = $obs->getOrder();
if ($order->getStatus() === $order::STATE_COMPLETE
&& $order->getOrigData('status' !== $order::STATE_COMPLETE))
{
Mage::getModel('customer/customer')
->load($order->getCustomerId())
->setCustomAttr('new val') //custom attr code
->save();
//Another approach if you don't need events, etc.:
/*
$obj = new Varien_Object(
array(
'entity_id'=>$order->getCustomerId(),
'custom_attr'=>'new val'
)
);
Mage::getResourceModel('customer/customer')
->saveAttribute($obj,'custom_attr');
*/
}
}

Categories