Magento Different Grand Total and Invoice amount - magento

Please check these 2 images; I am having an issue where Grand Total displays correctly on all pages throughout the site; But when admin sends an invoice to user it does not include some of the items in the invoiced amount.
I need suggestion on how to fix this.

I found the problem ; It comes from the generated extension from silksoftware;
If you have similar problem; open the file in this directory
/www/app/code/local/Company/ExtraFee/Model/Order/Invoice/Total
and replace this line
$DepositTotal = $order->getDepositTotal();
if ($DepositTotal&&count($order->getInvoiceCollection())==0) {
with
$orderDepositTotal= $order->getDepositTotal();
if ($orderDepositTotal&&count($order->getInvoiceCollection())==0) {
:)
Thanks guys for no help :p I ended up debugging it myself and feeling pretty good :p
<?php
class Comapny_ExtraFee_Model_Order_Invoice_Total_Deposit
extends Mage_Sales_Model_Order_Invoice_Total_Abstract
{
public function collect(Mage_Sales_Model_Order_Invoice $invoice)
{
$order=$invoice->getOrder();
$DepositTotal = $order->getDepositTotal();
if ($DepositTotal&&count($order->getInvoiceCollection())==0) {
$invoice->setGrandTotal($invoice->getGrandTotal()+$orderDepositTotal);
$invoice->setBaseGrandTotal($invoice->getBaseGrandTotal()+$orderDepositTotal);
}
return $this;
}
}

Related

About Codeigniter Members Count?

How can I make show the total number of members registered in Codeigniter?
I need model, controller, view codes.
I would appreciate if you help.
As you didn't give us more code and information though. I think you want to display the total number of users registered in your view, write this part of the code where you want to count the number.
<?php
$this->load->model('admindash_model');
$count_users = count($this->admindash_model->get());
print $count_users;
?>
I think this will going to help you. If you could understand and place
it properly.
Model:
public function get(){
$this->db->select('gorun');
$this->db->from('users');
$this->db->where('gorun', '0' );
return $this->db->count_all_results();
}
Controller:
public function admindash(){
$this->load->model("admindash_model");
$results = $this->admindash_model->get();
}

Laravel getStream - How to follow or add activity to a Company (non user)

an app I am creating needs to follow Companies, aside from users. And let the companies have their own activities. How is this configured in Laravel getStream. Seems the feeds are only for user types.
timelineFeed = FeedManager::getNewsFeed($user->id)['timeline'];
$aggregatedTimelineFeed = FeedManager::getNewsFeed($user->id)['timeline_aggregated'];
sample model i have is this:
namespace App;
use Illuminate\Database\Eloquent\Model;
class CompanyPost extends Model
{
use \GetStream\StreamLaravel\Eloquent\ActivityTrait;
public function company()
{
return $this->belongsTo('App\Company', 'company_id', 'id');
}
public function activityVerb()
{
return 'company_post';
}
public function activityActorMethodName()
{
return 'company';
}
}
but i have noticed the feed is still saved on the user activities instead of the company activities.
Thanks in advance guys.
Ian seems to have confused you with me in his link to the Github issue which brought this post to my attention.
The reason this is still showing up on the user feed is that this isn't a configurable option at least on a case by case (or model by model) level. You can override what Stream Laravel uses as the "user feed" in the main configuration but as far as I can tell you are stuck posting to the active logged in user's feed unless you build out the functionality yourself with the Stream-PHP libs and abstain from using the StreamLaravel Activity trait.
You can see here starting at Line: 73 of StreamLaravelManager.php what's happening when an activity is created.
public function activityCreated($instance)
{
$activity = $instance->createActivity();
$feed = $this->getFeed($this->userFeed, $instance->activityActorId());
$feed->addActivity($activity);
}
Unfortunately "$this->userFeed" ultimately is pulled from the configuration file and I don't think there is a way to override it.
Personally, I ran into this when creating "like" functionality. I didn't really want people to have to see what everyone "likes" on their timeline since most of it would be irrelevant and it would get cluttered fast so I ended up not even creating a "like" activity. Instead I'm only added it to a users notification feed when someone likes something of theirs. Of course this may not be desirable for everyone to handle it that way but I noticed you had the "like" activity in your screenshot so I figured I'd mention it.
Good luck on your app!
Our stream-laravel project has some documentation on how to change the model
class Pin extends Eloquent {
use GetStream\StreamLaravel\Eloquent\ActivityTrait;
public function author()
{
return $this->belongsTo('Author');
}
public function activityActorMethodName()
{
return 'author';
}
As far as letting volunteers follow companies and users, we have some documentation in the main README.
(edited to remove my mistaken github reference)
sorry for the late reply. I have managed to follow a company creating
a feed group:
company flat On
and the using sample code below to follow:
$feed = FeedManager::getClient()->feed('timeline', $user->id);
$feed->followFeed('company', $companyId);
Unfollow:
$feed->unfollowFeed('company', $companyId);
Add activity:
$companyFeed = FeedManager::getClient()->feed('company', $company->id);
$companyFeed->addActivity([
"actor" => "App\Company:{$company->id}",
"verb" => "company_post",
"object" => "App\CompanyPost:{$post->id}",
"foreign_id" => "App\CompanyPost:{$post->id}"
]);

Magento incorrect amount while paying

I have used this to create plugin http://www.silksoftware.com/magento-module-creator/ it is working fine and grand total is displaying correct; But when users pay the do not see this amount included in that;
Can you let me know what could be wrong?
Thanks!
Total screenshot
You can see that Totals are being added up in grand total but when users pay they don't see the amount for Refundable Damage/Loss Deposit; That's why it is still coming as due amount.
I found the problem ; It comes from the generated extension from silksoftware;
If you have similar problem; open the file in this directory
/www/app/code/local/Company/ExtraFee/Model/Order/Invoice/Total
and replace this line
$DepositTotal = $order->getDepositTotal();
if ($DepositTotal&&count($order->getInvoiceCollection())==0) {
with
$orderDepositTotal= $order->getDepositTotal();
if ($orderDepositTotal&&count($order->getInvoiceCollection())==0) {
:)
Thanks guys for no help :p I ended up debugging it myself and feeling pretty good :p
<?php
class Comapny_ExtraFee_Model_Order_Invoice_Total_Deposit
extends Mage_Sales_Model_Order_Invoice_Total_Abstract
{
public function collect(Mage_Sales_Model_Order_Invoice $invoice)
{
$order=$invoice->getOrder();
$DepositTotal = $order->getDepositTotal();
if ($DepositTotal&&count($order->getInvoiceCollection())==0) {
$invoice->setGrandTotal($invoice->getGrandTotal()+$orderDepositTotal);
$invoice->setBaseGrandTotal($invoice->getBaseGrandTotal()+$orderDepositTotal);
}
return $this;
}
}

Magento returning incorrect customer data on frontend pages

isn't this the right method to get Name of logged in customer?
<?php echo Mage::helper('customer')->getCustomer()->getName(); ?>
I have a website with live chat functionality. Yesterday I have been asked to pass email address and the name of the logged into the user into the Javascript Tracking variable code placed in the head section of the website. So that the operators could see who is on the website and whom are they talking to without any need to ask about their information.
So I passed the information from Magento into the Javascript code but now I see this very strange thing happening. For example,
If I am logged in with credentials Name = John Email =
john12#yahoo.com
Then This name and email variable values are changing with the change of pages. For example if I click on any product page the variable values which I am passing changes to some other user's information.
Name becomes Ricky Email becomes ricky23#gmail.com
this variable values are kept on changing back to john and from john to something else with the change of pages. So operator does not have any idea whom are they talking because the values are kept on changing. Also, user ricky or who ever it changes to also exist in the database. so it is picking up random person from the database.
This is what i did to pass the code to javascript. Please let me know if that is not the right code to pass the information. Please check the php code I am using to fetch information from Magento. Roughly, I receive incorrect value once in 5 times. Please provide some assistance. Thanks in advance.
<?php
$customer = Mage::getSingleton('customer/session')->getCustomer();
$email = $customer->getEmail();
$firstname = $customer->getFirstname();
$lastname= $customer->getLastname();
$name = $firstname . ' ' . $lastname;
?>
<script type="text/javascript">
if (typeof(lpMTagConfig) == "undefined"){ lpMTagConfig = {};}
if (typeof(lpMTagConfig.visitorVar) == "undefined"){ lpMTagConfig.visitorVar = [];}
lpMTagConfig.visitorVar[lpMTagConfig.visitorVar.length] = 'Email=<?php echo $email; ?>';
lpMTagConfig.visitorVar[lpMTagConfig.visitorVar.length] = 'Name=<?php echo $name; ?>';
</script>
I'm also attaching a snap shot
I'd be interested to hear how you're adding this code to the page? Is it in it's own block, or are you adding it to footer.phtml, or similar? If your adding to an existing block be sure to check the block caching settings of that template.
To confirm the caching hypothesis I'd ask the following:
Do you get the same name, all the time, on the same page? When you refresh the page, do you get the same name and email in the Javascript?
Does the problem persist with caching disabled?
This doesn't sound like a singleton problem at all. Each execution of the PHP script is isolated from the others, serving one page request. There's no chance of another customer's object moving between invokations of the script.
It is a matter of understanding the singleton pattern. If you call your code twice:
$customer_1 = Mage::helper('customer')->getCustomer()->getName();
$customer_2 = Mage::helper('customer')->getCustomer()->getName();
you get two different instances of the object. But... if one of them has already implemented a singleton pattern in its constructor or has implemented a singleton getInstance then both objects will actually point to the same thing.
Looking at the customer/helper/Data.php code you can see the function
public function getCustomer()
{
if (empty($this->_customer)) {
$this->_customer = Mage::getSingleton('customer/session')->getCustomer();
}
return $this->_customer;
}
That means that in one of the cases singleton is already implemented/called and in other one - not as the property is already set.
The correct way to work with quote/customer/cart in order to get always the correct data is always to use the singleton pattern.
So using this:
$customer = Mage::getSingleton('customer/session')->getCustomer();
always guarantee that you get the correct customer in that session. And as may be you know singleton pattern is based on registry pattern in app/Mage.php:
public static function getSingleton($modelClass='', array $arguments=array())
{
$registryKey = '_singleton/'.$modelClass;
if (!self::registry($registryKey)) {
self::register($registryKey, self::getModel($modelClass, $arguments));
}
return self::registry($registryKey);
}
and looking at app/Mage.php:
public static function register($key, $value, $graceful = false)
{
if (isset(self::$_registry[$key])) {
if ($graceful) {
return;
}
self::throwException('Mage registry key "'.$key.'" already exists');
}
self::$_registry[$key] = $value;
}
...
public static function registry($key)
{
if (isset(self::$_registry[$key])) {
return self::$_registry[$key];
}
return null;
}
you can see that Magento checks is it is already set. If so, Magento will either throw an Exception, which is the default behavior or return null.
Hope this will help you to understand the issue you face.
I have sorted this out. I have moved the code from footer.phtml to head.phtml and it's working fine now.Values are not changing anymore. If anyone know the logic behind please post and I will change my answer. So far this is working.

Get customer in Mage_Tax_Model_Calculation::getRate in magento

I have overwritten the Mage_Tax_model_Calculation::getRate, so that I want to not tax certain customers. I do not have a special customer class for them.
I have a custom field in my customer model, which I want to check after I am able to load my customer model and if this field has a value I do not tax him, otherwise I call parent::getRate($request)
Is it possible to get that in the function.
Try something like this:
function getRate($request) {
// find a customer ID
$admin_session = Mage::getSingleton('adminhtml/session_quote');
if($admin_session) {
if($admin_session->getCustomerId()) {
$customer_id = $admin_session->getCustomerId();
}
} else {
$customer_id = Mage::getSingleton("customer/session")->getCustomerId();
}
// find customer attr
if($customer_id) {
$customer = Mage::getModel("customer/customer")->load($customer_id);
if($customer->getSomeColumnValue()) {
return 0;
}
}
// fallthrough
return parent::getRate($request);
}
Hope that helps!
Thanks,
Joe
EDIT: good point ;)
Looking through the adminhtml code, it seems to be far less useful than the normal customer code. I was hoping for a call to Mage::register but that's not happening. I found a possible solution, though loading sessions in Magento seems to have side effects. See above.
RE-EDIT: to incorporate your fixes for posterity.
Try this to load the current logged-in customer:
$session = Mage::getSingleton('customer/session');
$customer = Mage::getModel('customer/customer')->load($session->getCustomerId());
$customValue = $customer->getCustomFieldName();
Cheers,
JD

Resources