nicatronTg

Untitled

May 9th, 2015
461
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 20.66 KB | None | 0 0
  1. //-----------------------------------------------------------------
  2. // Licensed Materials - Property of IBM
  3. //
  4. // WebSphere Commerce
  5. //
  6. // (C) Copyright IBM Corp. 2008, 2012 All Rights Reserved.
  7. //
  8. // US Government Users Restricted Rights - Use, duplication or
  9. // disclosure restricted by GSA ADP Schedule Contract with
  10. // IBM Corp.
  11. //-----------------------------------------------------------------
  12.  
  13. /**
  14. * @fileOverview This class contains declarations of AJAX services used by the Madisons store pages.
  15. */
  16.  
  17. dojo.require("wc.service.common");
  18.  
  19. /**
  20. * @class This class stores common parameters needed to make the service call.
  21. */
  22. shoppingActionsServicesDeclarationJS = {
  23. langId: "-1", /* language of the store */
  24. storeId: "", /*numeric unique identifier of the store */
  25. catalogId: "", /*catalog of the store that is currently in use */
  26.  
  27. /**
  28. * Sets common parameters used by the services
  29. * @param (int) langId The language of the store.
  30. * @param (int) storeId The store currently in use.
  31. * @param (int) catalogId The catalog of the store currently in use.
  32. */
  33. setCommonParameters:function(langId,storeId,catalogId){
  34. this.langId = langId;
  35. this.storeId = storeId;
  36. this.catalogId = catalogId;
  37. }
  38. }
  39.  
  40. /**
  41. * Add an item to a shopping cart in Ajax mode. A message is displayed after
  42. * the service call.
  43. * @constructor
  44. */
  45. wc.service.declare({
  46. id: "AddOrderItem",
  47. actionId: "AddOrderItem",
  48. url: getAbsoluteURL() + "AjaxOrderChangeServiceItemAdd",
  49. formId: ""
  50.  
  51. /**
  52. * display a success message
  53. * @param (object) serviceResponse The service response object, which is the
  54. * JSON object returned by the service invocation
  55. */
  56.  
  57. ,successHandler: function(serviceResponse) {
  58. //MessageHelper.hideAndClearMessage();
  59. // Do not show this message. When item is added, we open up mini cart to display the currently added item.
  60. // MessageHelper.displayStatusMessage(storeNLS["SHOPCART_ADDED"]);
  61. dropdownUpdated = false;
  62. showMiniShopCartDropDown('widget_minishopcart','quick_cart_container','orderItemsListAutoClose');
  63. $('html, body').animate({ scrollTop:0}, $(window).scrollTop() / 3);
  64. cursor_clear();
  65. if(shoppingActionsJS){
  66.  
  67. var attributes = document.getElementsByName("attrValue");
  68.  
  69. var singleSKU = true;
  70.  
  71. for(var i=0; i<attributes.length; i++){
  72. if (attributes[i].options.length > 1)
  73. {
  74. singleSKU = false;
  75. }
  76. }
  77.  
  78. if (!singleSKU)
  79. {
  80. shoppingActionsJS.selectedAttributes = new Object();
  81. dojo.publish('attributesChanged_'+ shoppingActionsJS.baseCatalogEntryId, [dojo.toJson(shoppingActionsJS.selectedAttributes)]);
  82. for(var i=0; i<attributes.length; i++){
  83. if(attributes[i] != null){
  84. attributes[i].value = "";
  85. attributes[i].onchange();
  86. }
  87. }
  88. }
  89.  
  90. }
  91. if(typeof(ShipmodeSelectionExtJS)!= null && typeof(ShipmodeSelectionExtJS)!='undefined'){
  92. ShipmodeSelectionExtJS.setOrderItemId(serviceResponse.orderItemId[0]);
  93. }
  94. dojo.publish("CMAddToCart");
  95. }
  96. /**
  97. * display an error message
  98. * @param (object) serviceResponse The service response object, which is the
  99. * JSON object returned by the service invocation
  100. */
  101. ,failureHandler: function(serviceResponse) {
  102.  
  103. if (serviceResponse.errorMessage) {
  104. if(serviceResponse.errorMessageKey == "_ERR_NO_ELIGIBLE_TRADING"){
  105. //MessageHelper.displayErrorMessage(storeNLS["ERROR_CONTRACT_EXPIRED_GOTO_ORDER"]);
  106. } else if (serviceResponse.errorMessageKey == "_ERR_RETRIEVE_PRICE") {
  107. var tempString = storeNLS["GENERICERR_MAINTEXT"];
  108. tempString = dojo.string.substitute(tempString,{0:storeNLS["GENERICERR_CONTACT_US"]});
  109. //MessageHelper.displayErrorMessage(tempString);
  110. } else {
  111. //MessageHelper.displayErrorMessage(serviceResponse.errorMessage);
  112. alert(serviceResponse.errorMessage);
  113. }
  114. }
  115. else {
  116. if (serviceResponse.errorMessageKey) {
  117. //MessageHelper.displayErrorMessage(serviceResponse.errorMessageKey);
  118. }
  119. }
  120. cursor_clear();
  121. }
  122.  
  123. }),
  124.  
  125. wc.service.declare({
  126. id: "MiniCartOrderCalculate",
  127. actionId: "MiniCartOrderCalculate",
  128. url: getAbsoluteURL() + "AjaxOrderCalculate",
  129. formId: ""
  130. ,successHandler: function(serviceResponse)
  131. {
  132. console.log ("Order calculate success");
  133. var orderId=serviceResponse.orderIdOrderItemAccessBean;
  134. var orderItemId=serviceResponse.orderItemId;
  135. var param = [];
  136. param.storeId = WCParamJS.storeId;
  137. param.catalogId = WCParamJS.catalogId;
  138. param.langId = WCParamJS.langId;
  139. param.orderId = orderId
  140. param.orderItemId = orderItemId;
  141.  
  142.  
  143.  
  144.  
  145. //alert($("#PDPSku").val());
  146. var accessoriesUrl = "PDPAccessoriesFinderView?storeId=" +
  147. shoppingActionsServicesDeclarationJS.storeId + "&catalogId=" +
  148. shoppingActionsServicesDeclarationJS.catalogId + "&langId=" +
  149. shoppingActionsServicesDeclarationJS.langId + "&productId=" +$("#PDPSku").val().split('_')[1]+"&SKU_ID="+$("#PDPSku").val().split('_')[0];
  150. $.ajax({
  151. url: getAbsoluteURL()+accessoriesUrl ,
  152. success: function(data) {
  153. $("body").append("<div style:visibility='hidden'>"+data+"</div>");
  154. if($("#PDPAccessoriesAssociations").val() != undefined && $("#PDPAccessoriesAssociations").val().indexOf('Y')!=-1) {
  155. var productId=$("#PDPSku").val().split('_')[1];
  156. updateCartQuantityInAddtoCart(serviceResponse.orderId);
  157. var redirectUrl = "AccessoriesView?storeId=" +
  158. shoppingActionsServicesDeclarationJS.storeId + "&catalogId=" +
  159. shoppingActionsServicesDeclarationJS.catalogId + "&langId=" +
  160. shoppingActionsServicesDeclarationJS.langId + "&productId=" +
  161. productId+"&SKU_ID="+$("#PDPSku").val().split('_')[0];
  162. document.location.href = getAbsoluteURL() + redirectUrl;
  163. }
  164. else {
  165. updateCartQuantityInAddtoCart(serviceResponse.orderId);
  166. var redirectUrl = "AjaxOrderItemDisplayView?storeId=" +
  167. shoppingActionsServicesDeclarationJS.storeId + "&catalogId=" +
  168. shoppingActionsServicesDeclarationJS.catalogId + "&langId=" +
  169. shoppingActionsServicesDeclarationJS.langId + "&hashString="+serviceResponse.hashString + "&catentDeletedName=" +serviceResponse.catentDeletedName;
  170. document.location.href = getAbsoluteURL() + redirectUrl;
  171. }
  172. }
  173. });
  174. }
  175. ,failureHandler: function(serviceResponse)
  176. {
  177. console.log ("Order calculate failed");
  178. var redirectUrl = "AjaxOrderItemDisplayView?storeId=" +
  179. shoppingActionsServicesDeclarationJS.storeId + "&catalogId=" +
  180. shoppingActionsServicesDeclarationJS.catalogId + "&langId=" +
  181. shoppingActionsServicesDeclarationJS.langId;
  182. document.location.href = getAbsoluteURL() + redirectUrl;
  183. }
  184.  
  185. }),
  186.  
  187. wc.service.declare({
  188. id: "AddToCartAjax",
  189. actionId: "AddToCartAjax",
  190. url: getAbsoluteURL() + "AddToCartAjax",
  191. formId: ""
  192.  
  193. /**
  194. * display a success message
  195. * @param (object) serviceResponse The service response object, which is the
  196. * JSON object returned by the service invocation
  197. */
  198.  
  199. ,successHandler: function(serviceResponse) {
  200. dropdownUpdated = false;
  201. cursor_clear();
  202. if(shoppingActionsJS){
  203.  
  204. var attributes = document.getElementsByName("attrValue");
  205.  
  206. var singleSKU = true;
  207.  
  208. for(var i=0; i<attributes.length; i++){
  209. if (attributes[i].options.length > 1)
  210. {
  211. singleSKU = false;
  212. }
  213. }
  214.  
  215. if (!singleSKU)
  216. {
  217. shoppingActionsJS.selectedAttributes = new Object();
  218. dojo.publish('attributesChanged_'+ shoppingActionsJS.baseCatalogEntryId, [dojo.toJson(shoppingActionsJS.selectedAttributes)]);
  219. for(var i=0; i<attributes.length; i++){
  220. if(attributes[i] != null){
  221. attributes[i].value = "";
  222. attributes[i].onchange();
  223. }
  224. }
  225. }
  226.  
  227. }
  228. if(typeof(ShipmodeSelectionExtJS)!= null && typeof(ShipmodeSelectionExtJS)!='undefined'){
  229. ShipmodeSelectionExtJS.setOrderItemId(serviceResponse.orderItemId[0]);
  230. }
  231. //dojo.publish("CMAddToCart");
  232. setShopCartRedirectCookie();
  233. /***********************************************************
  234.  
  235.  
  236. if($("#isAddtoCartFromPDPAttach").val()!= undefined && $("#isAddtoCartFromPDPAttach").val().indexOf('Y')!=-1) {
  237. }
  238. else{
  239. var accessoriesUrl = "PDPAccessoriesFinderView?storeId=" +
  240. shoppingActionsServicesDeclarationJS.storeId + "&catalogId=" +
  241. shoppingActionsServicesDeclarationJS.catalogId + "&langId=" +
  242. shoppingActionsServicesDeclarationJS.langId + "&productId=" +$("#PDPSku").val().split('_')[1]+"&SKU_ID="+$("#PDPSku").val().split('_')[0];
  243. $.ajax({
  244. url: getAbsoluteURL()+accessoriesUrl ,
  245. success: function(data) {
  246. $("body").append("<div style:visibility='hidden'>"+data+"</div>");
  247. if($("#PDPAccessoriesAssociations").val() != undefined && $("#PDPAccessoriesAssociations").val().indexOf('Y')!=-1) {
  248. var productId=$("#PDPSku").val().split('_')[1];
  249. updateCartQuantityInAddtoCart(serviceResponse.orderId);
  250. var redirectUrl = "AccessoriesView?storeId=" +
  251. shoppingActionsServicesDeclarationJS.storeId + "&catalogId=" +
  252. shoppingActionsServicesDeclarationJS.catalogId + "&langId=" +
  253. shoppingActionsServicesDeclarationJS.langId + "&productId=" +
  254. productId+"&SKU_ID="+$("#PDPSku").val().split('_')[0];
  255. document.location.href = getAbsoluteURL() + redirectUrl;
  256. }
  257. else {
  258. updateCartQuantityInAddtoCart(serviceResponse.orderId);
  259. var redirectUrl = "AjaxOrderItemDisplayView?storeId=" +
  260. shoppingActionsServicesDeclarationJS.storeId + "&catalogId=" +
  261. shoppingActionsServicesDeclarationJS.catalogId + "&langId=" +
  262. shoppingActionsServicesDeclarationJS.langId;
  263. document.location.href = getAbsoluteURL() + redirectUrl;
  264. }
  265. }
  266. });
  267. }
  268. */
  269. if($("#isAddtoCartFromPDPAttach").val()!= undefined && $("#isAddtoCartFromPDPAttach").val().indexOf('Y')!=-1) {
  270. }
  271. else{
  272. updateCartQuantityInAddtoCart(serviceResponse.orderId);
  273. var redirectUrl = "AjaxOrderItemDisplayView?storeId=" +
  274. shoppingActionsServicesDeclarationJS.storeId + "&catalogId=" +
  275. shoppingActionsServicesDeclarationJS.catalogId + "&langId=" +
  276. shoppingActionsServicesDeclarationJS.langId + "&hashString="+serviceResponse.hashString + "&catentDeletedName=" +serviceResponse.catentDeletedName;
  277. document.location.href = getAbsoluteURL() + redirectUrl;
  278. }
  279.  
  280. /****************************************************
  281.  
  282.  
  283. if($("#hasAccessoriesAssociations").val() != undefined && $("#hasAccessoriesAssociations").val().indexOf('Y')!=-1) {
  284. var productId=$("#hasAccessoriesAssociations").val().split('_')[1];
  285. //alert('productId '+productId);
  286. updateCartQuantityInAddtoCart(serviceResponse.orderId);
  287. var redirectUrl = "STOAccessoriesView?storeId=" +
  288. shoppingActionsServicesDeclarationJS.storeId + "&catalogId=" +
  289. shoppingActionsServicesDeclarationJS.catalogId + "&langId=" +
  290. shoppingActionsServicesDeclarationJS.langId + "&productId=" +productId;
  291. document.location.href = getAbsoluteURL() + redirectUrl;
  292. }
  293. else {
  294. updateCartQuantityInAddtoCart(serviceResponse.orderId);
  295. var redirectUrl = "AjaxOrderItemDisplayView?storeId=" +
  296. shoppingActionsServicesDeclarationJS.storeId + "&catalogId=" +
  297. shoppingActionsServicesDeclarationJS.catalogId + "&langId=" +
  298. shoppingActionsServicesDeclarationJS.langId;
  299. document.location.href = getAbsoluteURL() + redirectUrl;
  300. }
  301. **********************************************************************/
  302. }
  303. /**
  304. * display an error message
  305. * @param (object) serviceResponse The service response object, which is the
  306. * JSON object returned by the service invocation
  307. */
  308. ,failureHandler: function(serviceResponse) {
  309. if (serviceResponse.errorMessage) {
  310. if(serviceResponse.errorMessageKey == "_ERR_NO_ELIGIBLE_TRADING"){
  311. //MessageHelper.displayErrorMessage(storeNLS["ERROR_CONTRACT_EXPIRED_GOTO_ORDER"]);
  312. } else if (serviceResponse.errorMessageKey == "_ERR_RETRIEVE_PRICE") {
  313. var tempString = storeNLS["GENERICERR_MAINTEXT"];
  314. tempString = dojo.string.substitute(tempString,{0:storeNLS["GENERICERR_CONTACT_US"]});
  315. //MessageHelper.displayErrorMessage(tempString);
  316. } else {
  317. //MessageHelper.displayErrorMessage(serviceResponse.errorMessage);
  318. alert(serviceResponse.errorMessage);
  319. }
  320. }
  321. else {
  322. if (serviceResponse.errorMessageKey) {
  323. //MessageHelper.displayErrorMessage(serviceResponse.errorMessageKey);
  324. }
  325. }
  326. cursor_clear();
  327. }
  328.  
  329. }),
  330.  
  331.  
  332.  
  333.  
  334.  
  335.  
  336. //code for add to cart
  337.  
  338. wc.service.declare({
  339. id: "AddOrderItem1",
  340. actionId: "AddOrderItem",
  341. url: getAbsoluteURL() + "AjaxOrderChangeServiceItemAdd",
  342. formId: ""
  343.  
  344. /**
  345. * display a success message
  346. * @param (object) serviceResponse The service response object, which is the
  347. * JSON object returned by the service invocation
  348. */
  349.  
  350. ,successHandler: function(serviceResponse) {
  351. //MessageHelper.hideAndClearMessage();
  352. // Do not show this message. When item is added, we open up mini cart to display the currently added item.
  353. // MessageHelper.displayStatusMessage(storeNLS["SHOPCART_ADDED"]);
  354. dropdownUpdated = false;
  355. //showMiniShopCartDropDown('widget_minishopcart','quick_cart_container','orderItemsListAutoClose');
  356. //cursor_clear();
  357. cursor_wait();
  358. if(shoppingActionsJS){
  359.  
  360. var attributes = document.getElementsByName("attrValue");
  361.  
  362. var singleSKU = true;
  363.  
  364. for(var i=0; i<attributes.length; i++){
  365. if (attributes[i].options.length > 1)
  366. {
  367. singleSKU = false;
  368. }
  369. }
  370.  
  371. if (!singleSKU)
  372. {
  373. shoppingActionsJS.selectedAttributes = new Object();
  374. dojo.publish('attributesChanged_'+ shoppingActionsJS.baseCatalogEntryId, [dojo.toJson(shoppingActionsJS.selectedAttributes)]);
  375. for(var i=0; i<attributes.length; i++){
  376. if(attributes[i] != null){
  377. attributes[i].value = "";
  378. attributes[i].onchange();
  379. }
  380. }
  381. }
  382.  
  383. }
  384. if(typeof(ShipmodeSelectionExtJS)!= null && typeof(ShipmodeSelectionExtJS)!='undefined'){
  385. ShipmodeSelectionExtJS.setOrderItemId(serviceResponse.orderItemId[0]);
  386. }
  387. dojo.publish("CMAddToCart");
  388. setShopCartRedirectCookie();
  389. var params = [];
  390. params.storeId = WCParamJS.storeId;
  391. params.catalogId = WCParamJS.catalogId;
  392. params.langId = WCParamJS.langId;
  393. params.URL= "";
  394. params.updatePrices = "1";
  395. params.orderId = ".";
  396. params.calculationUsageId = "-1";
  397. wc.service.invoke("MiniCartOrderCalculate",params);
  398. }
  399. /**
  400. * display an error message
  401. * @param (object) serviceResponse The service response object, which is the
  402. * JSON object returned by the service invocation
  403. */
  404. ,failureHandler: function(serviceResponse) {
  405.  
  406. if (serviceResponse.errorMessage) {
  407. if(serviceResponse.errorMessageKey == "_ERR_NO_ELIGIBLE_TRADING"){
  408. //MessageHelper.displayErrorMessage(storeNLS["ERROR_CONTRACT_EXPIRED_GOTO_ORDER"]);
  409. } else if (serviceResponse.errorMessageKey == "_ERR_RETRIEVE_PRICE") {
  410. var tempString = storeNLS["GENERICERR_MAINTEXT"];
  411. tempString = dojo.string.substitute(tempString,{0:storeNLS["GENERICERR_CONTACT_US"]});
  412. //MessageHelper.displayErrorMessage(tempString);
  413. } else {
  414. //MessageHelper.displayErrorMessage(serviceResponse.errorMessage);
  415. alert(serviceResponse.errorMessage);
  416. }
  417. }
  418. else {
  419. if (serviceResponse.errorMessageKey) {
  420. //MessageHelper.displayErrorMessage(serviceResponse.errorMessageKey);
  421. }
  422. }
  423. cursor_clear();
  424. }
  425.  
  426. }),
  427.  
  428. /**
  429. * AA: Custom AjaxDeleteOrderItem service to handle the refresh
  430. scenario from mini cart pop up.
  431. * @constructor
  432. */
  433. wc.service.declare({
  434. id: "AjaxDeleteOrderItemTcs",
  435. actionId: "AjaxDeleteOrderItemTcs",
  436. url: getAbsoluteURL() +"AjaxOrderChangeServiceItemDelete",
  437. formId: ""
  438. /**
  439. * display a success message
  440. * @param (object) serviceResponse The service response object,
  441. which is the
  442. * JSON object returned by the service invocation
  443. */
  444. ,successHandler: function(serviceResponse) {
  445. dropdownInit = false;
  446. dropdownUpdated =false;
  447. setShopCartRedirectCookie();
  448. showMiniShopCartDropDown('widget_minishopcart','quick_cart_container','orderItemsListAutoClose1');
  449. updateCartCookie();
  450. wc.render.updateContext('MiniShoppingCartContext', {'status':'load'});
  451.  
  452. cursor_clear();
  453. }
  454. /**
  455. * display an error message
  456. * @param (object) serviceResponse The service response object,
  457. which is the
  458. * JSON object returned by the service invocation
  459. */
  460. ,failureHandler: function(serviceResponse) {
  461. if (serviceResponse.errorMessageKey == '_ERR_ORDER_IS_LOCKED' || serviceResponse.errorMessageKey == '_ERR_ORDER_IS_NOT_LOCKED') {
  462. alert (serviceResponse.errorMessage);
  463. }
  464. if (serviceResponse.errorMessage) {
  465. MessageHelper.displayErrorMessage
  466. (serviceResponse.errorMessage);
  467. }
  468. else {
  469. if (serviceResponse.errorMessageKey) {
  470. MessageHelper.displayErrorMessage
  471. (serviceResponse.errorMessageKey);
  472. }
  473. }
  474. cursor_clear();
  475. }
  476.  
  477. }),
  478.  
  479.  
  480. /**
  481. * Adds a pre-defined dynamic kit to a shopping cart in Ajax mode. A message is displayed after
  482. * the service call.
  483. * @constructor
  484. */
  485. wc.service.declare({
  486. id: "AddPreConfigurationToCart",
  487. actionId: "AddOrderItem",
  488. url: getAbsoluteURL() + "AjaxOrderChangeServiceAddPreConfigurationToCart",
  489. formId: ""
  490.  
  491. /**
  492. * display a success message
  493. * @param (object) serviceResponse The service response object, which is the
  494. * JSON object returned by the service invocation
  495. */
  496.  
  497.  
  498. ,successHandler: function(serviceResponse) {
  499. MessageHelper.hideAndClearMessage();
  500. cursor_clear();
  501. if(shoppingActionsJS){
  502.  
  503. var attributes = document.getElementsByName("attrValue");
  504.  
  505. var singleSKU = true;
  506.  
  507. for(var i=0; i<attributes.length; i++){
  508. if (attributes[i].options.length > 1)
  509. {
  510. singleSKU = false;
  511. }
  512. }
  513.  
  514. if (!singleSKU)
  515. {
  516. shoppingActionsJS.selectedAttributes = new Object();
  517. for(var i=0; i<attributes.length; i++){
  518. if(attributes[i] != null){
  519. attributes[i].value = "";
  520. attributes[i].onchange();
  521. }
  522. }
  523. }
  524. }
  525. if(typeof(ShipmodeSelectionExtJS)!= null && typeof(ShipmodeSelectionExtJS)!='undefined'){
  526. ShipmodeSelectionExtJS.setOrderItemId(serviceResponse.orderItemId[0]);
  527. }
  528. }
  529. /**
  530. * display an error message
  531. * @param (object) serviceResponse The service response object, which is the
  532. * JSON object returned by the service invocation
  533. */
  534. ,failureHandler: function(serviceResponse) {
  535.  
  536. if (serviceResponse.errorMessage) {
  537. if(serviceResponse.errorMessageKey == "_ERR_NO_ELIGIBLE_TRADING"){
  538. MessageHelper.displayErrorMessage(storeNLS["ERROR_CONTRACT_EXPIRED_GOTO_ORDER"]);
  539. } else if (serviceResponse.errorMessageKey == "_ERR_RETRIEVE_PRICE") {
  540. var tempString = storeNLS["GENERICERR_MAINTEXT"];
  541. tempString = dojo.string.substitute(tempString,{0:storeNLS["GENERICERR_CONTACT_US"]});
  542. MessageHelper.displayErrorMessage(tempString);
  543. } else {
  544. MessageHelper.displayErrorMessage(serviceResponse.errorMessage);
  545. }
  546. }
  547. else {
  548. if (serviceResponse.errorMessageKey) {
  549. MessageHelper.displayErrorMessage(serviceResponse.errorMessageKey);
  550. }
  551. }
  552. cursor_clear();
  553. }
  554.  
  555. })
Advertisement
Add Comment
Please, Sign In to add comment