Trying to understand, why I'm not able to popup users balance using paypal sandox.
Here is my AccountBalance.php part code, when user paid in paypal
public function rebuildBalance($user_id, $amount, $bonus = 0, $frozen = false, $currency) {
$balance = UserBalance::where('user_id', $user_id)->where('currency_id', $currency)->first();
if ($bonus == 0) {
if ($frozen) {
$balance->balance_frozen += $amount;
} else {
$balance->balance += $amount;
}
} else {
$balance->bonus += $amount;
}
And when transaction is over, I got Creating default object from empty value
to this part $balance->balance += $amount;
Thankx
This is because your $balance variable is null from this query:
$balance = UserBalance::where('user_id', $user_id)->where('currency_id', $currency)->first();
Figure out why this query doesn't work the way you intend it to and you should be fine. A good start would be to figure out what $currency variable holds - and make sure you pass it correctly when calling rebuildBalance(args).
If you try to assign a property to null you get your exact error.
Related
I just started studying OpenCart, downloaded latest version of opencart and reading the documentation about where to find the function definition of tax calculate function.
In the non admin side, opening any Products shows data with tax calculation. Here is code it uses it.
$this->tax->calculate($product_info['price'], $product_info['tax_class_id'], $this->config->get('config_tax'))
Is there any link to check the location of tax class for checking the calculate function definition?
Not quite sure what exactly do you want to achieve. But the calculate function you can find in system/library/cart/tax.php.
public function calculate($value, $tax_class_id, $calculate = true) {
if ($tax_class_id && $calculate) {
$amount = 0;
$tax_rates = $this->getRates($value, $tax_class_id);
foreach ($tax_rates as $tax_rate) {
if ($calculate != 'P' && $calculate != 'F') {
$amount += $tax_rate['amount'];
} elseif ($tax_rate['type'] == $calculate) {
$amount += $tax_rate['amount'];
}
}
return $value + $amount;
} else {
return $value;
}
}
Although in this file you will find a lot of interesting connected with tax processing in OpenCart.
If this information not enough - please, describe the desired result with more details and I will try to help.
I'm trying to set additional custom attribute while using Accessor in Laravel model.
Example:
I'm calculating promotion price and setting this new attribute, but in additional want to set "$promo = 1 || $promo = 0" using the same logic.
The very cut example just with logic. The real logic is far deeper, that's why I don't want to duplicate the accessor:
public function getFinalPriceAttribute($value)
{
if($this->promotion == true) {
$final_price = $this->price * 100;
//here I want to add new attribute (promo = 1)
//Something like using another method here to setAttribute. Example: setPromoAttribute(1)
} else {
$final_price = $price;
//here I want to add new attribute (promo = 0)
//Something like using another method here to setAttribute. Example: setPromoAttribute(0)
}
return $final_price;
}
protected $appends = ['final_price', 'on_sale'];
}
I can easily duplicate the whole getFinalPriceAttribute(), but make no sense to have exactly the same code in two getAttribute() accessors. Any idea?
I don't know whether this is the correct implementation of what you want to achieve but here are two hacks:
1.
Create a virtual relation for this row in accessor with a new Illuminate\Database\Eloquent\Collection and then push the item promo value into it. But THIS WILL BE AN ARRAY.
public function getFinalPriceAttribute($value)
{
$this->setRelation('promo', new Collection());
if($this->promotion == true) {
$final_price = $this->price * 100;
$this->promo->push(1);
} else {
$final_price = $price;
$this->promo->push(1);
}
return $final_price;
}
So in response, you'll get promo as array like:
{
"promotion": true,
"promo": [
1
]
}
or
{
"promotion": false,
"promo": [
0
]
}
2.
Create two accessors for promo. One as promo0 & other is promo1 and append the attribute dynamically(and conditionally) with append(). But this way you'll get two different attributes in response conditionally.
public function getPromo1Attribute()
{
return true;
}
public function getPromo0Attribute()
{
return true;
}
public function getFinalPriceAttribute($value)
{
if($this->promotion == true) {
$final_price = $this->price * 100;
$this->append('promo1');
} else {
$final_price = $price;
$this->append('promo0');
}
return $final_price;
}
And this will return the response like:
{
"promotion": true,
"promo1": true
}
or
{
"promotion": false,
"promo0": true
}
I hope this will help at least someone in the future.
i am writing a program using mvc , and because the program i am writing is for admitting bank transactions, the resaults this program gives me is very important to me. and i need this to work without any logical errors and everything should workout with needed focus and giving me the exact thing i expect it to give. the thing that i want it to do for me is that some information will be sent out to the program with web service (like price, info, etc...) and then using a controller it checks the information and calls for the module, and sends the information to it. the it puts the module information to a stdclass and then using the PDO module it creates a transaction. and while the transaction is at work an insert command is sent for the database, and then we have a SELECT command and the program works well even after the insert command but while SELECT is at work , we have repetitive IDs which is the problem here:
my code:
//WSDL Creattor And Class
<?php
ini_set("soap.wsdl_cache_enabled", 1);
set_time_limit(300);
class wsdl extends Controller
{
public function index()
{
if (isset($_SERVER['REQUEST_METHOD']) && $_SERVER['REQUEST_METHOD'] == 'POST') {
$servidorSoap = new SoapServer('http://' . $_SERVER['SERVER_NAME'] . '/wsdl');
$servidorSoap->setClass('wsdl');
$servidorSoap->handle();
}
}
public function request($pin = null, $amount = 1, $callback = null, $orderid = null, $desc = null)
{
if(empty($callback))
return -10; // call back is empty.
if (empty($pin) && $result->pin != $pin)
return -1; // pin invalid
$this->Model("payment");
$au = $this->mod->Request($result, $amount, $callback, $orderid, $desc);
return $au;
}
}
payment model:
<?php
class Payment_mod extends Model
{
public function Request($gateway, $amount, $callback, $orderid, $description)
{
// using pdo module
$this->DB->CONNECT->beginTransaction();
try {
$trans = new stdClass;
$trans->gateway_id = $gateway->id;
$trans->au = str_replace('.', '_temp_', microtime(true));
$trans->price = $amount;
$trans->order_id = $orderid;
$trans->ip = $_SERVER['REMOTE_ADDR'];
$trans->time = time();
$trans->call_back = $callback;
$trans->description = $description;
$this->DB->Insert("trans", $trans); // insert into table trans …
$id = $this->DB->Fetch("trans", "`gateway_id` =" . $trans->gateway_id . " AND `price`=".$trans->price." AND time = " . $trans->time)->id; // select id from trans where …
$u = new stdClass;
$u->t_id = $id;
$this->DB->Insert("test",$u); // insert into test . it for test table for check result
$this->DB->CONNECT->commit();
} catch (Exception $e) {
$this->DB->CONNECT->rollBack();
return -9; // return unknow error.
}
return $id;
}
}
for understanding where the problem exactly is and how many times each ID repeats itself, i added a table and i got the amount of return data of SELECT and put it into the database. and when i hold the f5 key for some seconds it shows that each ID repeats nearly 9 times.
screenshot:
http://uploads.im/biWEn.jpg
note: this picture shows the amount of repeat of IDs.
where is the problem? i need this to repeat a specific ID for each call.
i did the exact thing in YII framework and i had no problem there and the progam worked exactly as i needed it to. i'd be glad if you help me.
Basically, I have two functions as shown below, the first function checks if the pickup is an airport address (which is being sent via ajax from jquery function). If it is an airport basically I want to send the variable $fare from getAirportFare function to getFinalFare function, so that it adds a charge if it is an airport address. I was just wondering how I would do this? (still trying to learn PHP)
Any help would be much appreciated.
//DEBUG//
public function getAirportFare($fare, $fieldAirport) {
if ($fieldAirport == 'airport') {
$fare = $fare + 50.00;
return $fare;
}
}
//END OF DEBUG//
private static function getFinalFare($fare) {
$final_fare = ($fare * self::$fare_factor);
if (self::$str_wait_return == "true") {
$final_fare = $final_fare * 2;
}
if (self::$str_return == "true" && self::$return_date != "false" && self::$return_time != "false") {
// We need to calc to fare based on the return date and time
$return_fare = self::getFare(1);
// Append to final fare
$final_fare = $final_fare + $return_fare;
}
// Create new journey object with the info that we have so far
/*$journey = new Journey($journey_id,$pickup,$dropoff,$vias,$distance,$vehicle,
$date_time,$return_journey,$meet_greet,$extras);*/
return number_format($final_fare,2);
}
To send a variable from one function to another (or from an instance method to a static method, as you're doing here), call the second function within the first function, and pass it the variable as an argument, like so:
public function getAirportFare($fare, $fieldAirport) {
if ($fieldAirport == 'airport') {
$fare = $fare + 50.00;
return self::getFinalFare($fare);
}
}
Your instance method will now return the return value of your static method.
If I understand this correctly, it's as simple as this:
//DEBUG//
public function getAirportFare($fare, $fieldAirport) {
if ($fieldAirport == 'airport') {
$fare = $fare + 50.00;
// Send the fare to the getFinalFare function and assign it's result.
$final_fare = self::getFinalFare($fare);
return $final_fare;
}
}
Let me know if I haven't answered your question.
I believe you must declare global $fare outside the function, and when use inside it, use $this->fare.
I am trying to get the subtotal amount on checkout success page. It works good for registred users:
$_order = Mage::getModel('sales/order')->loadByIncrementId($this->getOrderId());
$amount = $_order->getData('subtotal');
$total = number_format($amount, 2);
But when the order is processed by a guest, $total is empty.
What can be done?
P.S.: I am using Magento 1.6.1 CE
Taken from Magento's app/code/core/Mage/Checkout/Block/Onepage.php:
if (!$this->isCustomerLoggedIn()) {
return $this->getQuote()->getShippingAddress();
} else {
return Mage::getModel('sales/quote_address');
}
I am 99% sure you can do exactly the same with getOrder() and with Mage_Checkout_Block_Success =)
Note: the isCustomerLoggedIn() method is defined at Mage_Checkout_Block_Onepage_Abstract which is not inherited by Mage_Checkout_Block_Success. So, you could simply use its implementation:
public function isCustomerLoggedIn()
{
return Mage::getSingleton('customer/session')->isLoggedIn();
}
E.g. your code now shall look like this:
if (!Mage::getSingleton('customer/session')->isLoggedIn()) {
$order = Mage::getSingleton('checkout/session')->getOrder();
} else {
$order = Mage::getModel('sales/order')->loadByIncrementId($this->getOrderId());
}
Sorry for saying non-sense things before...