Ejemplo n.º 1
0
 /**
  * Proxy PHP functions
  *
  * @param string $name
  * @param array $args
  * @return mixed
  */
 public function __call($name, $args)
 {
     $function = $this->_prefix . Bronto_Utils::underscore($name);
     if (!function_exists($function)) {
         throw new BadMethodCallException("Resource function {$function} does not exist.");
     }
     if (!array_key_exists($name, $this->_excluded) && !is_null($this->_resource)) {
         array_unshift($args, $this->_resource);
     }
     $return = call_user_func_array($function, $args);
     if ($name == 'close') {
         unset($this->_resource);
         $this->_resource = null;
         return $this;
     }
     if (is_resource($return)) {
         $this->_resource = $return;
         return $this;
     }
     return $return;
 }
Ejemplo n.º 2
0
 /**
  * Processing object before save data
  *
  * @return Mage_Core_Model_Abstract
  */
 protected function _beforeSave()
 {
     if ($this->isValueChanged()) {
         try {
             $fieldObject = Mage::helper('bronto_common')->getApi()->transferField();
             $fieldName = Bronto_Utils::normalize($this->getValue());
             if (!array_key_exists($fieldName, self::$_fieldCache)) {
                 $field = $fieldObject->getByName($fieldName);
                 if (!$field) {
                     $field->withName($fieldName)->withLabel($this->getValue())->asText()->asHidden();
                     $field->withId($fieldObject->add()->addField($field)->first()->getItem()->getId());
                 }
                 self::$_fieldCache[$fieldName] = $field;
             }
             $this->_saveConfigData(str_replace('_new', '', $this->getPath()), $field->getId());
             $this->setValue(null);
         } catch (Exception $e) {
             Mage::throwException(Mage::helper('adminhtml')->__('Unable to save new field: ') . $e->getMessage());
         }
     }
     return parent::_beforeSave();
 }
Ejemplo n.º 3
0
 /**
  * Returns a tuple of a prefixed camel-case name, ie:
  * $this->_camelizedValue('addSomething') == array('add', 'something')
  *
  * @param string $name
  * @return array($prefixed, $camelized)
  */
 protected function _camelizedValue($name)
 {
     if (preg_match('/^([^A-Z0-9]+).+/', $name, $match)) {
         $modified = $this->_stripAndLower($name, strlen($match[1]));
         return array($match[1], $this->_underscore ? Bronto_Utils::underscore($modified) : $modified);
     }
     return array("", "");
 }
Ejemplo n.º 4
0
 /**
  * Capture "Create New..." attributes, create field in Bronto, and save field id
  *
  * @param  array $attributesFields
  * @param string $section
  * @param string $group
  *
  * @return array
  */
 protected function _processDynamicAttributes($attributesFields = array(), $section, $group)
 {
     // Create Config Object
     $config = Mage::getModel('core/config');
     // Get Admin Scope Parameters
     $scopeParams = Mage::helper('bronto_common')->getScopeParams();
     // Get Array of Attributes that are hard-coded into system.xml
     $ignore = Mage::helper('bronto_customer')->getSystemAttributes();
     $api = Mage::helper('bronto_common')->getApi();
     $fieldCache = array();
     // Cycle Through Attribute Fields to Find and Save Dynamic Fields
     foreach ($attributesFields as $fieldId => $field) {
         // Save Dynamic 'Create New...' Fields
         if (preg_match('/_dynamic_new/', $fieldId) || preg_match('/_new/', $fieldId)) {
             // Strip off '_dynamic_new' or '_new' from Field ID to Get real Field ID
             $realField = preg_replace('/_dynamic_new|_new$/', '', $fieldId);
             if (!is_array($field)) {
                 $value = $field;
             } else {
                 $value = $field['value'];
             }
             if (is_null($value)) {
                 continue;
             }
             try {
                 /* @var $fieldObject Bronto_Api_Field */
                 $fieldObject = $api->transferField();
                 $fieldName = Bronto_Utils::normalize($value);
                 if (!array_key_exists($fieldName, $fieldCache)) {
                     $brontoField = $fieldObject->getByName($fieldName);
                     if (!$brontoField) {
                         $brontoField = $fieldObject->createObject()->withName($fieldName)->withLabel($value)->asText()->asHidden();
                         foreach ($fieldObject->add()->addField($brontoField) as $result) {
                             $item = $result->getItem();
                             if ($item->getIsError()) {
                                 Mage::throwException("{$item->getErrorCode()}: {$item->getErrorMessage()}");
                             }
                             $brontoField->withId($item->getId());
                         }
                     }
                     $fieldCache[$fieldName] = $brontoField;
                 }
                 $scope = $scopeParams['scope'];
                 if ($scope != 'default') {
                     $scope .= 's';
                 }
                 // Save Field To Config
                 $config->saveConfig($section . '/' . $group . '/' . $realField, $brontoField->getId(), $scope, $scopeParams[$scopeParams['scope'] . '_id']);
                 // Unset Dynamic Fields
                 unset($attributesFields[$realField]);
                 unset($attributesFields[$fieldId]);
                 unset($fieldObject);
             } catch (Exception $e) {
                 Mage::helper('bronto_customer')->writeError("Unable to save new field: {$value}: {$e->getMessage()}");
             }
         } elseif (array_key_exists('value', $field) && !in_array($fieldId, $ignore[$group])) {
             $scope = $scopeParams['scope'];
             if ($scope != 'default') {
                 $scope .= 's';
             }
             // Save Field To Config
             $config->saveConfig($section . '/' . $group . '/' . $fieldId, array_key_exists('value', $field) ? $field['value'] : '', $scope, $scopeParams[$scopeParams['scope'] . '_id']);
             // Unset Dynamic Field
             unset($attributesFields[$fieldId]);
         }
     }
     return $attributesFields;
 }