Jump to content

Get database value from a customer and display on tpl


Aioras

Recommended Posts

Hi everybody!

 

Well I'm trying to develop a functionality in which you can set from the admin panel a especial tax for some clients.

Thing I have done:

 

Created a database column to store if client needs special tax

Created a backed button on the backend edit customer

 

Things I want to do but I'm stuck:

Retrieve customer database value which is a boolean to know if special tax is active on that client

 

Would be nice to have a field also in which you can set the special tax (would be the same value for every client with special tax)

 

 

Files Edited:

 

Override on class customer for the new field

 

class Customer extends CustomerCore
{
    public $recargoequivalencia = 0;
 
    public function __construct($id = null)
    {
        self::$definition['fields']['recargoequivalencia'] = array('type' => self::TYPE_BOOL, 'validate' => 'isBool');
        parent::__construct($id);
    }
}
?>
 
Override In customer controller:
 
Added field:
elseif (Tools::isSubmit('changeRecargoequivalenciaVal') && $this->id_object)
{
   if ($this->tabAccess['edit'] === '1')
      $this->action = 'change_recargoequivalencia_val';
   else
      $this->errors[] = Tools::displayError('You do not have permission to edit this.');
}
 
also modified the render form!
 
for now the value on the database is working fine!
But don't know how to retrieve that field!
 
Thanks in advance! :)
 
Link to comment
Share on other sites

But the point is that I would like to show them on a tpl file for example in the shopping cart

I have tried this for example in category.tpl just to debug:

 

 

 

You can access the value directly since the field is the customer class field,

$customerObject = new Customer(1);
$customerObject->recargoequivalencia;

Thanks for the answer, but the point is that I would like to check that value from the tpl file to do something like:

{if isset ($customer->recargoequivalencia)}

   **apply special tax**

{/if}

 

what would be the best way for doing ?

Edited by Aioras (see edit history)
Link to comment
Share on other sites

ok...
 

And anybody knows how to display customer database values on Cart ?

 

because {$customer->whatever} isn't working

 

I also added this function to the Customer.php (override)
 

public static function hasEquivalenceSurcharge ($id_customer)
   {
        $sql = 'SELECT `recargoequivalencia`
                FROM `'._DB_PREFIX_.'customer`
                WHERE `id_customer` = '.(int)$id_customer;
        
        $recargoequivalencia = Db::getInstance()->ExecuteS($sql);
        return $recargoequivalencia;
   }
 
and then in the AdminCustomerController.php (override) this one:
 
public function checkEquivalenceSurcharge() {
            $recargoequivalencia = Customer::hasEquivalenceSurcharge($this->context->customer->id);
            return $this->context->smarty->assign('recargoequivalencia', $recargoequivalencia);
        }
 
 
Just to see if I could create a "global" var but I think this is wrong because shouldn't be in the admincontroller... but I've no more imagination T.T
 
Finally I got it creating a new override in Cart.php:
 
In function:
 
public function getSummaryDetails($id_lang = null, $refresh = false)
 
at the end you have:
 
return array(
			'delivery' => $delivery,
			'delivery_state' => State::getNameById($delivery->id_state),
			'invoice' => $invoice,
			'invoice_state' => State::getNameById($invoice->id_state),
			'formattedAddresses' => $formatted_addresses,
			'products' => array_values($products),
			'gift_products' => $gift_products,
			'discounts' => array_values($cart_rules),
			'is_virtual_cart' => (int)$this->isVirtualCart(),
			'total_discounts' => $total_discounts,
			'total_discounts_tax_exc' => $total_discounts_tax_exc,
			'total_wrapping' => $this->getOrderTotal(true, Cart::ONLY_WRAPPING),
			'total_wrapping_tax_exc' => $this->getOrderTotal(false, Cart::ONLY_WRAPPING),
			'total_shipping' => $total_shipping,
			'total_shipping_tax_exc' => $total_shipping_tax_exc,
			'total_products_wt' => $total_products_wt,
			'total_products' => $total_products,
			'total_price' => $base_total_tax_inc,
			'total_tax' => $total_tax,
			'total_price_without_tax' => $base_total_tax_exc,
			'is_multi_address_delivery' => $this->isMultiAddressDelivery() || ((int)Tools::getValue('multi-shipping') == 1),
			'free_ship' => $total_shipping ? 0 : 1,
			'carrier' => new Carrier($this->id_carrier, $id_lang),
                        
		);

Those are variables that can be called from cart controller, so I added 2 more variables and set them like:

return array(
			'delivery' => $delivery,
			'delivery_state' => State::getNameById($delivery->id_state),
			'invoice' => $invoice,
			'invoice_state' => State::getNameById($invoice->id_state),
			'formattedAddresses' => $formatted_addresses,
			'products' => array_values($products),
			'gift_products' => $gift_products,
			'discounts' => array_values($cart_rules),
			'is_virtual_cart' => (int)$this->isVirtualCart(),
			'total_discounts' => $total_discounts,
			'total_discounts_tax_exc' => $total_discounts_tax_exc,
			'total_wrapping' => $this->getOrderTotal(true, Cart::ONLY_WRAPPING),
			'total_wrapping_tax_exc' => $this->getOrderTotal(false, Cart::ONLY_WRAPPING),
			'total_shipping' => $total_shipping,
			'total_shipping_tax_exc' => $total_shipping_tax_exc,
			'total_products_wt' => $total_products_wt,
			'total_products' => $total_products,
			'total_price' => $base_total_tax_inc,
			'total_tax' => $total_tax,
			'total_price_without_tax' => $base_total_tax_exc,
			'is_multi_address_delivery' => $this->isMultiAddressDelivery() || ((int)Tools::getValue('multi-shipping') == 1),
			'free_ship' => $total_shipping ? 0 : 1,
			'carrier' => new Carrier($this->id_carrier, $id_lang),
                        'hasrecargoequivalencia' => (bool)RecargoEquivalencia::hasRecargoEquivalencia($this->id_customer),
                        'cantidadrecargo' => ((float)RecargoEquivalencia::getRecargoEquivalencia()/100),
                        
		);

Those variables are set in the module function and that way I can call them from shopping-cart.tpl

 

and the are shown!

 

BUT...

 

I have a new incidence....

when I try to change the product quantity from the cart sumary, I get this error:

 

TECHNICAL ERROR: unable to save update quantity Details: Error thrown: [object Object] Text status: parsererror

 

*****EDITED*******

 

It fixed by disabling and enabling module :)

 

**********************

 

I imagin that's because there is once function called on cartUpdate that I will have to look for..

 

Does somebody know which functions I should update for the cart quantity update??

 

*******EDITED********

 

I'm trying to edit cart-summary.js

 

Is there any way of getting the smarty variable into the cart-summary.js ?

I'd seen on internet that you can get it by doing:

var quantityrecargo = {$cantidadrecargo};

but that isn't working on the .js

 

 

************************

 

 

Thanks in advance!

 

 

 

 

 

 
Edited by Aioras (see edit history)
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...