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

Add to Cart Button for Out of Stock

 
Reply
   X-Cart forums > X-Cart 5 > Dev Questions (X-Cart 5)
 
Thread Tools Search this Thread
  #1  
Old 08-31-2016, 09:39 AM
 
RexxBattery RexxBattery is offline
 

Member
  
Join Date: Aug 2016
Posts: 13
 

Default Add to Cart Button for Out of Stock

We are looking to make a "Special Order" button (add to cart) for out of stock items. Any direction to get this going?
Thank you
__________________
5.2.16
Cloud Search
Market Price
Volume Discounts
Reply With Quote
  #2  
Old 08-31-2016, 10:06 PM
  qualiteam's Avatar 
qualiteam qualiteam is offline
 

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

Default Re: Add to Cart Button for Out of Stock

What will that button do?
__________________
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-01-2016, 05:55 AM
 
RexxBattery RexxBattery is offline
 

Member
  
Join Date: Aug 2016
Posts: 13
 

Default Re: Add to Cart Button for Out of Stock

It will add the item to the cart. Potentially also pop up with a message clarifying to the customer that it will be a special order.
__________________
5.2.16
Cloud Search
Market Price
Volume Discounts
Reply With Quote
  #4  
Old 09-04-2016, 08:25 PM
  qualiteam's Avatar 
qualiteam qualiteam is offline
 

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

Default Re: Add to Cart Button for Out of Stock

The widget that displays the button on the product page and in the Quick Look popup is this one:
\XLite\View\Product\Details\Customer\AddButton

You can alter it as follows:

1. Create a custom template in your module (skins/default/en/modules/[YOUR_DEV_ID]/[YOUR_MODULE_ID]/product/add_button/body.tpl) with the following code (it is a slightly tweaked copy of the code from the skins/default/en/product/add_button/body.tpl file):
Code:
<div class="add-button-wrapper {getFingerprint()}"> <widget IF="!isOutOfStock()" class="\XLite\View\Button\Submit" label="{getButtonLabel()}" style="regular-main-button add2cart" /> </div>

2. Decorate the widget as follows:
PHP Code:
<?php
class AddButton extends \XLite\View\Product\Details\Customer\AddButton implements \XLite\Base\IDecorator
{
    protected function 
getButtonLabel()
    {
        return 
$this->isSpecialOrderButton() ? 'Special order' 'Add to cart';
    }

    protected function 
isSpecialOrderButton()
    {
        
$product $this->getProduct();
        
$result = ...place there your check against the product...

        return 
$result;
    }
}

You need also a way to configure which products are regular ones, and which should display the custom button label. Depending on this you should adjust the above text.

As for the popup message: do you mean the message that appears at the top of the page? If so, you should look into decorating the \XLite\Controller\Customer\Cart::doActionAdd() and other methods that it calls.

As you see this may require changing a number of files, so you may be better to hire someone who could code this for you.
__________________
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

The following user thanks qualiteam for this useful post:
RexxBattery (09-08-2016)
  #5  
Old 09-07-2016, 07:25 AM
 
RexxBattery RexxBattery is offline
 

Member
  
Join Date: Aug 2016
Posts: 13
 

Default Re: Add to Cart Button for Out of Stock

i just mean a simple message box that pops up, not the message at the top of the page. I assume that wouldn't be difficult at all. Thank you for your help, I'll see if I come up with any new questions.
__________________
5.2.16
Cloud Search
Market Price
Volume Discounts
Reply With Quote
  #6  
Old 09-08-2016, 08:01 AM
 
RexxBattery RexxBattery is offline
 

Member
  
Join Date: Aug 2016
Posts: 13
 

Default Re: Add to Cart Button for Out of Stock

What specifically determines whether or not the button displays? I can get it to decide what the button label is, but that doesn't help if the button does not show on out of stock products.
__________________
5.2.16
Cloud Search
Market Price
Volume Discounts
Reply With Quote
  #7  
Old 09-12-2016, 01:38 AM
  qualiteam's Avatar 
qualiteam qualiteam is offline
 

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

Default Re: Add to Cart Button for Out of Stock

I believe it is the isVisible() method. However, you may also need to look into \XLite\Module\QSL\CallForPrice\View\ProductPageCol lection::getWidgetsCollection() as this method determines which widgets appear on the product page depending on different checks.
__________________
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
  #8  
Old 09-12-2016, 01:43 PM
 
RexxBattery RexxBattery is offline
 

Member
  
Join Date: Aug 2016
Posts: 13
 

Default Re: Add to Cart Button for Out of Stock

i ended up changing a function in Model/Product.php to look like this:

Code:
public function isPublicAvailable() { return $this->isVisible() && $this->availableInDate(); //&& !$this->isOutOfStock(); }

I had to alter a few other files to allow the item to actually be added to the cart though. the file you mentioned must be for a different version, as it does not exist.


Where is the location of what the add to cart button actually does?
__________________
5.2.16
Cloud Search
Market Price
Volume Discounts
Reply With Quote
  #9  
Old 09-13-2016, 07:03 AM
  qualiteam's Avatar 
qualiteam qualiteam is offline
 

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

Default Re: Add to Cart Button for Out of Stock

You're right. I copied it from a wrong file. The right method is \XLite\View\ProductPageCollection::getWidgetsColle ction().

Quote:
Where is the location of what the add to cart button actually does?

It submites the form with "target" = "cart" and "action" = "add". So, you should look into the \XLite\Controller\Cart::doActionAdd() method.
__________________
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
  #10  
Old 09-13-2016, 01:09 PM
 
RexxBattery RexxBattery is offline
 

Member
  
Join Date: Aug 2016
Posts: 13
 

Default Re: Add to Cart Button for Out of Stock

Quote:
Originally Posted by qualiteam
It submites the form with "target" = "cart" and "action" = "add". So, you should look into the \XLite\Controller\Cart::doActionAdd() method.

Thank you, I ended up finding this not long after asking. What initializes doActionAdd()? I can't seem to get this popup code to work when the button is clicked.
Code:
echo '<script type="text/javascript">alert("hello!");</script>';
__________________
5.2.16
Cloud Search
Market Price
Volume Discounts
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 03:15 PM.

   

 
X-Cart forums © 2001-2020