X-Cart: shopping cart software

X-Cart forums (https://forum.x-cart.com/index.php)
-   Dev Questions (X-Cart 5) (https://forum.x-cart.com/forumdisplay.php?f=56)
-   -   Building a Request for Quote module (https://forum.x-cart.com/showthread.php?t=69847)

totaltec 08-19-2014 08:42 AM

Building a Request for Quote module
 
Asking a question here, hoping to expand my understanding of XC5 and OOP, and reach out to the community for help. I am developing a "Request for Quote" module for a client.

The idea behind this module is to provide a way fr customers to request a custom quote for any product. The planned functionality is as follows:
1. New attribute RFQ added to the list of attributes, and can be assigned to any product.
2. The attribute functions similar to a textarea.
3. When attribute is assigned to a product, it displays at the below the default attributes on the product page.
4. The textarea is initially hidden, with only a checkbox and the attribute name showing, for example "Request for Quote" could be the display text.
5. When this checkbox is checked the default attributes are hidden, the textarea is revealed, and the previously selected default attribute values are copied into it.
6. Now the customer can continue specifying additional options that they want in the custom quote.
7. When the box is checked the price of the product should change to $0.
8. Once added to cart, the default attributes of the product should not display in the cart or minicart, only the RFQ attribute name, and the value taken from the RFQ textarea.
9. The customer should be able to proceed with checkout with the $0 item in their cart, and customer support personnel can follow up with the quote.

I have completed steps 1-6, and still need to complete 7-9. Currently I am attempting to work on #8.

I have a function that checks if the current product has an RFQ attribute assigned to it.

Here is a portion of my class that does this:
Code:

namespace XLite\Module\Baby\RFQ\View\Product\Details\Customer;

/**
 * Product attribute values
 */
class AttributesModify extends \XLite\View\Product\Details\Customer\AttributesModify implements \XLite\Base\IDecorator
{
    /**
    * Check if product has an RFQ attribute
    *
    * @param array $attributes Attributes
    *
    * @return boolean
    */
    protected function isRFQ()
    {
        $attributeslist = $this->getRFQAttribute();
        $foundRFQ = false;
        $product = $this->getProduct();
        if ($product && !\XLite::isAdminZone()) {
            foreach ($attributeslist as $i => $attribute) {
                $value = $attribute->getAttributeValue($product);
                if (
                    $value
                    && $value instanceOf \XLite\Module\Baby\RFQ\Model\AttributeValue\AttributeValueRFQ
                ) {
                    $foundRFQ = true;
                }
            }
        }

        return $foundRFQ;
    }

Now on the cart page I would like to reuse this function and take action in a template if this attribute is related to the product. I realize it may need to be defined as public rather than protected. I am trying to affect the attribute display on the cart page as described above.

I have copied a class and a template into my module, creating:
Code:

namespace XLite\Module\Baby\RFQ\View;

/**
 * Selected product attribute values widget
 *
 */
class SelectedAttributeValues extends \XLite\View\SelectedAttributeValues implements \XLite\Base\IDecorator
{
    /**
    * Return widget default template
    *
    * @return string
    */
    protected function getDefaultTemplate()
    {
        return 'modules/Baby/RFQ/selected_attribute_values/body.tpl';
    }
}


And I have created my template file: default/en/modules/Baby/RFQ/selected_attribute_values/body.tpl

With just the same contents as the original so far:
Code:

<div class="item-attribute-values">
  <ul class="selected-attribute-values">
    {foreach:item.getSortedAttributeValues(),option}
      <li>
        <span>{option.getActualName()}:</span>
        {option.getActualValue()}{if:!optionArrayPointer=optionArraySize}, {end:}
      </li>
    {end:}
  </ul>
 
  <div IF="getParam(#source#)" class="item-change-attribute-values">
    <a href="{getChangeAttributeValuesLink()}">{t(#Change attributes#)}</a>
  </div>
</div>

I would like to put {if:isRFQ()} in the template and only display the attributes if this evaluates to false. If it is true and the RFQ textarea contains content, only the RFQ attribute name and value should display. I also need to remove the RFQ attribute from displaying at all in this list if the textarea has no value.

I am struggling with how to accomplish this. I would like to reuse the function so as not to recreate code. I also need a new function that checks if the attribute has value. Any and all solutions to the problem are welcome and much appreciated. I have sent Tony a copy of my module, anyone that wants a copy just PM me. I can't post it publicly because my client is considering selling it in the marketplace once complete.

qualiteam 08-20-2014 01:23 AM

Re: Building a Request for Quote module
 
The logic sounds too complex to me. Are you sure you need to base the RFQ logic on the Attributes feauture?

As for reusing the code: you can put the code as a public method into either a model class (something like $product->isRFQ(); ), or a new XLite\Module\Baby\RFQ\Core\... class.

tony_sologubov 08-20-2014 02:22 AM

Re: Building a Request for Quote module
 
Hi Mike!

Sorry, I cannot look into right now, because of upcoming webinar. I will get to it next week and will suggest a solution.

Tony.

tony_sologubov 08-27-2014 05:56 AM

Re: Building a Request for Quote module
 
Hi Mike!

Thanks for your patience!

Actually qualiteam is right. You need to make this method isRFQ() be available in the XLite/Model/OrderItem object, so you would be able to use it in the template similar to your default/en/modules/Baby/RFQ/selected_attribute_values/body.tpl or default skins/default/en/selected_attribute_values/body.tpl.

Also, you can define your own methods that would display the value of RFQ textarea, so you may need to decorate XLite/Model/OrderItem class and add two more methods

- isRFQ()
- getRFQValue()

Please, let me know if it makes sense and if it is any help for you.

Surely, any more questions -- just let me know.

Tony.

GreatLakesVacuum 09-30-2014 12:57 PM

Re: Building a Request for Quote module
 
Mike, did you finish this module? I would be interested in taking a look at it for our site.

totaltec 09-30-2014 06:56 PM

Re: Building a Request for Quote module
 
It is finished, and it works great. It should be released very soon. I am not releasing it, I developed it for another company that plans to sell it in the X-cart marketplace.

GreatLakesVacuum 10-01-2014 05:01 AM

Re: Building a Request for Quote module
 
Ok, thanks for the quick answer Mike.

kaduchess@yahoo.com 06-26-2015 08:06 AM

Re: Building a Request for Quote module
 
Hey Mike, Hal from NJ here..I think you'll remember me..
Do you know if this Mod was ever offered to the public yet? Thanks..

totaltec 06-27-2015 05:29 AM

Re: Building a Request for Quote module
 
Should be soon Hal. But it will be for Xcart 5. Good to hear from you man!

Noobab 01-04-2019 03:25 AM

Re: Building a Request for Quote module
 
Hi
i have a customer who would like a website that customers can add items to a basket , then request a quote .

there must be no pricing on the website at this point ,(this will be for 6 months to test the market demand ) once they are happy with the demand they want to change to eCommerce , same items just now with pricing . i dont want to redo website from scratch each time +/- 2000 items

does xcart have this avaliable

sean


All times are GMT -8. The time now is 11:51 AM.

Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.