我在magento结帐时遇到问题。通过集成Billsafe Payment插件,我在结帐过程中收到以下错误:
HTTP-Error 500 (Internal Server Error):
错误日志显示:
mod_fcgid:stderr:PHP致命错误:在/var/www/vhosts/domain.com/httpdocs/app/code/community/AwHh/PaymentFee/Helper/中调用非对象上的成员函数setName() Data.php
任何想法?
Data.php的代码:
/**
* Check if the extension is active
*
* @return boolean
*/
public function isEnabled()
{
return (bool)Mage::getStoreConfig('payment_services/paymentfee/active');
}
/**
* Check if minimum fee amount, maximum fee amount or percentage rate is given
* @return boolean
*/
public function hasFeeValues()
{
$min = (bool)max(0, Mage::getStoreConfig('payment_services/paymentfee/min_fee_amount'));
$max = (bool)Mage::getStoreConfig('payment_services/paymentfee/max_fee_amount');
$rate = (bool)Mage::getStoreConfig('payment_services/paymentfee/relative_fee');
return ($min || $max || $rate);
}
public function getFeeProductSku()
{
return Mage::getStoreConfig('payment_services/paymentfee/sku');
}
/**
* if item represents fee product
*
* @param Mage_Catalog_Model_Product|Mage_Sales_Model_Item $product
* @return boolean
*/
public function isFeeProduct($product)
{
return ($product->getSku() == $this->getFeeProductSku());
}
public function setFeeProduct($feeProduct)
{
$this->feeProduct = $feeProduct;
}
public function getFeeProduct()
{
if (is_null($this->feeProduct)) {
$this->feeProduct = Mage::getModel('catalog/product')->loadByAttribute('sku', $this->getFeeProductSku());
}
return $this->feeProduct;
}
public function hasFeeProduct()
{
$feeProduct = $this->getFeeProduct();
return ($feeProduct && 0 < $feeProduct->getId());
}
/**
* Obtain the fee that is set for the current payment method
* @return float
*/
public function getPaymentFee()
{
if (!$this->isEnabled()) {
return 0;
}
if (!Mage::getModel('checkout/cart')->getQuote()->getPayment()->hasMethodInstance()) {
return 0;
}
// get the currently set payment method
$payment_model = Mage::getModel('checkout/cart')->getQuote()->getPayment()->getMethodInstance();
// check which methods are enabled for payment fee via backend
$enabled_methods = explode(',', Mage::getStoreConfig('payment_services/paymentfee/payment_methods'));
if (!$payment_model || !in_array($payment_model->getCode(), $enabled_methods)) {
return 0;
}
// return fee if
// (1) a payment method has been selected by the customer
// (2) the selected payment method is enabled for payment fee via backend
// (3) the payment method has a fee
return (float)$payment_model->getFee();
}
/**
* get quote item representing fee
*
* @return Mage_Sales_Model_Quote_Item
*/
protected function getFeeQuoteItem()
{
foreach (Mage::getSingleton('checkout/session')->getQuote()->getItemsCollection() as $item) {
if ($this->isFeeProduct($item->getProduct())) {
return $item;
}
}
}
/**
* Computed amount of payment fee based on backend configuration
* and grand total and attach it to fee product.
*/
public function getUpdatedFeeProduct($product=null, $grandTotal=null)
{
if (!$product) {
$product = $this->getFeeProduct();
}
$product->setName($product->getResource()->getAttributeRawValue($product->getId(), 'name', Mage::app()->getStore()->getId()));
if (!$grandTotal) {
$quote = Mage::getSingleton('checkout/session')->getQuote();
$grandTotal = $quote->getGrandTotal();
$feeAmount = 0;
foreach ($quote->getItemsCollection() as $quoteItem) {
if ($this->isFeeProduct($quoteItem->getProduct())) {
$feeAmount = $quoteItem->getBaseRowTotalInclTax();
continue;
}
}
$grandTotal -= $feeAmount;
}
$min = max(0, Mage::getStoreConfig('payment_services/paymentfee/min_fee_amount'));
$max = Mage::getStoreConfig('payment_services/paymentfee/max_fee_amount');
$rate = Mage::getStoreConfig('payment_services/paymentfee/relative_fee');
//$product->setName($this->__('Payment fee'));
if ($this->getFeeQuoteItem()) {
$product->setTaxPercent($this->getFeeQuoteItem()->getTaxPercent());
}
// first, set payment fee to the price configured in backend
$price = $max;
// If set to zero, do not limit the final fee
if (!$max) {
$max = INF;
}
$product->setCheckoutDescription($this->formatPrice($price))
->setExceedsMaxAmount(false)
->setExceedsMinAmount(false);
// calculate relative fee if given in backend
if ($rate) {
$price = $grandTotal * $rate / 100;
if ($max < $price) {
// calculated relative fee exceeds maximum charge
// -> use maximum charge
$product->setCheckoutDescription($this->formatPrice($max));
$product->setExceedsMaxAmount(true);
$price = $max;
} elseif ($price < $min) {
// calculated relative fee is below minimum charge
// -> use minimum charge
$product->setCheckoutDescription($this->formatPrice($min));
$product->setExceedsMinAmount(true);
$price = $min;
} else {
// calculated relative fee is between minimum and maximum charge
// -> use calculated relative fee
$msg = '%s (%s%% of Total %s)';
$product->setCheckoutDescription($this->__(
$msg,
$this->formatPrice($price),
$rate,
$this->formatPrice($grandTotal)
));
$msg = '%s %s (%s%% of Total %s)';
$product->setName($this->__(
$msg,
$product->getName(),
strip_tags($this->formatPrice($price)),
$rate,
strip_tags($this->formatPrice($grandTotal))
));
}
}
$product->setPriceInclTax($price)
->setPrice($price)
->setFinalPrice($price);
// Make sure fee product is "in stock"
$stockItem = Mage::getModel('cataloginventory/stock_item');
$stockItem->assignProduct($product);
$stockItem->setIsInStock(1);
$stockItem->setManageStock(1);
$stockItem->setQty(10000);
$stockItem->save();
return $product;
}
public function removeFeeFromQuote(Mage_Sales_Model_Quote $quote)
{
foreach ($quote->getItemsCollection() as $quoteItem) {
if ($this->isFeeProduct($quoteItem->getProduct())) {
$quote->removeItem($quoteItem->getId());
}
}
}
}
答案 0 :(得分:1)
我遇到了同样的问题。 解: 你可能没有添加虚拟文章。
转到您的管理员,选择目录 - &gt;管理文章 添加一个新的并选择虚拟文章 给它一些名字,并确保它的活动,不可见 将SKU设置为某些东西并复制它。你以后需要它! 设定价格为零,库存至少为1 您可以选择是否给予更高的库存或只有一个并转向库存管理。 保存后转到system-&gt; configuration-&gt; paymenttypes,你必须这样做 将您刚刚复制的SKU粘贴到SKU所说的字段中。
毕竟你必须清除你的缓存,然后你去:)
答案 1 :(得分:0)
辅助类扩展了Mage_Core_Helper_Abstract
..
类Mage_Catalog_Helper_Data
不会扩展varien_object,因此getName()
函数会导致此错误。
而不是从辅助类对象调用getname。
使用
$model = getmodel('whatever')
然后致电
$model->getName()
从那里开始。
答案 2 :(得分:0)
或者,您可以<配置(系统 - &gt;配置 - &gt;付款)停用Billsafe (设置有效:否)