/**
  * Get all available shipping methods.
  *
  * <p>Request parameter (either or):</p>
  * <ul>
  *  <li>addressId - A valid address id (only accepted if owned by the current user)</li>
  *  <li>Any address proerty (<em>countryId, zoneId, postcode, etc.</em>)</li>
  * </ul>
  *
  * @param ZenMagick\Http\Request request The current request.
  */
 public function getShippingMethodsJSON($request)
 {
     // try to set up an address using request information
     $address = null;
     if (null !== ($addressId = $request->getParameter('addressId'))) {
         $address = $this->container->get('addressService')->getAddressForId($addressId, $this->getUser()->getId());
     } else {
         $data = array();
         foreach (array('countryId', 'zoneId', 'state', 'suburb', 'postcode', 'city') as $property) {
             if (null !== ($value = $request->getParameter($property))) {
                 $data[$property] = $value;
             }
         }
         if (0 < count($data)) {
             $address = Beans::map2obj('Address', $data);
         }
     }
     $shoppingCart = $this->get('shoppingCart');
     if (null == $address) {
         $address = $shoppingCart->getShippingAddress();
     }
     $shippingMethods = array();
     if (null != $address && !$shoppingCart->isEmpty()) {
         foreach ($this->container->get('shippingProviderService')->getShippingProviders(true) as $provider) {
             foreach ($provider->getShippingMethods($shoppingCart, $address) as $shippingMethod) {
                 $shippingMethods[] = $shippingMethod;
             }
         }
     }
     $flatObj = $this->flattenObject($shippingMethods, $this->get('ajaxShippingMethodMap'));
     $json = json_encode($flatObj);
     $this->setJSONHeader($json);
 }
 /**
  * Build a collection of Widget and/or ConfigValue objects
  *
  * @param array array of config values
  * @return array A list of <code>ConfigValue</code>s.
  */
 protected function buildObjects($configValues)
 {
     $values = array();
     $translator = $this->container->get('translator');
     foreach ($configValues as $value) {
         if (0 === strpos($value['setFunction'], 'widget@')) {
             $widgetDefinition = $value['setFunction'] . '&' . $value['useFunction'];
             // build definition from both function values (just in case)
             $definition = str_replace('widget@', '', $widgetDefinition);
             // handle old definition ids in the db
             if (0 === strpos($definition, 'ZM')) {
                 $definition = lcfirst(substr($definition, 2));
             }
             $widget = Beans::getBean($definition, $this->container);
             if (null !== $widget) {
                 $widget->setTitle($value['name']);
                 $widget->setDescription($value['description']);
                 $widget->setValue($value['value']);
                 // needed for generic plugin config support
                 $widget->set('configurationKey', $value['key']);
                 $values[] = $widget;
             } else {
                 $this->container->get('logger')->warn('failed to create widget: ' . $widgetDefinition);
             }
         } else {
             // try to convert into widget...
             $widget = null;
             $setFunction = $value['setFunction'];
             if (null != $setFunction) {
                 $tmp = explode('(', $setFunction);
                 $setFunction = trim($tmp[0]);
             }
             switch ($setFunction) {
                 case null:
                     $widget = $this->container->get('textFormWidget');
                     $size = strlen($value['value']) + 3;
                     $size = 64 < $size ? 64 : $size;
                     $widget->set('size', $size);
                     break;
                 case 'zen_cfg_textarea':
                     $widget = $this->container->get('textAreaFormWidget');
                     $widget->setRows(5);
                     $widget->setCols(60);
                     break;
                 case 'zen_cfg_textarea_small':
                     $widget = $this->container->get('textAreaFormWidget');
                     $widget->setRows(1);
                     $widget->setCols(35);
                     break;
                 case 'zen_cfg_select_option':
                     // XXX: perhaps make radio group
                     $widget = $this->container->get('selectFormWidget');
                     $widget->setOptions($this->splitOptions($value['setFunction']));
                     if (3 < count($widget->getOptions(null))) {
                         $widget->setStyle('select');
                     } else {
                         $widget->setStyle('radio');
                     }
                     break;
                 case 'zen_cfg_select_drop_down':
                     $widget = $this->container->get('selectFormWidget');
                     $widget->setOptions($this->splitOptions($value['setFunction']));
                     break;
                 case 'zen_cfg_pull_down_order_statuses':
                     $widget = $this->container->get('orderStatusSelectFormWidget');
                     break;
                 case 'zen_cfg_pull_down_country_list':
                     $widget = $this->container->get('countrySelectFormWidget');
                     break;
                 case 'zen_cfg_pull_down_country_list_none':
                     $widget = $this->container->get('countrySelectFormWidget');
                     $widget->setOptions(array('' => $translator->trans('None')));
                     break;
                 case 'zen_cfg_pull_down_htmleditors':
                     $widget = $this->container->get('textFormWidget');
                     $widget->set('readonly', true);
                     //$widget = $this->container->get('EditorSelectFormWidget');
                     break;
                 case 'zen_cfg_pull_down_zone_list':
                     $widget = $this->container->get('zoneSelectFormWidget');
                     $widget->setOptions(array('' => $translator->trans('None')));
                     break;
                 case 'zen_cfg_select_coupon_id':
                     $widget = $this->container->get('couponSelectFormWidget');
                     $widget->setOptions(array('' => $translator->trans('None')));
                     break;
                 default:
                     $widget = Beans::map2obj('ZenMagick\\StoreBundle\\Entity\\ConfigValue', $value);
                     break;
             }
             if ($widget instanceof Widget) {
                 // common stuff
                 $widget->setName($value['key']);
                 $widget->setTitle($value['name']);
                 $widget->setDescription(htmlentities($value['description']));
                 $widget->setValue(htmlentities($value['value']));
                 $widget->set('id', $value['key']);
                 // needed for generic plugin config support
                 $widget->set('configurationKey', $value['key']);
             }
             $values[] = $widget;
         }
     }
     return $values;
 }
Esempio n. 3
0
 /**
  * Test map2obj.
  */
 public function testMap2obj()
 {
     $data = array('foo' => 'bar', 'doh' => 'nut');
     // test all
     $expectAll = array('foo' => 'bar', 'doh' => 'nut', 'properties' => array('foo' => 'bar', 'doh' => 'nut'), 'propertyNames' => array('foo', 'doh'), 'attachedMethods' => array());
     $obj = Beans::map2obj('ZenMagick\\Base\\ZMObject', $data);
     $map = Beans::obj2map($obj);
     $this->assertEquals($expectAll, $map);
     $this->assertTrue($obj instanceof ZMObject);
     // test some
     $expectSome = array('foo' => 'bar', 'properties' => array('foo' => 'bar'), 'propertyNames' => array('foo'), 'attachedMethods' => array());
     $obj = Beans::map2obj('ZenMagick\\Base\\ZMObject', $data, array('foo'));
     $map = Beans::obj2map($obj);
     $this->assertEquals($expectSome, $map);
     $this->assertTrue($obj instanceof ZMObject);
 }
Esempio n. 4
0
 /**
  * Build a collection of ConfigValue objects
  *
  * @param array array of config values
  * @return array A list of <code>ConfigValue</code>s.
  */
 protected function buildObjects($configValues)
 {
     $values = array();
     foreach ($configValues as $value) {
         $values[] = Beans::map2obj('ZenMagick\\StoreBundle\\Entity\\ConfigValue', $value);
     }
     return $values;
 }