Follow us on Twitter X-Cart on Facebook Wiki
Shopping cart software Solutions for online shops and malls
 

xcart 5 additional charge

 
Reply
   X-Cart forums > X-Cart 5 > Dev Questions (X-Cart 5)
 
Thread Tools Search this Thread
  #1  
Old 09-17-2014, 06:10 AM
  ecommweb's Avatar 
ecommweb ecommweb is offline
 

Advanced Member
  
Join Date: Nov 2008
Posts: 49
 

Default xcart 5 additional charge

Hi,

I want to make it so that if the QTY Ordered is not equal to the Size specified below, an additional charge of ё10 is added to the line total in the cart.

I have added a global attribute called "Additional Charge" as a Yes/No selection and plan to add the additional charge as a config value later

Example: product has 6 variants:
Thickness=10, Size=25
Thickness=10, Size=50
Thickness=10, Size=75
Thickness=10, Size=100
Thickness=20, Size=25
Thickness=20, Size=50



This is what I have so far:
PHP Code:
abstract class AdditionalCharge extends \XLite\Model\OrderItem implements \XLite\Base\IDecorator
{
    public function 
calculateNetSubtotal()
    {
        
$this->setItemNetPrice($this->defineNetPrice());

        
$total $this->getItemNetPrice() * $this->getAmount();
        
    
$amount $this->getVariant()
            ? 
$this->getVariant()->getAmount()
            : 
parent::getAmount();
        
        if(
$amount 25) { $total += 10; }

        return 
$total;
    }



This works and adds ё10 to the line total in the cart if the QTY ordered is not a multiple of 25.

All I need to know is how to retreive the Size of the variant selected and the product attribute "Additional Charge" in this function so that I can calculate the price correctly.


We are using xcart 5.1.3

Thanks
__________________
www.ecommweb.co.uk
Custom X-Cart design and functions
eCommerce SEO

www.hubmaster.co.uk
Combine all your eCommerce channels in your existing website admin

+44 (0)1302 325 032
Reply With Quote
  #2  
Old 09-18-2014, 10:20 PM
  qualiteam's Avatar 
qualiteam qualiteam is offline
 

X-Guru
  
Join Date: Dec 2010
Posts: 6,373
 

Default Re: xcart 5 additional charge

I believe \XLite\Model\OrderItem is not the class that you should use for adding extra charges to orders.
I would use the \XLite\Module\CDev\SalesTax\Logic\Order\Modifier class as the example as it does almost the same thing that you need (goes through products and adds an order surcharge).

Quote:
All I need to know is how to retreive the Size of the variant selected and the product attribute "Additional Charge" in this function so that I can calculate the price correctly.

\XLite\Model\OrderItem has the getVariant() method, so in your modifier you may interate over order items and compare variants against identifiers of the mentioned options. However, this requires you to hardcode these indentifiers into your module.

A better solution would be adding a new checkbox on the "Edit variants" page and checking it for every variant when iterating over order items in your modifier.
__________________
Alex Solovev,
Qualiteam

---

User manual Video tutorials X-Cart FAQ

You are welcome to press "Thanks" button
if you find this post useful

Click here to learn how to apply patches

X-Cart Extensions
Reply With Quote
  #3  
Old 09-22-2014, 07:49 AM
  ecommweb's Avatar 
ecommweb ecommweb is offline
 

Advanced Member
  
Join Date: Nov 2008
Posts: 49
 

Default Re: xcart 5 additional charge

Thanks for the reply

I would agree that adding a surcharge would be preferable and I spent some time trying to get that to work, but after copying and editing that class accordingly I just couldn't figure it out (it didn't ever apply anything).

I have found I can use this (below) to get the currently selected Variant info, but could you provide any example as to how to get all other product variants for this order item?


PHP Code:
foreach ($this->getAttributeValues() as $v) {
                
$av $v->getAttributeValue();
                if (
$av->getAttribute()->isVariable($this->getProduct())) {
                    echo 
'<br/>'.  $av->getAttribute()->getName() . ': ' $av->asString();
                }
            } 


If I can get the non-ordered variants for this product here, I can compare them with the current $amount ordered and then selectively apply the additional charge.
__________________
www.ecommweb.co.uk
Custom X-Cart design and functions
eCommerce SEO

www.hubmaster.co.uk
Combine all your eCommerce channels in your existing website admin

+44 (0)1302 325 032
Reply With Quote
  #4  
Old 09-23-2014, 10:35 PM
  qualiteam's Avatar 
qualiteam qualiteam is offline
 

X-Guru
  
Join Date: Dec 2010
Posts: 6,373
 

Default Re: xcart 5 additional charge

$product->getVariants() should work. And if you work with order items, try this $item->getProduct()->getVariants().
__________________
Alex Solovev,
Qualiteam

---

User manual Video tutorials X-Cart FAQ

You are welcome to press "Thanks" button
if you find this post useful

Click here to learn how to apply patches

X-Cart Extensions
Reply With Quote
Reply
   X-Cart forums > X-Cart 5 > Dev Questions (X-Cart 5)



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump


All times are GMT -8. The time now is 08:02 PM.

   

 
X-Cart forums © 2001-2020