0

我在 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/Data.php 中的非对象上调用成员函数 setName()

有任何想法吗?

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());
        }
    }
}

}

4

3 回答 3

1

我有同样的问题。解决方案:你可能没有添加虚拟文章。

转到您的 Adminarea,选择目录 -> 管理文章添加新文章并选择虚拟文章为其命名,并确保其活动且不可见,将 SKU 设置为某些内容并复制它。你以后需要它!将价格设置为零并且库存至少为 1 您可以选择是否给它更高的库存或只给它一个并转向库存管理。保存后转到 system->configuration->paymenttypes,您必须将刚刚复制的 SKU 粘贴到其中包含 SKU 的字段中。

毕竟你必须清除你的缓存然后你去:)

于 2013-03-31T14:38:24.470 回答
0

一个帮助类扩展了 extends Mage_Core_Helper_Abstract..

Mage_Catalog_Helper_Data 不扩展 varien_object 所以getName()函数会产生这个错误。

而不是从帮助类对象调用 getname。

使用 $model = getmodel('whatever')然后 $model->getName()从那里调用。

于 2013-03-21T05:25:06.887 回答
0

或者,您可以在 Configuration (System->Configuration->payment) 下禁用 Billsafe (设置 Active: no )

于 2014-05-11T18:59:19.597 回答