第2行出现意外的T_Public错误

时间:2015-03-03 03:23:20

标签: php

我在此代码中遇到意外的T_Public错误“public function checkSubTotal(){

你能建议修复吗? 谢谢,

public function hasRecurringProducts(){// BOF - Zappo - Group Discounts - Get Total Price in Cart (Excluding Discounts)
    public function checkSubTotal(){
    $total = 0;
    $customer_group_id = ($this->customer->isLogged()) ? $this->customer->getCustomerGroupId() : $this->config->get('config_customer_group_id');
    foreach ($this->session->data['cart'] as $key => $quantity) {
        $product = explode(':', $key);
        $product_id = $product[0];
        $options = (isset($product[1]) && $product[1]) ? unserialize(base64_decode($product[1])) : array();
        $product_query = $this->db->query("SELECT * FROM " . DB_PREFIX . "product p LEFT JOIN " . DB_PREFIX . "product_description pd ON (p.product_id = pd.product_id) WHERE p.product_id = '" . (int)$product_id . "' AND pd.language_id = '" . (int)$this->config->get('config_language_id') . "' AND p.date_available <= NOW() AND p.status = '1'");
        if ($product_query->num_rows) {

            $discount_quantity = 0;
            foreach ($this->session->data['cart'] as $key_2 => $quantity_2) {
                $product_2 = explode(':', $key_2);
                if ($product_2[0] == $product_id) $discount_quantity += $quantity_2;
            }

1 个答案:

答案 0 :(得分:0)

如果你想保持checkSubTotal()公开,那么就这样做:

public function hasRecurringProducts()
{
   checksubtotal();
   // ... extra code
}

public function checkSubTotal()
{
    $total = 0;
    $customer_group_id = ($this->customer->isLogged()) ? $this->customer->getCustomerGroupId() : $this->config->get('config_customer_group_id');
    foreach ($this->session->data['cart'] as $key => $quantity) 
    {
        $product = explode(':', $key);
        $product_id = $product[0];
        $options = (isset($product[1]) && $product[1]) ? unserialize(base64_decode($product[1])) : array();
        $product_query = $this->db->query("SELECT * FROM " . DB_PREFIX . "product p LEFT JOIN " . DB_PREFIX . "product_description pd ON (p.product_id = pd.product_id) WHERE p.product_id = '" . (int)$product_id . "' AND pd.language_id = '" . (int)$this->config->get('config_language_id') . "' AND p.date_available <= NOW() AND p.status = '1'");
    if ($product_query->num_rows) 
    {
        $discount_quantity = 0;
        foreach ($this->session->data['cart'] as $key_2 => $quantity_2) 
        {
            $product_2 = explode(':', $key_2);
            if ($product_2[0] == $product_id)
            {
               $discount_quantity += $quantity_2;
            }
          }
        }
     }
  }

否则,您无法将checkSubTotal()定义为public。这样做:

public function hasRecurringProducts()
{
   function checkSubTotal()
  {
    $total = 0;
    $customer_group_id = ($this->customer->isLogged()) ? $this->customer->getCustomerGroupId() : $this->config->get('config_customer_group_id');
    foreach ($this->session->data['cart'] as $key => $quantity) 
    {
        $product = explode(':', $key);
        $product_id = $product[0];
        $options = (isset($product[1]) && $product[1]) ? unserialize(base64_decode($product[1])) : array();
        $product_query = $this->db->query("SELECT * FROM " . DB_PREFIX . "product p LEFT JOIN " . DB_PREFIX . "product_description pd ON (p.product_id = pd.product_id) WHERE p.product_id = '" . (int)$product_id . "' AND pd.language_id = '" . (int)$this->config->get('config_language_id') . "' AND p.date_available <= NOW() AND p.status = '1'");
    if ($product_query->num_rows) 
    {
        $discount_quantity = 0;
        foreach ($this->session->data['cart'] as $key_2 => $quantity_2) 
        {
            $product_2 = explode(':', $key_2);
            if ($product_2[0] == $product_id)
            {
               $discount_quantity += $quantity_2;
            }
          }
        }
     }
  }