getRequest()->getBaseUrl(); $translate = $this->getTranslate(); $this->setBodyCode('') ->setBodyCode( ""); } /** * * get custom fields array * * @return array */ public function getCustomFields() { return $this->_customFields; } /** * * set custom fields array * * @param array $customFields * * @return $this */ public function setCustomFields($customFields) { $this->_customFields = $customFields; return $this; } /** * * get form data * * @param string $key * * @return mixed */ public function getFormData($key = null) { if ($key !== null) { if (!empty($this->_formData[$key])) { return $this->_formData[$key]; } return null; } return $this->_formData; } /** * * set form data * * @param array $formData * * @return $this */ public function setFormData($formData) { $this->_formData = $formData; return $this; } /** * * check empty flag * * @return boolean */ public function isEmpty() { return $this->_empty; } /** * * set empty flag * * @param boolean $empty * * @return $this */ public function setEmpty($empty) { $this->_empty = $empty; return $this; } public function render() { $output = null; $array = array(); $customFields = $this->getCustomFields(); foreach ($customFields as $key => $customField) { if ($customField['product_attribute']) { $customFields[$key]['multiOptions'] = $multiOptions = \Ppb\Utility::unserialize($customField['multiOptions']); if (!empty($multiOptions['key'])) { $id = intval(str_replace('custom_field_', '', $customField['id'])); $value = array_filter($multiOptions['key']); $customFieldData = (array)$this->getFormData($customField['id']); $array[$id] = array_intersect($customFieldData, $value); } } } $cartesian = array_filter( $this->_cartesian($array)); if (count($cartesian) > 0) { $values = $this->getValue(); $translate = $this->getTranslate(); $cloneButton = true; $helper = new ProductAttributesHelper(); foreach ($cartesian as $key => $row) { $value = str_ireplace( array("'", '"'), array(''', '"'), serialize($row)); $price = null; $quantity = null; foreach ((array)$values as $k => $v) { if (!empty($values[$k][self::FIELD_OPTIONS])) { if (\Ppb\Utility::unserialize($values[$k][self::FIELD_OPTIONS]) == $row) { $quantity = (!empty($values[$k][self::FIELD_QUANTITY])) ? abs(intval($values[$k][self::FIELD_QUANTITY])) : null; $price = (!empty($values[$k][self::FIELD_PRICE])) ? abs(floatval($values[$k][self::FIELD_PRICE])) : null; } } } $output .= ''; $this->removeAttribute('placeholder')->addAttribute('placeholder', $translate->_('Qty')); $output .= '' . '
' . ' renderAttributes() . ' value="' . $quantity . '" ' . $this->_endTag; if ($cloneButton === true) { $output .= ''; } $this->removeAttribute('placeholder')->addAttribute('placeholder', $translate->_('Price')); $output .= ' ' . $translate->_('Add Extra:') . ' renderAttributes() . ' value="' . $price . '" ' . $this->_endTag; $output .= '
' . '
'; $cloneButton = false; } } if ($output == null) { $this->setEmpty(true); $hidden = new Element\Hidden($this->_name); $output = $hidden->render(); } return '
' . $output . '
'; } /** * * create the cartesian product of the input array * * @param array $input * * @return array */ protected function _cartesian($input) { // filter out empty values $input = array_filter($input); $result = array(array()); foreach ($input as $key => $values) { $append = array(); foreach ($result as $product) { foreach ($values as $item) { $product[$key] = $item; $append[] = $product; } } $result = $append; } return $result; } }