/** * Sets the attributes in the given service item. * * @param MShop_Order_Item_Base_Service_Interface $orderServiceItem Order service item that will be added to the basket * @param array $attributes Attribute key/value pairs entered by the customer during the checkout process * @param string $type Type of the configuration values (delivery or payment) */ protected function _setConfigFE(MShop_Order_Item_Base_Service_Interface $orderServiceItem, array $attributes, $type) { $manager = MShop_Factory::createManager($this->_context, 'order/base/service/attribute'); $attributeItems = array(); foreach ($attributes as $key => $value) { $ordBaseAttrItem = $manager->createItem(); $ordBaseAttrItem->setCode($key); $ordBaseAttrItem->setValue(strip_tags($value)); // prevent XSS $ordBaseAttrItem->setType($type); $attributeItems[] = $ordBaseAttrItem; } $orderServiceItem->setAttributes($attributeItems); }
/** * Sets a service as delivery or payment service for an order. * * @param MShop_Order_Item_Base_Service_Interface $service Order service item for the given domain * @param string $type Service type * @return MShop_Order_Item_Base_Service_Interface Item that was really added to the basket */ public function setService(MShop_Order_Item_Base_Service_Interface $service, $type) { $this->_checkPrice($service->getPrice()); $this->_notifyListeners('setService.before', $service); // enforce that the type is the same as the given one $service->setType($type); $this->_services[$type] = clone $service; $this->_modified = true; $this->_notifyListeners('setService.after', $service); return $this->_services[$type]; }
/** * Saves a list of attributes for the order service. * * @param array $attributes Attributes which have to be saved * @param MShop_Order_Item_Base_Service_Interface $serviceItem Service Item which saves the attributes */ protected function _saveAttributes(array $attributes, MShop_Order_Item_Base_Service_Interface $serviceItem, $type = 'payment/paypal') { $attributeManager = MShop_Factory::createManager($this->_getContext(), 'order/base/service/attribute'); $map = array(); foreach ($serviceItem->getAttributes() as $attributeItem) { $map[$attributeItem->getCode()] = $attributeItem; } foreach ($attributes as $code => $value) { if (array_key_exists($code, $map) !== true) { $attributeItem = $attributeManager->createItem(); $attributeItem->setServiceId($serviceItem->getId()); $attributeItem->setCode($code); $attributeItem->setType($type); } else { $attributeItem = $map[$code]; } $attributeItem->setValue($value); $attributeManager->saveItem($attributeItem); } }
/** * Sets the attributes in the given service item. * * @param MShop_Order_Item_Base_Service_Interface $orderServiceItem Order service item that will be added to the basket * @param array $attributes Attribute key/value pairs entered by the customer during the checkout process * @param string $type Type of the configuration values (delivery or payment) */ protected function _setAttributes(MShop_Order_Item_Base_Service_Interface $orderServiceItem, array $attributes, $type) { $manager = MShop_Factory::createManager($this->_context, 'order/base/service/attribute'); foreach ($attributes as $key => $value) { $item = $manager->createItem(); $item->setCode($key); $item->setValue($value); $item->setType($type); $orderServiceItem->setAttributeItem($item); } }