View Single Post
  #1  
Old 08-19-2014, 08:42 AM
  totaltec's Avatar 
totaltec totaltec is offline
 

X-Guru
  
Join Date: Jan 2007
Location: Louisville, KY USA
Posts: 5,823
 

Default 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.
__________________
Mike White - Now Accepting new clients and projects! Work with the best, get a US based development team for just $125 an hour. Call 1-502-773-6454, email mike at babymonkeystudios.com, or skype b8bym0nkey

XcartGuru
X-cart Tutorials | X-cart 5 Tutorials

Check out the responsive template for X-cart.
Reply With Quote