1 Reply Latest reply on Mar 2, 2011 4:35 AM by sowmya shivakumar

    Flex Store with PHP ?

    Chanuwan

      I will develop Flex Store with PHP from sample application.

       

      http://www.adobe.com/devnet/flex/samples/flex_store/

       

      I have a problem data transfer shopping cart to php file,

      i can't send all data sales.

       

      I use methods from http://cookbooks.adobe.com/post_Read_and_write_data_to_PHP_with_Flex-7744.html

       

      This is code from file ProductCart.mxml

       

      <?xml version="1.0" encoding="utf-8"?>
      <mx:VBox xmlns:mx="http://www.adobe.com/2006/mxml"
          xmlns:productsView="productsView.*"
          horizontalAlign="right"
          paddingTop="8"
          paddingBottom="8"
          paddingRight="4"
          paddingLeft="4"
          horizontalScrollPolicy="off"
          verticalScrollPolicy="off">
         
      <mx:HTTPService id="writeData" url="http://localhost/demo/write.php" method="GET" resultFormat="text" result="resultHandler(event)"/>

          <mx:Script>
              <![CDATA[
             
              import mx.controls.Alert;     
              import samples.flexstore.Product;
              import samples.flexstore.ProductListEvent;
             
              [Bindable]
              public var numProducts:int=0;
             
              [Bindable]
              private var total:Number = 0;

              private const SHIPPING:Number = 1.99;
             
              private function productListEventHandler(event:ProductListEvent):void
              {
                  switch (event.type)
                  {
                      case ProductListEvent.ADD_PRODUCT:
                          event.product.qty = 0; 
                                  
                      case ProductListEvent.DUPLICATE_PRODUCT:
                          event.product.qty++;
                          total += event.product.price;
                          numProducts++;
                          break;           
                      case ProductListEvent.PRODUCT_QTY_CHANGE:
                      case ProductListEvent.REMOVE_PRODUCT:
                          var items:Array = productList.items;
                          total = 0;
                          numProducts = 0;
                          for (var i:int=0; i < items.length; i++)
                          {
                              var product:Product = items.product;
                              total += product.qty * product.price;
                              numProducts += product.qty;
                          }      
                          break;
                      default:
                          break;
                  }
              }
             
              ]]>
          </mx:Script>
         <mx:Script>
                // This is function send data to php
                      // I do not know what to put variables "
      ????"
                 import mx.rpc.events.ResultEvent;
                  import mx.controls.Alert;
                  public function resultHandler( event: ResultEvent ):void
                  {
                      Alert.show( "Result "+String(event.result) );
                  }      
                  public function sendData( ):void
                  {
                      var objSend:Object = new Object;
                      objSend.first = "???";
                      objSend.second = "
      ????";
                      writeData.send( objSend );
                  }
           </mx:Script>


          <mx:CurrencyFormatter currencySymbol="" id="cf" precision="2"/>
         
          <mx:Label width="100%" text="Your Shopping Cart" styleName="sectionHeader"/>
             
          <productsView:ProductList id="productList" height="100%" width="100%"
              newItemStartX="-100" newItemStartY="-100"
              addProduct="productListEventHandler(event)"
              duplicateProduct="productListEventHandler(event)"
              productQtyChange="productListEventHandler(event)"
              removeProduct="productListEventHandler(event)"
              showQuantity="true"
              />
         
          <mx:Form verticalGap="0" paddingRight="0" width="239">

              <mx:FormItem label="Total:" width="184">

                  <mx:Label width="90" text="{cf.format(total)}" textAlign="right"/>

              </mx:FormItem>

              <mx:FormItem label="Shipping:" width="183">

                  <mx:Label width="90" text="{cf.format(numProducts * SHIPPING)} " textAlign="right"/>

              </mx:FormItem>

              <mx:FormItem label="Grand Total:" fontWeight="bold" width="182">

                  <mx:Label width="97" text="{cf.format(total + (numProducts * SHIPPING))} บาท" textAlign="right"/>

              </mx:FormItem>

          </mx:Form>

          <mx:Button label="Submit Order"  click="sendData( )"/>

      </mx:VBox>

       

       

      Best Regards,

      MrCha