Jump to content

How to pass a variable to a non-related tpl.


Arkataev

Recommended Posts

Hi!

 

I have a variable assigned only in productcontroller and available in product.tpl. I need this variable to be available in product-list.tpl also.

 

Here it is (from productcontroller)

protected function assignPriceAndTax()
{
  /*DIGISELLER*/
 $xml="
<digiseller.request>
<id_goods>REPLACEME</id_goods>
</digiseller.request>
";
$xml=str_replace("REPLACEME", (int)$this->product->reference ,$xml);
function _GetAnswer($address, $xml){
  $ch = curl_init($address);
  curl_setopt($ch, CURLOPT_HEADER, 0);
  curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
  curl_setopt($ch, CURLOPT_POST,1);
  curl_setopt($ch, CURLOPT_POSTFIELDS, $xml);
  $result=curl_exec($ch);
  return $result;
}

$answer=_GetAnswer("http://shop.digiseller.ru/xml/personal_goods_info.asp", $xml);

$xmlres = simplexml_load_string($answer);
foreach ($xmlres->price_goods->wmr as $price_goods) ;
$xmlres = simplexml_load_string($answer);
foreach ($xmlres->price_goods->wmu as $wmu
);

self::$smarty->assign('product-list_tpl',$wmu );

$xmlres = simplexml_load_string($answer);
foreach ($xmlres->price_goods->pcr as $pcr
);
$xmlres = simplexml_load_string($answer);
foreach ($xmlres->reward as $reward
);
$xmlres = simplexml_load_string($answer);
foreach ($xmlres->reward_summ as $arew
);
$xmlres = simplexml_load_string($answer);
foreach ($xmlres->reward_curr as $arewc
);

 $id_customer = (isset($this->context->customer) ? (int)$this->context->customer->id : 0);
 $id_group = (isset($this->context->customer) ? $this->context->customer->id_default_group : _PS_DEFAULT_CUSTOMER_GROUP_);
 $id_country = (int)$id_customer ? Customer::getCurrentCountry($id_customer) : Configuration::get('PS_COUNTRY_DEFAULT');
 $group_reduction = GroupReduction::getValueForProduct($this->product->id, $id_group);
 if ($group_reduction == 0)
  $group_reduction = Group::getReduction((int)$this->context->cookie->id_customer) / 100;
 // Tax
 $tax = (float)$this->product->getTaxesRate(new Address((int)$this->context->cart->{Configuration::get('PS_TAX_ADDRESS_TYPE')}));
 $this->context->smarty->assign('tax_rate', $tax);
 $product_price_with_tax = Product::getPriceStatic($this->product->id, true, null, 6);
 if (Product::$_taxCalculationMethod == PS_TAX_INC)
  $product_price_with_tax = Tools::ps_round($product_price_with_tax, 2);
 $product_price_without_eco_tax = (float)$product_price_with_tax - $this->product->ecotax;
 $ecotax_rate = (float)Tax::getProductEcotaxRate($this->context->cart->{Configuration::get('PS_TAX_ADDRESS_TYPE')});
 $ecotax_tax_amount = Tools::ps_round($this->product->ecotax, 2);
 if (Product::$_taxCalculationMethod == PS_TAX_INC && (int)Configuration::get('PS_TAX'))
  $ecotax_tax_amount = Tools::ps_round($ecotax_tax_amount * (1 + $ecotax_rate / 100), 2);
 $id_currency = (int)$this->context->cookie->id_currency;
 $id_product = (int)$this->product->id;
 $id_shop = $this->context->shop->id;
 $quantity_discounts = SpecificPrice::getQuantityDiscounts($id_product, $id_shop, $id_currency, $id_country, $id_group, null, true);
 foreach ($quantity_discounts as &$quantity_discount)
  if ($quantity_discount['id_product_attribute'])
  {
$combination = new Combination((int)$quantity_discount['id_product_attribute']);
$attributes = $combination->getAttributesName((int)$this->context->language->id);
foreach ($attributes as $attribute)
 $quantity_discount['attributes'] = $attribute['name'].' - ';
$quantity_discount['attributes'] = rtrim($quantity_discount['attributes'], ' - ');
  }
 $product_price = $this->product->getPrice(Product::$_taxCalculationMethod == PS_TAX_INC, false);
 $address = new Address($this->context->cart->{Configuration::get('PS_TAX_ADDRESS_TYPE')});
 $this->context->smarty->assign(array(
  'quantity_discounts' => $this->formatQuantityDiscounts($quantity_discounts, $product_price, (float)$tax),
  'ecotax_tax_inc' => $ecotax_tax_amount,
  'ecotax_tax_exc' => Tools::ps_round($this->product->ecotax, 2),
  'ecotaxTax_rate' => $ecotax_rate,
  'productPriceWithoutEcoTax' => (float)$product_price_without_eco_tax,
  'group_reduction' => (1 - $group_reduction),
  'no_tax' => Tax::excludeTaxeOption() || !$this->product->getTaxesRate($address),
  'ecotax' => (!count($this->errors) && $this->product->ecotax > 0 ? Tools::convertPrice((float)$this->product->ecotax) : 0),
  'tax_enabled' => Configuration::get('PS_TAX'),
  'digsale'=>$price_goods,
'digsalewmu'=>$wmu,
'digsalepcr'=>$pcr,
'digsalereward'=>$reward,
'digsalearew'=>$arew,
'digsalearewc'=>$arewc,
 ));

 

A variable {$digsalewmu} works fine on product page. But I need to put it in product-list. tpl also.

The main problem is that this variable is formed with a help of an xml request wich uses productcontroller variable ($this->product->reference) so I can't move it to another controller, categorycontroller, for example.

 

Could anyone please share an advice how to solve this?

 

Thanks!

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...