@@ -31,6 +31,20 @@ function receiveImages(images) {
3131 }
3232}
3333
34+ function receiveVariants ( variants ) {
35+ return {
36+ type : t . PRODUCT_VARIANTS_RECEIVE ,
37+ variants
38+ }
39+ }
40+
41+ function receiveOptions ( options ) {
42+ return {
43+ type : t . PRODUCT_OPTIONS_RECEIVE ,
44+ options
45+ }
46+ }
47+
3448export function cancelProductEdit ( ) {
3549 return {
3650 type : t . PRODUCT_DETAIL_ERASE
@@ -320,6 +334,91 @@ export function fetchImages(productId) {
320334 }
321335}
322336
337+ export function fetchOptions ( productId ) {
338+ return ( dispatch , getState ) => {
339+ return api . products . options . list ( productId ) . then ( ( { status, json} ) => {
340+ dispatch ( receiveOptions ( json ) )
341+ } )
342+ . catch ( error => { } ) ;
343+ }
344+ }
345+
346+ export function fetchVariants ( productId ) {
347+ return ( dispatch , getState ) => {
348+ return api . products . variants . list ( productId ) . then ( ( { status, json} ) => {
349+ dispatch ( receiveVariants ( json ) )
350+ } )
351+ . catch ( error => { } ) ;
352+ }
353+ }
354+
355+ export function createVariant ( productId ) {
356+ return ( dispatch , getState ) => {
357+ // todo: get price, stock_quantity and weight from product details
358+ const variant = { price : 0 , stock_quantity : 0 , weight : 0 } ;
359+ return api . products . variants . create ( productId , variant ) . then ( ( { status, json} ) => {
360+ dispatch ( receiveVariants ( json ) )
361+ } )
362+ . catch ( error => { } ) ;
363+ }
364+ }
365+
366+ export function updateVariant ( productId , variantId , variant ) {
367+ return ( dispatch , getState ) => {
368+ return api . products . variants . update ( productId , variantId , variant ) . then ( ( { status, json} ) => {
369+ dispatch ( receiveVariants ( json ) )
370+ } )
371+ . catch ( error => { } ) ;
372+ }
373+ }
374+
375+ export function setVariantOption ( productId , variantId , optionId , valueId ) {
376+ return ( dispatch , getState ) => {
377+ const option = { option_id : optionId , value_id : valueId } ;
378+ return api . products . variants . setOption ( productId , variantId , option ) . then ( ( { status, json} ) => {
379+ dispatch ( receiveVariants ( json ) )
380+ } )
381+ . catch ( error => { } ) ;
382+ }
383+ }
384+
385+ export function createOption ( productId , option ) {
386+ return ( dispatch , getState ) => {
387+ return api . products . options . create ( productId , option ) . then ( ( { status, json} ) => {
388+ dispatch ( receiveOptions ( json ) )
389+ } )
390+ . catch ( error => { } ) ;
391+ }
392+ }
393+
394+ export function updateOption ( productId , optionId , option ) {
395+ return ( dispatch , getState ) => {
396+ return api . products . options . update ( productId , optionId , option ) . then ( ( { status, json} ) => {
397+ dispatch ( receiveOptions ( json ) )
398+ } )
399+ . catch ( error => { } ) ;
400+ }
401+ }
402+
403+
404+ export function deleteOption ( productId , optionId ) {
405+ return ( dispatch , getState ) => {
406+ return api . products . options . delete ( productId , optionId ) . then ( ( { status, json} ) => {
407+ dispatch ( receiveOptions ( json ) )
408+ } )
409+ . catch ( error => { } ) ;
410+ }
411+ }
412+
413+
414+ export function deleteVariant ( productId , variantId ) {
415+ return ( dispatch , getState ) => {
416+ return api . products . variants . delete ( productId , variantId ) . then ( ( { status, json} ) => {
417+ dispatch ( receiveVariants ( json ) )
418+ } )
419+ . catch ( error => { } ) ;
420+ }
421+ }
323422
324423export function deleteImage ( productId , imageId ) {
325424 return ( dispatch , getState ) => {
0 commit comments