VirtueMart Forum

VirtueMart 2 + 3 + 4 => Virtuemart Development and bug reports => Topic started by: acooper on June 01, 2019, 08:19:55 AM

Title: parts of [product_attribute]
Post by: acooper on June 01, 2019, 08:19:55 AM
I need get parts of [product_attribute]
Of this attribute, I just need visible the (deliverydate) and (enddate)

[product_attribute] => { "102": { "10119": { "type": "rent", "deliverydate": "28\/06\/2019", "enddate": "30\/06\/2019" } } } [order_status] => F [intnotes] => [virtuemart_category_id] => 2 [virtuemart_manufacturer_id] => Array (
Title: Re: parts of [product_attribute]
Post by: Jörgen on June 01, 2019, 09:16:43 AM
Use php function json_decode to get Your attributes.

Jörgen @ Kreativ Fotografi
Title: Re: parts of [product_attribute]
Post by: acooper on June 01, 2019, 15:15:11 PM
Hi, sorry, got it not.
I can take the values that way;


Alugando por 3 Dia(s), de 25/05/2019 até 27/05/2019: R$ 15,00 (I do not need to bring the value)

---
foreach($this->orderDetails['items'] as $item) {
            $product_attribute = VirtueMartModelCustomfields::CustomsFieldOrderDisplay($item,'FE');
            echo $product_attribute;}
Title: Re: parts of [product_attribute]
Post by: Studio 42 on June 01, 2019, 15:23:08 PM
You need to write your own plugin "rent", so you can customize the display in order, cart, product details... and more
Title: Re: parts of [product_attribute]
Post by: acooper on June 01, 2019, 17:28:31 PM
I already have this plugin
Title: Re: parts of [product_attribute]
Post by: Studio 42 on June 02, 2019, 00:39:50 AM
Depending the view, you have this functions in your plugin to modify
   function plgVmOnViewCartVM3(&$product, &$group, &$html) {
   }

   function plgVmOnViewCartModuleVM3( &$product, &$group, &$html) {
   }

   function plgVmDisplayInOrderBEVM3( &$product, &$group, &$html) {
   }

   function plgVmDisplayInOrderFEVM3(&$product, &$group, &$html) {
   }
Title: Re: parts of [product_attribute]
Post by: acooper on June 02, 2019, 05:06:54 AM
Yes, have all

--
   function plgVmOnViewCartModuleVM3(&$product, &$pc, &$html) {
      if (empty($pc->custom_element) or $pc->custom_element != $this->_name) return false;
      if (empty($product->customProductData[$pc->virtuemart_custom_id][$pc->virtuemart_customfield_id])) return false;
      $this->parseRentCustomParams($pc);
      $items = $product->customProductData[$pc->virtuemart_custom_id];
      foreach ($items as $k =>$item) {
         if($pc->virtuemart_customfield_id == $k and JArrayHelper :: getValue($item, 'type') != 'purchase'
          and $deliverydate = $this->decodeDate(JArrayHelper :: getValue($item, 'deliverydate'), $pc)
           and $enddate = $this->decodeDate(JArrayHelper :: getValue($item, 'enddate'), $pc)) {
            $this->_loadLanguageFile();
            $rent_days = floor((strtotime($enddate) - strtotime($deliverydate))/86400) + 1;
            if ($rent_days > 0) {
               $html .= '<div>';
               $html .= JText :: sprintf('PLG_FWVMR_RENT_FOR_DAYS', $rent_days, $this->encodeDate($deliverydate, $pc), $this->encodeDate($enddate, $pc));
               $html .= '</div>';
            }
         }
      }
      return true;
   }
   function plgVmOnViewCartVM3(&$product, &$pc, &$html) {
      if (empty($pc->custom_element) or $pc->custom_element != $this->_name) return false;
      if (empty($product->customProductData[$pc->virtuemart_custom_id][$pc->virtuemart_customfield_id])) return false;
      $this->parseRentCustomParams($pc);
      $items = $product->customProductData[$pc->virtuemart_custom_id];
      foreach ($items as $k =>$item ) {
         if ($pc->virtuemart_customfield_id == $k and JArrayHelper :: getValue($item, 'type') != 'purchase'
          and $deliverydate = $this->decodeDate(JArrayHelper :: getValue($item, 'deliverydate'), $pc)
           and $enddate = $this->decodeDate(JArrayHelper :: getValue($item, 'enddate'), $pc)) {

            $this->_loadLanguageFile();
            require_once(JPATH_ADMINISTRATOR.'/components/com_virtuemart/helpers/currencydisplay.php');
            $currency = CurrencyDisplay::getInstance();

            $rent_days = floor((strtotime($enddate) - strtotime($deliverydate))/86400) + 1;
            $per_period = (!empty($pc->price_per) and $pc->price_per == 'period');
            if (!empty($pc->count_first_day)) {
               $rent_days--;
            }

            if ($rent_days > 0) {
               $price = 0;
               if (!empty($pc->rent_sizes)) foreach ($pc->rent_sizes as $i => $rent) {
                  if (!empty($rent->rent_show) and $rent_days >= $rent->rent_start and $rent_days <= $rent->rent_end) {
                     if ($per_period) {
                        $price = $rent->rent_product_price;
                     } else {
                        $price = $rent->rent_product_price * $rent_days;
                     }
                     break;
                  }
               }
               $html .= JText :: sprintf('PLG_FWVMR_RENT_FOR_DAYS', $rent_days, $this->encodeDate($deliverydate, $pc), $this->encodeDate($enddate, $pc)).': '.$currency->getSymbol().' '.number_format($price * $product->quantity, 2, ",", ".").'<br/>';
               if ($pc->rent_product_deposit > 0) $html .= JText :: sprintf('PLG_FWVMR_INCLUDING_DEPOSIT').': '.$currency->getSymbol().' '.number_format($pc->rent_product_deposit * $product->quantity, 2, ",", ".").'<br/>';
               if (JArrayHelper :: getValue($item, 'insurance_option')) $html .= JText :: sprintf('PLG_FWVMR_INCLUDING_INSURANCE').': '.$currency->getSymbol().' '.number_format($pc->rent_product_insurance * $product->quantity, 2, ",", ".");
            }
         }
      }
      return true;
   }
   function plgVmDisplayInOrderBEVM3( &$product, &$pc, &$html) {
      $this->plgVmDisplayInOrderFEVM3($product,$pc,$html);
    }
   function plgVmDisplayInOrderFEVM3( &$product, &$pc, &$html) {
      if (empty($pc->custom_element) or $pc->custom_element != $this->_name) return false;
      if (empty($product->customProductData[$pc->virtuemart_custom_id][$pc->virtuemart_customfield_id])) return false;
      $this->parseRentCustomParams($pc);
      $items = $product->customProductData[$pc->virtuemart_custom_id];
      foreach ($items as $k =>$item ) {
         if($pc->virtuemart_customfield_id == $k and JArrayHelper :: getValue($item, 'type') != 'purchase'
          and $deliverydate = $this->decodeDate(JArrayHelper :: getValue($item, 'deliverydate'), $pc)
           and $enddate = $this->decodeDate(JArrayHelper :: getValue($item, 'enddate'), $pc)) {

            $this->_loadLanguageFile();
            require_once(JPATH_ADMINISTRATOR.'/components/com_virtuemart/helpers/currencydisplay.php');
            $currency = CurrencyDisplay::getInstance();

            $rent_days = floor((strtotime($enddate) - strtotime($deliverydate))/86400) + 1;

            if ($rent_days > 0) {
               $price = $product->product_item_price - (($pc->rent_product_deposit > 0)?$pc->rent_product_deposit:0) - (JArrayHelper :: getValue($item, 'insurance_option')?$pc->rent_product_insurance:0);

               $html .= JText :: sprintf('PLG_FWVMR_RENT_FOR_DAYS', $rent_days, $this->encodeDate($deliverydate, $pc), $this->encodeDate($enddate, $pc)).': '.$currency->getSymbol().' '.number_format($price * $product->product_quantity, 2, ",", ".").'<br/>';
               if ($pc->rent_product_deposit > 0) $html .= JText :: sprintf('PLG_FWVMR_INCLUDING_DEPOSIT').': '.$currency->getSymbol().' '.number_format($pc->rent_product_deposit * $product->product_quantity, 2, ",", ".").'<br/>';
               if (JArrayHelper :: getValue($item, 'insurance_option')) $html .= JText :: sprintf('PLG_FWVMR_INCLUDING_INSURANCE').': '.$currency->getSymbol().' '.number_format($pc->rent_product_insurance * $product->product_quantity, 2, ",", ".");
            }
         }
      }
      return true;
    }
Title: Re: parts of [product_attribute]
Post by: Studio 42 on June 02, 2019, 14:45:28 PM
The code already extract it and display it formated.
So check the right function and modify the render
$html return the display inside the order and cart