News:

You may pay someone to create your store, or you visit our seminar and become a professional yourself with the silver certification

Main Menu

override custom field price or product price in productlink

Started by Micha70, December 20, 2016, 00:45:49 AM

Previous topic - Next topic

Micha70

Hello,

i have a temporary product with a custom field. The default value in the custom field i have set to "cartPrices['salesPrice']=".

With a link i must add the product in cart. Bevor addtocart i need to override the price/custom field price.

I can add the product in cart but without an overridden price:

index.php?option=com_virtuemart&view=cart&virtuemart_product_id[0]=61&virtuemart_category_id[0]=16
&quantity[0]=1&product_priceWithoutTax[0]=1.20&task=add

The product with the static custom field price i can add too. But not override the price:

index.php?option=com_virtuemart&view=cart&virtuemart_product_id[0]=61&virtuemart_category_id[0]=16&quantity[0]=1&task=add&customProductData[61][31][244][comment]=TestText&field[0][customfield_price][0]=1.20

How can i override the price bevor in cart, with a link like above links ?

regards

Studio 42

If you need to change price, you need to use a customfield plugin.
eg &customProductData[61][31][244][comment]=TestText is for text input comment data
&customProductData[61][custom_id][customfield_id][myprice]=1.2
where
custom_id is the customfield id.
customfield_id is the product customfield id
and myprice your value to convert as price

Micha70

I have change the default value of my customfield plugin to 'textinput'.

In the product the custom field code is the followed:

<b>Plugins</b> plg textinput price</span><br/>

<span class="vmicon vmicon-16-default"></span><span class="vmicon vmicon-16-move"></span>
<span class="vmicon vmicon-16-remove 4remove"></span>

<input type="hidden" value="E" name="field[0][field_type]" />
<input type="hidden" value="textinput" name="field[0][custom_element]" />
<input type="hidden" value="10046" name="field[0][custom_jplugin_id]" />
<input type="hidden" value="27" name="field[0][virtuemart_custom_id]" />
<input type="hidden" value="61" name="field[0][virtuemart_product_id]" />
<input type="hidden" value="239" name="field[0][virtuemart_customfield_id]" />
<input class="ordering" type="hidden" value="0" name="field[0][ordering]" /></td>

<td >
<input type="hidden" value="textinput" name="field[0][customfield_value]" /><span style="white-space: nowrap;">
<input type="text" size="12" style="text-align:right;" value="0.000000" name="field[0][customfield_price]" /> €</span>
</td>




My Link is this:
index.php?option=com_virtuemart&view=cart&virtuemart_product_id[0]=61&virtuemart_category_id[0]=16&quantity[0]=1&task=add
&customProductData[61][27][239][comment]=TestText
&customProductData[61][27][239][discountedPriceWithoutTax]=1.20

The product price is 0.01. But when i call the link nothing will happens. Only the product with the comment is showing in cart. With the old price 0.01.


Micha70

In my cart override file default_pricelist.php i have insert this code to check my product:



if( $prow->virtuemart_product_id == 61)
{
$prow->prices['discountedPriceWithoutTax'] = $_POST['discountedPriceWithoutTax'];

echo $this->currencyDisplay->createPriceDiv ('discountedPriceWithoutTax', '', $prow->prices, FALSE, FALSE, 1.0, false, true);
}



With task=recalculate the price is written in the customfield array (
index.php?option=com_virtuemart&view=cart&virtuemart_product_id[0]=61&virtuemart_category_id[0]=16&quantity[0]=1&task=add&customProductData[61][27][239][comment]=TestText&customProductData[61][27][239][discountedPriceWithoutTax]=1.20&task=recalculate ).
But the cartPrice is not overriden.
And in the array [prices] is no discountedPriceWithoutTax.



                    [customfields] => Array
                        (
                            [0] => stdClass Object
                                (
                                    [virtuemart_custom_id] => 27
                                    [custom_parent_id] => 0
                                    [virtuemart_vendor_id] => 1
   ...
[modificatorSum] => 0
                    [customProductData] => Array
                        (
                            [27] => Array
                                (
                                    [239] => Array
                                        (
                                            [comment] => TestText
                                            [discountedPriceWithoutTax] => 1.20
                                        )

                                )

   ...

    [cartProductsData] => Array
        (
            [0] => Array
                (
                    [virtuemart_product_id] => 61
                    [quantity] => 1
                    [customProductData] => Array
                        (
                            [27] => Array
                                (
                                    [239] => Array
                                        (
                                            [comment] => TestText
                                            [discountedPriceWithoutTax] => 1.20
                                        )

                                )

                        )
   ...

    [cartPrices] => Array
        (
            [basePrice] => 0.01
            [basePriceWithTax] => 0.0119
            [discountedPriceWithoutTax] => 0.01
            [salesPrice] => 0.0119
            [taxAmount] => 0.0019
            [salesPriceWithDiscount] => 0
            [discountAmount] => 0
            [priceWithoutTax] => 0.01
            [subTotalProducts] => 0
            [billTotal] => 0.0119
            [1Diff] => -0.0019
            [0] => Array
                (
                    [virtuemart_product_price_id] => 80
                    [virtuemart_product_id] => 61
                    [virtuemart_shoppergroup_id] => 0
                    [product_price] => 0.01
                    [override] => 0
                    [product_override_price] => 0
                    [product_tax_id] => 1
                    [product_discount_id] => 0
                    [product_currency] => 47
                    [product_price_publish_up] => 0000-00-00 00:00:00
                    [product_price_publish_down] => 0000-00-00 00:00:00
                    [price_quantity_start] => 0
                    [price_quantity_end] => 0
                    [created_on] => 2016-12-29 23:20:31
                    [created_by] => 119
                    [modified_on] => 2016-12-29 23:20:31
                    [modified_by] => 119
                    [locked_on] => 0000-00-00 00:00:00
                    [locked_by] => 0
                    [costPrice] => 0.01
                    [basePrice] => 0.01
                    [basePriceVariant] => 0.01
                    [basePriceWithTax] => 0.0119
                    [discountedPriceWithoutTax] => 0.01
                    [priceBeforeTax] => 0.01
                    [salesPrice] => 0.0119
                    [taxAmount] => 0.0019
                    [salesPriceWithDiscount] => 0
                    [salesPriceTemp] => 0.0119
                    [unitPrice] => 0
                    [priceWithoutTax] => 0.01
                    [discountAmount] => -0
                    [variantModification] => 0

     ...

[prices] => Array
                        (
                            [virtuemart_product_price_id] => 80
                            [virtuemart_product_id] => 61
                            [virtuemart_shoppergroup_id] => 0
                            [product_price] => 0.01
                            [override] => 0
                            [product_override_price] => 0
                            [product_tax_id] => 1
                            [product_discount_id] => 0
                            [product_currency] => 47
                            [product_price_publish_up] => 0000-00-00 00:00:00
                            [product_price_publish_down] => 0000-00-00 00:00:00
                            [price_quantity_start] => 0
                            [price_quantity_end] => 0
                            [created_on] => 2016-12-29 23:20:31
                            [created_by] => 119
                            [modified_on] => 2016-12-29 23:20:31
                            [modified_by] => 119
                            [locked_on] => 0000-00-00 00:00:00
                            [locked_by] => 0
                            [costPrice] => 0.01
                            [basePrice] => 0.01
                            [basePriceVariant] => 0.01
                            [basePriceWithTax] => 0.0119
                            [discountedPriceWithoutTax] =>
                            [priceBeforeTax] => 0.01
                            [salesPrice] => 0.0119
                            [taxAmount] => 0.0019
                            [salesPriceWithDiscount] => 0
                            [salesPriceTemp] => 0.0119
                            [unitPrice] => 0
                            [priceWithoutTax] => 0.01
                            [discountAmount] => -0
                            [variantModification] => 0





Studio 42

You have to modify your textinput plugin, to do this.
But it's not safe, any user can change the price.
Check file JOOMLAROOT\plugins\vmcustom\textinput\textinput.php the code inside
public function plgVmPrepareCartProduct

for your case, if you always have a fixed value
replace:
if (!empty($selected['comment'])) {
if ($customfield->custom_price_by_letter ==1) {
$charcount = strlen (html_entity_decode ($selected['comment']));
} else {
$charcount = 1.0;
}
$modificatorSum += $charcount * $customfield->customfield_price ;
} else {
$modificatorSum += 0.0;
}

with
if (!empty($selected['comment'])) {

$modificatorSum += $customfield->customfield_price ;
}


so you have 1.2 added if you change customfield price to 1.2 in the product

Micha70

That's work very fine so far. The discountedPriceWithoutTax it is written in all prices fields in the cart array.
And the product link is not longer show in the page source code.

Unfortunately it gives me not an overriden price, the customfield_price fieldhas the custom textplugin price 0.00000 in it.



[allPrices] => Array
(
[0] => Array
(
[virtuemart_product_price_id] => 80
[virtuemart_product_id] => 61
[virtuemart_shoppergroup_id] => 0
[product_price] => 0.01
[override] => 0
[product_override_price] => 0
[product_tax_id] => 0
[product_discount_id] => 0
[product_currency] => 47
[product_price_publish_up] => 0000-00-00 00:00:00
[product_price_publish_down] => 0000-00-00 00:00:00
[price_quantity_start] => 0
[price_quantity_end] => 0
[created_on] => 2016-12-29 23:20:31
[created_by] => 119
[modified_on] => 2016-12-31 00:34:21
[modified_by] => 119
[locked_on] => 0000-00-00 00:00:00
[locked_by] => 0
[costPrice] => 0.01
[basePrice] => 0.01
[basePriceVariant] => 0.01
[basePriceWithTax] => 0.01
[discountedPriceWithoutTax] => 0.01
[priceBeforeTax] => 0.01
[salesPrice] => 0.01
[taxAmount] => 0
[salesPriceWithDiscount] => 0
[salesPriceTemp] => 0.01
[unitPrice] => 0
[priceWithoutTax] => 0.01
[discountAmount] => -0
[variantModification] => 0

...

[customfields] => Array
                        (
                            [0] => stdClass Object
                                (
                                    [virtuemart_custom_id] => 27
                                    [custom_parent_id] => 0
                                    [virtuemart_vendor_id] => 1
                                    [custom_jplugin_id] => 10046
                                    [custom_element] => textinput
                                    [admin_only] => 0
                                    [custom_title] => plg textinput price
                                    [show_title] => 1
                                    [custom_tip] =>
                                    [custom_value] =>
                                    [custom_desc] =>
                                    [field_type] => E
                                    [is_list] => 0
                                    [is_hidden] => 0
                                    [is_cart_attribute] => 1
                                    [is_input] => 1
                                    [layout_pos] => addtocart
                                    [custom_params] => custom_size="40"|custom_price_by_letter="0"|
                                    [shared] => 0
                                    [published] => 1
                                    [ordering] => 0
                                    [virtuemart_customfield_id] => 239
                                    [virtuemart_product_id] => 61
                                    [customfield_value] => textinput
                                    [customfield_price] => 0.000000
                                    [customfield_params] => custom_size="40"|custom_price_by_letter="0"|
                                    [fpublished] => 0
                                    [override] => 0
                                    [disabler] => 0




I have changed the code in textinput.php and hardcoded the price for tests. That works and the product price in cart
will display with 2.2222, respectively 2.23. The field modificatorSum has this price and show it me in cart. But i can it not override
with a variable form for my link.

Textinput.php:



public function plgVmPrepareCartProduct(&$product, &$customfield,$selected,&$modificatorSum){

if ($customfield->custom_element !==$this->_name) return ;

  if (!empty($selected['comment']))
  {
  $customfield->customfield_price = '2.2222'; 
  $modificatorSum += $customfield->customfield_price ;
// $customfield->product_price_override = 1;
  //$customfield->override = 1;
  //$charcount = 1.0;
  }


return true;
}




The cart array:
The customfields '[customfield_price]' has the hardcoded price 2.2222:


[allPrices] => Array
(
[0] => Array
(
[virtuemart_product_price_id] => 80
[virtuemart_product_id] => 61
[virtuemart_shoppergroup_id] => 0
[product_price] => 0.01
[override] => 0
[product_override_price] => 0
[product_tax_id] => 0
[product_discount_id] => 0
[product_currency] => 47
[product_price_publish_up] => 0000-00-00 00:00:00
[product_price_publish_down] => 0000-00-00 00:00:00
[price_quantity_start] => 0
[price_quantity_end] => 0
[created_on] => 2016-12-29 23:20:31
[created_by] => 119
[modified_on] => 2016-12-31 00:34:21
[modified_by] => 119
[locked_on] => 0000-00-00 00:00:00
[locked_by] => 0
[costPrice] => 0.01
[basePrice] => 2.2322
[basePriceVariant] => 2.2322
[basePriceWithTax] => 2.2322
[discountedPriceWithoutTax] => 2.2322
[priceBeforeTax] => 2.2322
[salesPrice] => 2.2322
[taxAmount] => 0
[salesPriceWithDiscount] => 0
[salesPriceTemp] => 2.2322
[unitPrice] => 0
[priceWithoutTax] => 2.2322
[discountAmount] => -0
[variantModification] => 2.2222

...

[cartProductsData] => Array
(
[0] => Array
(
[virtuemart_product_id] => 61
[quantity] => 1
[customProductData] => Array
(
[27] => Array
(
[239] => Array
(
[comment] => TestText
[discountedPriceWithoutTax] => 1.2


...

[cartPrices] => Array
(
[basePrice] => 2.2322
[basePriceWithTax] => 2.2322
[discountedPriceWithoutTax] => 2.2322
[salesPrice] => 2.2322
[taxAmount] => 0
[salesPriceWithDiscount] => 0
[discountAmount] => 0
[priceWithoutTax] => 2.2322
[subTotalProducts] => 0
[billTotal] => 2.2322
[7Diff] => 0
[0] => Array
(
[virtuemart_product_price_id] => 80
[virtuemart_product_id] => 61
[virtuemart_shoppergroup_id] => 0
[product_price] => 0.01
[override] => 0
[product_override_price] => 0
[product_tax_id] => 0
[product_discount_id] => 0
[product_currency] => 47
[product_price_publish_up] => 0000-00-00 00:00:00
[product_price_publish_down] => 0000-00-00 00:00:00
[price_quantity_start] => 0
[price_quantity_end] => 0
[created_on] => 2016-12-29 23:20:31
[created_by] => 119
[modified_on] => 2016-12-31 00:34:21
[modified_by] => 119
[locked_on] => 0000-00-00 00:00:00
[locked_by] => 0
[costPrice] => 0.01
[basePrice] => 2.2322
[basePriceVariant] => 2.2322
[basePriceWithTax] => 2.2322
[discountedPriceWithoutTax] => 2.2322
[priceBeforeTax] => 2.2322
[salesPrice] => 2.2322
[taxAmount] => 0
[salesPriceWithDiscount] => 0
[salesPriceTemp] => 2.2322
[unitPrice] => 0
[priceWithoutTax] => 2.2322
[discountAmount] => -0
[variantModification] => 2.2222

...

[customfields] => Array
(
[0] => stdClass Object
(
[virtuemart_custom_id] => 27
[custom_parent_id] => 0
[virtuemart_vendor_id] => 1
[custom_jplugin_id] => 10046
[custom_element] => textinput
[admin_only] => 0
[custom_title] => plg textinput price
[show_title] => 1
[custom_tip] =>
[custom_value] =>
[custom_desc] =>
[field_type] => E
[is_list] => 0
[is_hidden] => 0
[is_cart_attribute] => 1
[is_input] => 1
[layout_pos] => addtocart
[custom_params] => custom_size="40"|custom_price_by_letter="0"|
[shared] => 0
[published] => 1
[ordering] => 0
[virtuemart_customfield_id] => 239
[virtuemart_product_id] => 61
[customfield_value] => textinput
[customfield_price] => 2.2222
[customfield_params] => custom_size="40"|custom_price_by_letter="0"|
[fpublished] => 0
[override] => 0
[disabler] => 0
[_varsToPushParam] => Array
(
[custom_size] => Array
(
[0] => 0
[1] => int
)

[custom_price_by_letter] => Array
(
[0] => 0
[1] => bool
)

)

[_varsToPushParamCustom] => Array
(
[custom_size] => Array
(
[0] => 0
[1] => int
)

[custom_price_by_letter] => Array
(
[0] => 0
[1] => bool
)

)

[_varsToPushParamCustomField] => Array
(
[custom_size] => Array
(
[0] => 0
[1] => int
)

[custom_price_by_letter] => Array
(
[0] => 0
[1] => bool
)

)

[custom_size] => 40
[custom_price_by_letter] => 0
[_xParams] => customfield_params
)

)

[modificatorSum] => 2.2222
[customProductData] => Array
(
[27] => Array
(
[239] => Array
(
[comment] => TestText
[discountedPriceWithoutTax] => 1.2
)

)

)







The call customfield_price=1.2 with the link

index.php?option=com_virtuemart&view=cart&virtuemart_product_id[0]=61&virtuemart_category_id[0]=16&quantity[0]=1&task=add&
customProductData[61][27][239][comment]=TestText&customProductData[61][27][239][customfield_price=1.2

write  me the price in the customProductData array. But not in the field customfields->customfield_price:





[customfields] => Array
(
[0] => stdClass Object
(
[virtuemart_custom_id] => 27
[custom_parent_id] => 0
[virtuemart_vendor_id] => 1
[custom_jplugin_id] => 10046
[custom_element] => textinput
[admin_only] => 0
[custom_title] => plg textinput price
[show_title] => 1
[custom_tip] =>
[custom_value] =>
[custom_desc] =>
[field_type] => E
[is_list] => 0
[is_hidden] => 0
[is_cart_attribute] => 1
[is_input] => 1
[layout_pos] => addtocart
[custom_params] => custom_size="40"|custom_price_by_letter="0"|
[shared] => 0
[published] => 1
[ordering] => 0
[virtuemart_customfield_id] => 239
[virtuemart_product_id] => 61
[customfield_value] => textinput
[customfield_price] => 0.000000

...


[customProductData] => Array
(
[27] => Array
(
[239] => Array
(
[comment] => TestText
[customfield_price] => 1.2
)

)

)
...






When i change the textinput code to:

$customfield->customfield_price = $products->cartProductsData['discountedPriceWithoutTax'];

or

$customfield->customfield_price = $cart->customProductData['discountedPriceWithoutTax'];

The customfield_price is empty.




Studio 42

Why you want overide the price and not use this method?
It's not safe to add the price directly in the link, because any customer can manipulate it.
So you need to modify the code in plgVmPrepareCartProduct and not add it in the link.
If you need to modify original price, this is in the $product objectin same function plgVmPrepareCartProduct .

If you need to display it, then you need to modify function plgVmOnViewCartVM3


Micha70

Thank you so much. With the product object in the form of $customfield->customfield_price = $selected['my_price']
respectively with $product->selectedPrice]['product_tax_id'] now still solve.
The link seems to be nowhere to be seen from outside. Only the canonical 'index.php?option=com_virtuemart&view=cart&lang= ' is visible.
That should be safe so far.

If nothing speaks against it, I set the status to resolved.

best regards,
Michael

Micha70


A question I still have to overrides. Is there an override for the textinput plugin or will be overwritten with the next update?

Studio 42

For a permanent solution, write your own plugin.
You only nee to change the class name and the file names reference using textinput as model and redo a ZIP pack and install it.

Micha70

That's great. I just had to adjust the xml structure to install it, which was something tricky
for the first time. Now the plugin works wonderfully.