<MvCOMMENT>
|
| Miva Merchant v4.x
|
| This file and the source codes contained herein are the property 
| of Miva Corporation.  Use of this file is restricted to the specific 
| terms and conditions in the License Agreement associated with this 
| file.  Distribution of this file or portions of this file for uses
| not covered by the License Agreement is not allowed without a written 
| agreement signed by an officer of Miva Corporation.
| 
| Copyright 1998-2001 Miva Corporation.  All rights reserved.
| http://www.miva.com/
|
| dBase III Database Layer
| $Source: /home/cvs/merchant/Merchant/features/usl/usl_rt.mv,v $
|
| Prefix         : MER-USL-DB-
| Next Error Code: 0    
| Next Text ID   : 0  
|
</MvCOMMENT>

<MvFUNCTION NAME = "Action_AddUpsoldProductToBasket" STANDARDOUTPUTLEVEL = "">
	<MvASSIGN NAME = "l.ok" VALUE = 1>
	<MvASSIGN NAME = "l.continue" VALUE = 1>
	
	<MvDO FILE = "{ g.Module_Library_DB }" NAME = "l.found" VALUE = "{ StoreModule_FindFirst_Type( 'SYSTEM' ) }">
	<MvWHILE EXPR = "{ l.found }">
		<MvDO FILE = "{ g.Module_Root $ Modules.d.module }" NAME = "l.result" VALUE = "{ SystemModule_Action_AddUpsoldProductToBasket() }">

		<MvIF EXPR = "{ l.result LE 0 }">
			<MvASSIGN NAME = "l.continue" VALUE = 0>

			<MvIF EXPR = "{ l.result EQ 0 }">
				<MvASSIGN NAME = "l.ok" VALUE = 0>
			</MvIF>

			<MvWHILESTOP>
		</MvIF>

		<MvDO FILE = "{ g.Module_Library_DB }" NAME = "l.found" VALUE = "{ StoreModule_FindNext_Type( 'SYSTEM' ) }">
	</MvWHILE>

	<MvIF EXPR = "{ l.continue }">
		<MvDO FILE = "{ g.Module_Feature_USL_DB }" NAME = "l.ok" VALUE = "{ Upsell_Delete_UpsellProductInBasket() }">
	</MvIF>

	<MvIF EXPR = "{ l.continue }">
		<MvDO FILE = "{ g.Module_Library_DB }" NAME = "l.ok" VALUE = "{ Product_Find_Code( g.Product_Code ) }">

		<MvIF EXPR = "{ l.ok }">
			<MvDO FILE = "{ g.Module_Feature_USL_DB }" NAME = "l.ok" VALUE = "{ Upsell_Find_Product_ID( Products.d.id ) }">
		</MvIF>

		<MvIF EXPR = "{ l.ok }">
			<MvDO FILE = "{ g.Module_Library_DB }" NAME = "l.quantity" VALUE = "{ Basket_Quantity( g.Session_ID, Products.d.id ) }">
			<MvIF EXPR = "{ l.quantity EQ 0 }">
				<MvASSIGN NAME = "l.missing" VALUE = 0>
				<MvASSIGN NAME = "l.attributes" VALUE = 0>

				<MvDO FILE = "{ g.Module_Library_DB }" NAME = "l.found" VALUE = "{ Attribute_FindFirst_Product( Products.d.id ) }">
				<MvWHILE EXPR = "{ l.found AND ( NOT l.missing ) }">
					<MvASSIGN NAME = "l.check" VALUE = 1>
					<MvASSIGN NAME = "l.found_attribute" VALUE = 0>
					
					<MvWHILE EXPR = "{ l.check LE g.AttributeCount }">
						<MvIF EXPR = "{ g.AttributeCode[ l.check ] EQ Attributes.d.code }">
							<MvIF EXPR = "{ ( Attributes.d.type EQ 'radio' ) OR ( Attributes.d.type EQ 'select' ) }">
								<MvDO FILE = "{ g.Module_Library_DB }" NAME = "l.id" VALUE = "{ Option_Find_Code( Attributes.d.id, g.AttributeValue[ l.check ] ) }">
								<MvIF EXPR = "{ l.id }">
									<MvASSIGN NAME = "l.attributes" VALUE = "{ l.attributes + 1 }">

									<MvASSIGN NAME = "l.attribute_id" INDEX = "{ l.attributes }" VALUE = "{ Attributes.d.id }">
									<MvASSIGN NAME = "l.attribute_code" INDEX = "{ l.attributes }" VALUE = "{ Attributes.d.code }">
									<MvASSIGN NAME = "l.option_id" INDEX = "{ l.attributes }" VALUE = "{ l.id }">
									<MvASSIGN NAME = "l.option_code" INDEX = "{ l.attributes }" VALUE = "{ Options.d.code }">
									<MvASSIGN NAME = "l.option_data" INDEX = "{ l.attributes }" VALUE = "">
									<MvASSIGN NAME = "l.option_price" INDEX = "{ l.attributes }" VALUE = "{ Options.d.price }">

									<MvASSIGN NAME = "l.found_attribute" VALUE = 1>
								</MvIF>
							<MvELSE>
								<MvIF EXPR = "{ Attributes.d.type NE 'template' }">
									<MvASSIGN NAME = "l.option_id" INDEX = "{ l.check }" VALUE = 0>

									<MvIF EXPR = "{ len( g.AttributeValue[ l.check ] ) }">
										<MvASSIGN NAME = "l.attributes" VALUE = "{ l.attributes + 1 }">

										<MvASSIGN NAME = "l.attribute_id" INDEX = "{ l.attributes }" VALUE = "{ Attributes.d.id }">
										<MvASSIGN NAME = "l.attribute_code" INDEX = "{ l.attributes }" VALUE = "{ Attributes.d.code }">
										<MvASSIGN NAME = "l.option_id" INDEX = "{ l.attributes }" VALUE = 0>
										<MvASSIGN NAME = "l.option_code" INDEX = "{ l.attributes }" VALUE = "">

										<MvIF EXPR = "{ Attributes.d.type EQ 'checkbox' }">
											<MvASSIGN NAME = "l.option_data" INDEX = "{ l.attributes }" VALUE = "">
										<MvELSE>
											<MvASSIGN NAME = "l.option_data" INDEX = "{ l.attributes }" VALUE = "{ g.AttributeValue[ l.check ] }">
										</MvIF>

										<MvASSIGN NAME = "l.option_price" INDEX = "{ l.attributes }" VALUE = "{ Attributes.d.price }">
										<MvASSIGN NAME = "l.found_attribute" VALUE = 1>
									</MvIF>
								</MvIF>
							</MvIF>

							<MvIF EXPR = "{ g.Features:AttributeTemplates:Enabled }">
								<MvIF EXPR = "{ ( Attributes.d.type EQ 'template' ) }">

									<MvDO FILE = "{ g.Module_Feature_ATT_DB }" NAME = "l.found" VALUE = "{ AttributeTemplate_Find_ID( Attributes.d.attemp_id ) }">
									<MvIF EXPR = "{ l.found }">
										<MvDO FILE = "{ g.Module_Feature_ATT_DB }" NAME = "l.found" VALUE = "{ AttributeTemplateAttribute_FindFirst_AttributeTemplate( AttributeTemplates.d.id ) }">

										<MvWHILE EXPR = "{ l.found }">
											<MvIF EXPR = "{ ( AttributeTemplateAttributes.d.type EQ 'radio' ) OR ( AttributeTemplateAttributes.d.type EQ 'select' ) }">
												<MvDO FILE = "{ g.Module_Feature_ATT_DB }" NAME = "l.id" VALUE = "{ AttributeTemplateOption_Find_Code( AttributeTemplateAttributes.d.id, g.AttributeValue[ l.check ] ) }">

												<MvIF EXPR = "{ l.id }">
													<MvASSIGN NAME = "l.attributes" VALUE = "{ l.attributes + 1 }">
													<MvASSIGN NAME = "l.attribute_id" INDEX = "{ l.attributes }" VALUE = "{ AttributeTemplateAttributes.d.id }">
													<MvASSIGN NAME = "l.attribute_code" INDEX = "{ l.attributes }" VALUE = "{ AttributeTemplateAttributes.d.code }">
													<MvASSIGN NAME = "l.option_id" INDEX = "{ l.attributes }" VALUE = "{ l.id }">
													<MvASSIGN NAME = "l.option_code" INDEX = "{ l.attributes }" VALUE = "{ AttributeTemplateOptions.d.code }">
													<MvASSIGN NAME = "l.option_data" INDEX = "{ l.attributes }" VALUE = "">

													<MvDO FILE = "{ g.Module_Library_Utilities }" NAME = "l.option_adjusted_price" VALUE = "{ Adjusted_Price( Products.d.id, Products.d.pgrpcount, AttributeTemplateOptions.d.price, AttributeTemplateOptions.d.cost ) }">

													<MvASSIGN NAME = "l.option_price" INDEX = "{ l.attributes }" VALUE = "{ l.option_adjusted_price }">
													<MvASSIGN NAME = "l.found_attribute" INDEX = "{ l.check }" VALUE = 1>
												</MvIF>
											<MvELSE>
												<MvASSIGN NAME = "l.option_id" INDEX = "{ l.check }" VALUE = 0>
												<MvIF EXPR = "{ len( g.AttributeValue[ l.check ] ) }">
													<MvASSIGN NAME = "l.attributes" VALUE = "{ l.attributes + 1 }">
													<MvASSIGN NAME = "l.attribute_id" INDEX = "{ l.attributes }" VALUE = "{ AttributeTemplateAttributes.d.id }">
													<MvASSIGN NAME = "l.attribute_code" INDEX = "{ l.attributes }" VALUE = "{ AttributeTemplateAttributes.d.code }">
													<MvASSIGN NAME = "l.option_id" INDEX = "{ l.attributes }" VALUE = 0>
													<MvASSIGN NAME = "l.option_code" INDEX = "{ l.attributes }" VALUE = "">
													<MvIF EXPR = "{ Attributes.d.type EQ 'checkbox' }">
														<MvASSIGN NAME = "l.option_data" INDEX = "{ l.attributes }" VALUE = "">
													<MvELSE>
														<MvASSIGN NAME = "l.option_data" INDEX = "{ l.attributes }" VALUE = "{ g.AttributeValue[ l.check ] }">
													</MvIF>
													<MvDO FILE = "{ g.Module_Library_Utilities }" NAME = "l.attribute_adjusted_price" VALUE = "{ Adjusted_Price( Products.d.id, Products.d.pgrpcount, AttributeTemplates.d.price, AttributeTemplates.d.cost ) }">
													<MvASSIGN NAME = "l.option_price" INDEX = "{ l.attributes }" VALUE = "{ l.attribute_adjusted_price }">
													<MvASSIGN NAME = "l.found_attribute" INDEX = "{ l.check }" VALUE = 1>
												</MvIF>
											</MvIF>

											<MvIF EXPR = "{ AttributeTemplateAttributes.d.required }">
												<MvIF EXPR = "{ NOT l.found_attribute[ l.check ] }">
													<MvASSIGN NAME = "l.missing" VALUE = 1>
												</MvIF>
											</MvIF>

											<MvDO FILE = "{ g.Module_Feature_ATT_DB }" NAME = "l.found" VALUE = "{ AttributeTemplateAttribute_FindNext_AttributeTemplate( AttributeTemplates.d.id ) }">
											<MvASSIGN NAME = "l.check" VALUE = "{ l.check + 1 }">
										</MvWHILE>
									</MvIF>
								</MvIF>

								<MvWHILESTOP>
							</MvIF>
						</MvIF>
						
						<MvASSIGN NAME = "l.check" VALUE = "{ l.check + 1 }">
					</MvWHILE>

					<MvIF EXPR = "{ Attributes.d.required }">
						<MvIF EXPR = "{ NOT l.found_attribute }">
							<MvASSIGN NAME = "l.missing" VALUE = 1>
						</MvIF>
					</MvIF>

					<MvDO FILE = "{ g.Module_Library_DB }" NAME = "l.found" VALUE = "{ Attribute_FindNext_Product( Products.d.id ) }">
				</MvWHILE>

				<MvIF EXPR = "{ l.missing }">
					<MvDO FILE = "{ g.Module_Library_Utilities }" NAME = "l.null" VALUE = "{ Data_Entry_Error( '' ) }">
					<MvDO FILE = "{ g.Module_Store_Module_UI }" NAME = "l.ok" VALUE = "{ UIModule_Upsell_Attributes() }">
				<MvELSE>
					<MvIF EXPR = "{ Upsell.d.percent }">
						<MvASSIGN NAME = "l.price" VALUE = "{ Products.d.price * ( Upsell.d.price / 100 ) }">
					<MvELSE>
						<MvASSIGN NAME = "l.price" VALUE = "{ Upsell.d.price }">
					</MvIF>
					<MvDO FILE = "{ g.Module_Library_DB }" NAME = "l.line_id" VALUE = "{ Basket_Insert( g.Basket_ID, Products.d.id, Products.d.code, Products.d.name, l.price, Products.d.weight, Products.d.taxable, 1, 1) }">

					<MvASSIGN NAME = "l.attribute" VALUE = 1>
					<MvWHILE EXPR = "{ l.attribute LE l.attributes }">
						<MvDO FILE = "{ g.Module_Library_DB }" NAME = "l.ok" VALUE = "{ BasketOption_Insert( l.line_id, l.attribute_id[ l.attribute ], l.attribute_code[ l.attribute ], l.option_id[ l.attribute ], l.option_code[ l.attribute ], l.option_data[ l.attribute ], l.option_price[ l.attribute ] ) }">
						<MvASSIGN NAME = "l.attribute" VALUE = "{ l.attribute + 1 }">
					</MvWHILE>

					<MvIF EXPR = "{ l.ok }">
						<MvDO FILE = "{ g.Module_Feature_INV_RT }" NAME = "l.ok" VALUE = "{ INV_AdjustInventoryAsNeeded( Products.d.id, -1 ) }">
					</MvIF>

					<MvIF EXPR = "{ l.ok }">
						<MvDO FILE = "{ g.Module_Library_Utilities }" NAME = "l.ok" VALUE = "{ Log_Action_AddUpsoldProductToBasket( g.Product_Code ) }">
					</MvIF>
				</MvIF>
			</MvIF>
		</MvIF>
	</MvIF>

	<MvFUNCTIONRETURN VALUE = "{ l.ok }">
</MvFUNCTION>

<MvFUNCTION NAME = "Action_AddMultipleUpsoldProductsToBasket" STANDARDOUTPUTLEVEL = "">
	<MvASSIGN NAME = "l.ok" VALUE = 1>
	<MvASSIGN NAME = "l.continue" VALUE = 1>
	<MvASSIGN NAME = "l.missing" VALUE = 0>
	
	<MvDO FILE = "{ g.Module_Library_DB }" NAME = "l.found" VALUE = "{ StoreModule_FindFirst_Type( 'SYSTEM' ) }">
	<MvWHILE EXPR = "{ l.found }">
		<MvDO FILE = "{ g.Module_Root $ Modules.d.module }" NAME = "l.result" VALUE = "{ SystemModule_Action_AddUpsoldProductToBasket() }">

		<MvIF EXPR = "{ l.result LE 0 }">
			<MvASSIGN NAME = "l.continue" VALUE = 0>

			<MvIF EXPR = "{ l.result EQ 0 }">
				<MvASSIGN NAME = "l.ok" VALUE = 0>
			</MvIF>

			<MvWHILESTOP>
		</MvIF>

		<MvDO FILE = "{ g.Module_Library_DB }" NAME = "l.found" VALUE = "{ StoreModule_FindNext_Type( 'SYSTEM' ) }">
	</MvWHILE>

	<MvIF EXPR = "{ l.continue }">
		<MvDO FILE = "{ g.Module_Feature_USL_DB }" NAME = "l.ok" VALUE = "{ Upsell_Delete_UpsellProductInBasket() }">
	</MvIF>

	<MvIF EXPR = "{ l.continue }">
		<MvDO FILE = "{ g.Module_Feature_USL_DB }" NAME = "l.ok" VALUE = "{ UpsellOptions_Find() }">
		<MvASSIGN NAME = "l.product" VALUE = 1>
		<MvASSIGN NAME = "l.products_selected" VALUE = 0>
		<MvWHILE EXPR = "{ ( l.product LE g.Upsell_Product_Count ) AND ( l.products_selected LE UpsellOptions.d.prod_sell ) }">
			<MvIF EXPR = "{ g.Upsell_Selected[ l.product ] }">
				<MvASSIGN NAME = "l.products_selected" VALUE = "{ l.products_selected + 1 }">
			</MvIF>

			<MvASSIGN NAME = "l.product" VALUE = "{ l.product + 1 }">
		</MvWHILE>
		<MvIF EXPR = "{ l.products_selected GT UpsellOptions.d.prod_sell }">
			<MvASSIGN NAME = "l.continue" VALUE = "0">
			<MvDO FILE = "{ g.Module_Library_Utilities }" NAME = "l.null" VALUE = "{ Data_Entry_Error( '' ) }">
			<MvDO FILE = "{ g.Module_Store_Module_UI }" NAME = "l.ok" VALUE = "{ UIModule_Upsell_Selected_Too_Many() }">
		</MvIF>
	</MvIF>

	<MvIF EXPR = "{ l.continue }">
		<MvASSIGN NAME = "l.product" VALUE = 1>
		<MvWHILE EXPR = "{ l.product LE g.Upsell_Product_Count }">
			<MvIF EXPR = "{ g.Upsell_Selected[ l.product ] }">

				<MvDO FILE = "{ g.Module_Library_DB }" NAME = "l.ok" VALUE = "{ Product_Find_Code( g.Product_Code[ l.product ] ) }">
				<MvIF EXPR = "{ l.ok }">
					<MvDO FILE = "{ g.Module_Feature_USL_DB }" NAME = "l.ok" VALUE = "{ Upsell_Find_Product_ID( Products.d.id ) }">
				</MvIF>

				<MvIF EXPR = "{ l.ok }">
					<MvDO FILE = "{ g.Module_Library_DB }" NAME = "l.quantity" VALUE = "{ Basket_Quantity( g.Session_ID, Products.d.id ) }">
					<MvIF EXPR = "{ l.quantity EQ 0 }">
						<MvASSIGN NAME = "l.attributes" INDEX = "{ l.product }" VALUE = 0>

						<MvDO FILE = "{ g.Module_Library_DB }" NAME = "l.found" VALUE = "{ Attribute_FindFirst_Product( Products.d.id ) }">
						<MvWHILE EXPR = "{ l.found AND ( NOT l.missing ) }">
							<MvIF EXPR = "{ ( Attributes.d.type EQ 'template' ) }">
								<MvDO FILE = "{ g.Module_Feature_ATT_DB }" NAME = "l.found" VALUE = "{ AttributeTemplate_Find_ID( Attributes.d.attemp_id ) }">
								<MvIF EXPR = "{ l.found }">
									<MvDO FILE = "{ g.Module_Feature_ATT_DB }" NAME = "l.found" VALUE = "{ AttributeTemplateAttribute_FindFirst_AttributeTemplate( AttributeTemplates.d.id ) }">
									<MvWHILE EXPR = "{ l.found  AND ( NOT l.missing ) }">
										<MvASSIGN NAME = "l.check" VALUE = 1>
										<MvASSIGN NAME = "l.found_attribute" VALUE = 0>

										<MvWHILE EXPR = "{ l.check LE g.AttributeCount[ l.product ] }">
											<MvIF EXPR = "{ g.AttributeCode[ l.product ][ l.check ] EQ AttributeTemplateAttributes.d.code }">
												<MvIF EXPR = "{ ( AttributeTemplateAttributes.d.type EQ 'radio' ) OR ( AttributeTemplateAttributes.d.type EQ 'select' ) }">
													<MvDO FILE = "{ g.Module_Library_DB }" NAME = "l.id" VALUE = "{ Option_Find_Code( AttributeTemplateAttributes.d.id, g.AttributeValue[ l.product ][ l.check ] ) }">
													<MvIF EXPR = "{ l.id }">
														<MvASSIGN NAME = "l.attributes" INDEX = "{ l.product }" VALUE = "{ l.attributes[ l.product ] + 1 }">

														<MvASSIGNARRAY NAME = "l.attribute_id" VALUE = "{ AttributeTemplateAttributes.d.id }">
															<MvDIMENSION INDEX = "{ l.product }">
															<MvDIMENSION INDEX = "{ l.attributes[ l.product ] }">
														</MvASSIGNARRAY>
														<MvASSIGNARRAY NAME = "l.attribute_code" VALUE = "{ AttributeTemplateAttributes.d.code }">
															<MvDIMENSION INDEX = "{ l.product }">
															<MvDIMENSION INDEX = "{ l.attributes[ l.product ] }">
														</MvASSIGNARRAY>
														<MvASSIGNARRAY NAME = "l.option_id" VALUE = "{ l.id }">
															<MvDIMENSION INDEX = "{ l.product }">
															<MvDIMENSION INDEX = "{ l.attributes[ l.product ] }">
														</MvASSIGNARRAY>
														<MvASSIGNARRAY NAME = "l.option_code" VALUE = "{ Options.d.code }">
															<MvDIMENSION INDEX = "{ l.product }">
															<MvDIMENSION INDEX = "{ l.attributes[ l.product ] }">
														</MvASSIGNARRAY>
														<MvASSIGNARRAY NAME = "l.option_data" VALUE = "">
															<MvDIMENSION INDEX = "{ l.product }">
															<MvDIMENSION INDEX = "{ l.attributes[ l.product ] }">
														</MvASSIGNARRAY>
														<MvASSIGNARRAY NAME = "l.option_price" VALUE = "{ Options.d.price }">
															<MvDIMENSION INDEX = "{ l.product }">
															<MvDIMENSION INDEX = "{ l.attributes[ l.product ] }">
														</MvASSIGNARRAY>

														<MvASSIGN NAME = "l.found_attribute" VALUE = 1>
													</MvIF>
												<MvELSE>
													<MvASSIGNARRAY NAME = "l.option_id" VALUE = 0>
														<MvDIMENSION INDEX = "{ l.product }">
														<MvDIMENSION INDEX = "{ l.check }">
													</MvASSIGNARRAY>

													<MvIF EXPR = "{ len( g.AttributeValue[ l.product ][ l.check ] ) }">
														<MvASSIGN NAME = "l.attributes" INDEX = "{ l.product }" VALUE = "{ l.attributes[ l.product ] + 1 }">

														<MvASSIGNARRAY NAME = "l.attribute_id" VALUE = "{ AttributeTemplateAttributes.d.id }">
															<MvDIMENSION INDEX = "{ l.product }">
															<MvDIMENSION INDEX = "{ l.attributes[ l.product ] }">
														</MvASSIGNARRAY>
														<MvASSIGNARRAY NAME = "l.attribute_code" VALUE = "{ AttributeTemplateAttributes.d.code }">
															<MvDIMENSION INDEX = "{ l.product }">
															<MvDIMENSION INDEX = "{ l.attributes[ l.product ] }">
														</MvASSIGNARRAY>
														<MvASSIGNARRAY NAME = "l.option_id" VALUE = 0>
															<MvDIMENSION INDEX = "{ l.product }">
															<MvDIMENSION INDEX = "{ l.attributes[ l.product ] }">
														</MvASSIGNARRAY>
														<MvASSIGNARRAY NAME = "l.option_code" VALUE = "">
															<MvDIMENSION INDEX = "{ l.product }">
															<MvDIMENSION INDEX = "{ l.attributes[ l.product ] }">
														</MvASSIGNARRAY>

														<MvIF EXPR = "{ AttributeTemplateAttributes.d.type EQ 'checkbox' }">
															<MvASSIGNARRAY NAME = "l.option_data" VALUE = "">
																<MvDIMENSION INDEX = "{ l.product }">
																<MvDIMENSION INDEX = "{ l.attributes[ l.product ] }">
															</MvASSIGNARRAY>
														<MvELSE>
															<MvASSIGNARRAY NAME = "l.option_data" VALUE = "{ g.AttributeValue[ l.product ][ l.check ] }">
																<MvDIMENSION INDEX = "{ l.product }">
																<MvDIMENSION INDEX = "{ l.attributes[ l.product ] }">
															</MvASSIGNARRAY>
														</MvIF>

														<MvASSIGNARRAY NAME = "l.option_price_" VALUE = "{ AttributeTemplateAttributes.d.price }">
															<MvDIMENSION INDEX = "{ l.product }">
															<MvDIMENSION INDEX = "{ l.attributes[ l.product ] }">
														</MvASSIGNARRAY>

														<MvASSIGN NAME = "l.found_attribute" VALUE = 1>
													</MvIF>
												</MvIF>
												<MvWHILESTOP>
											</MvIF>

											<MvASSIGN NAME = "l.check" VALUE = "{ l.check + 1 }">
										</MvWHILE>

										<MvIF EXPR = "{ AttributeTemplateAttributes.d.required }">
											<MvIF EXPR = "{ NOT l.found_attribute }">
												<MvASSIGN NAME = "l.missing" VALUE = 1>
											</MvIF>
										</MvIF>
									
										<MvDO FILE = "{ g.Module_Feature_ATT_DB }" NAME = "l.found" VALUE = "{ AttributeTemplateAttribute_FindNext_AttributeTemplate( AttributeTemplates.d.id ) }">
									</MvWHILE>
							
								</MvIF>
							<MvELSE>
								<MvASSIGN NAME = "l.check" VALUE = 1>
								<MvASSIGN NAME = "l.found_attribute" VALUE = 0>

								<MvWHILE EXPR = "{ l.check LE g.AttributeCount[ l.product ] }">
									<MvIF EXPR = "{ g.AttributeCode[ l.product ][ l.check ] EQ Attributes.d.code }">
										<MvIF EXPR = "{ ( Attributes.d.type EQ 'radio' ) OR ( Attributes.d.type EQ 'select' ) }">
											<MvDO FILE = "{ g.Module_Library_DB }" NAME = "l.id" VALUE = "{ Option_Find_Code( Attributes.d.id, g.AttributeValue[ l.product ][ l.check ] ) }">
											<MvIF EXPR = "{ l.id }">
												<MvASSIGN NAME = "l.attributes" INDEX = "{ l.product }" VALUE = "{ l.attributes[ l.product ] + 1 }">

												<MvASSIGNARRAY NAME = "l.attribute_id" VALUE = "{ Attributes.d.id }">
													<MvDIMENSION INDEX = "{ l.product }">
													<MvDIMENSION INDEX = "{ l.attributes[ l.product ] }">
												</MvASSIGNARRAY>
												<MvASSIGNARRAY NAME = "l.attribute_code" VALUE = "{ Attributes.d.code }">
													<MvDIMENSION INDEX = "{ l.product }">
													<MvDIMENSION INDEX = "{ l.attributes[ l.product ] }">
												</MvASSIGNARRAY>
												<MvASSIGNARRAY NAME = "l.option_id" VALUE = "{ l.id }">
													<MvDIMENSION INDEX = "{ l.product }">
													<MvDIMENSION INDEX = "{ l.attributes[ l.product ] }">
												</MvASSIGNARRAY>
												<MvASSIGNARRAY NAME = "l.option_code" VALUE = "{ Options.d.code }">
													<MvDIMENSION INDEX = "{ l.product }">
													<MvDIMENSION INDEX = "{ l.attributes[ l.product ] }">
												</MvASSIGNARRAY>
												<MvASSIGNARRAY NAME = "l.option_data" VALUE = "">
													<MvDIMENSION INDEX = "{ l.product }">
													<MvDIMENSION INDEX = "{ l.attributes[ l.product ] }">
												</MvASSIGNARRAY>
												<MvASSIGNARRAY NAME = "l.option_price" VALUE = "{ Options.d.price }">
													<MvDIMENSION INDEX = "{ l.product }">
													<MvDIMENSION INDEX = "{ l.attributes[ l.product ] }">
												</MvASSIGNARRAY>

												<MvASSIGN NAME = "l.found_attribute" VALUE = 1>
											</MvIF>
										<MvELSE>
											<MvASSIGNARRAY NAME = "l.option_id" VALUE = 0>
												<MvDIMENSION INDEX = "{ l.product }">
												<MvDIMENSION INDEX = "{ l.check }">
											</MvASSIGNARRAY>

											<MvIF EXPR = "{ len( g.AttributeValue[ l.product ][ l.check ] ) }">
												<MvASSIGN NAME = "l.attributes" INDEX = "{ l.product }" VALUE = "{ l.attributes[ l.product ] + 1 }">

												<MvASSIGNARRAY NAME = "l.attribute_id" VALUE = "{ Attributes.d.id }">
													<MvDIMENSION INDEX = "{ l.product }">
													<MvDIMENSION INDEX = "{ l.attributes[ l.product ] }">
												</MvASSIGNARRAY>
												<MvASSIGNARRAY NAME = "l.attribute_code" VALUE = "{ Attributes.d.code }">
													<MvDIMENSION INDEX = "{ l.product }">
													<MvDIMENSION INDEX = "{ l.attributes[ l.product ] }">
												</MvASSIGNARRAY>
												<MvASSIGNARRAY NAME = "l.option_id" VALUE = 0>
													<MvDIMENSION INDEX = "{ l.product }">
													<MvDIMENSION INDEX = "{ l.attributes[ l.product ] }">
												</MvASSIGNARRAY>
												<MvASSIGNARRAY NAME = "l.option_code" VALUE = "">
													<MvDIMENSION INDEX = "{ l.product }">
													<MvDIMENSION INDEX = "{ l.attributes[ l.product ] }">
												</MvASSIGNARRAY>

												<MvIF EXPR = "{ Attributes.d.type EQ 'checkbox' }">
													<MvASSIGNARRAY NAME = "l.option_data" VALUE = "">
														<MvDIMENSION INDEX = "{ l.product }">
														<MvDIMENSION INDEX = "{ l.attributes[ l.product ] }">
													</MvASSIGNARRAY>
												<MvELSE>
													<MvASSIGNARRAY NAME = "l.option_data" VALUE = "{ g.AttributeValue[ l.product ][ l.check ] }">
														<MvDIMENSION INDEX = "{ l.product }">
														<MvDIMENSION INDEX = "{ l.attributes[ l.product ] }">
													</MvASSIGNARRAY>
												</MvIF>

												<MvASSIGNARRAY NAME = "l.option_price_" VALUE = "{ Attributes.d.price }">
													<MvDIMENSION INDEX = "{ l.product }">
													<MvDIMENSION INDEX = "{ l.attributes[ l.product ] }">
												</MvASSIGNARRAY>

												<MvASSIGN NAME = "l.found_attribute" VALUE = 1>
											</MvIF>
										</MvIF>
										<MvWHILESTOP>
									</MvIF>

									<MvASSIGN NAME = "l.check" VALUE = "{ l.check + 1 }">
								</MvWHILE>

								<MvIF EXPR = "{ Attributes.d.required }">
									<MvIF EXPR = "{ NOT l.found_attribute }">
										<MvASSIGN NAME = "l.missing" VALUE = 1>
									</MvIF>
								</MvIF>
							</MvIF>
							<MvDO FILE = "{ g.Module_Library_DB }" NAME = "l.found" VALUE = "{ Attribute_FindNext_Product( Products.d.id ) }">
						</MvWHILE>

					</MvIF>
				</MvIF>
			</MvIF>

			<MvASSIGN NAME = "l.product" VALUE = "{ l.product + 1 }">
		</MvWHILE>
		
		
		<MvIF EXPR = "{ l.ok }">
			<MvIF EXPR = "{ l.missing }">
				<MvDO FILE = "{ g.Module_Library_Utilities }" NAME = "l.null" VALUE = "{ Data_Entry_Error( '' ) }">
				<MvDO FILE = "{ g.Module_Store_Module_UI }" NAME = "l.ok" VALUE = "{ UIModule_Upsell_Multiple_Attributes() }">
			<MvELSE>
				<MvASSIGN NAME = "l.product" VALUE = "1">
				<MvWHILE EXPR = "{ l.product LE g.Upsell_Product_Count }">
					<MvIF EXPR = "{ g.Upsell_Selected[ l.product ] }">
						<MvDO FILE = "{ g.Module_Library_DB }" NAME = "l.ok" VALUE = "{ Product_Find_Code( g.Product_Code[ l.product ] ) }">

						<MvIF EXPR = "{ l.ok }">
							<MvDO FILE = "{ g.Module_Feature_USL_DB }" NAME = "l.ok" VALUE = "{ Upsell_Find_Product_ID( Products.d.id ) }">
						</MvIF>

						<MvIF EXPR = "{ l.ok }">
							<MvDO FILE = "{ g.Module_Library_DB }" NAME = "l.quantity" VALUE = "{ Basket_Quantity( g.Session_ID, Products.d.id ) }">
							<MvIF EXPR = "{ Upsell.d.percent }">
								<MvASSIGN NAME = "l.price" VALUE = "{ Products.d.price * ( Upsell.d.price / 100 ) }">
							<MvELSE>
								<MvASSIGN NAME = "l.price" VALUE = "{ Upsell.d.price }">
							</MvIF>
							<MvDO FILE = "{ g.Module_Library_DB }" NAME = "l.line_id" VALUE = "{ Basket_Insert( g.Basket_ID, Products.d.id, Products.d.code, Products.d.name,
																										 l.price, Products.d.weight, Products.d.taxable, 1, 1 ) }">

							<MvASSIGN NAME = "l.attribute" VALUE = 1>
							<MvWHILE EXPR = "{ l.attribute LE l.attributes[ l.product ] }">
								<MvDO FILE = "{ g.Module_Library_DB }" NAME = "l.ok" VALUE = "{ BasketOption_Insert( l.line_id, l.attribute_id[ l.product ][ l.attribute ], l.attribute_code[ l.product ][ l.attribute ], l.option_id[ l.product ][ l.attribute ], l.option_code[ l.product ][ l.attribute ], l.option_data[ l.product ][ l.attribute ], l.option_price[ l.product ][ l.attribute ] ) }">
								<MvASSIGN NAME = "l.attribute" VALUE = "{ l.attribute + 1 }">
							</MvWHILE>
							
							<MvIF EXPR = "{ l.ok }">
								<MvDO FILE = "{ g.Module_Feature_INV_RT }" NAME = "l.ok" VALUE = "{ INV_AdjustInventoryAsNeeded( Products.d.id, -1 ) }">
							</MvIF>
	
							<MvIF EXPR = "{ l.ok }">
								<MvDO FILE = "{ g.Module_Library_Utilities }" NAME = "l.ok" VALUE = "{ Log_Action_AddUpsoldProductToBasket( g.Product_Code ) }">
							</MvIF>
						</MvIF>
					</MvIF>
					<MvASSIGN NAME = "l.product" VALUE = "{ l.product + 1 }">
				</MvWHILE>
			</MvIF>
		</MvIF>
	</MvIF>

	<MvFUNCTIONRETURN VALUE = "{ l.ok }">
</MvFUNCTION>
