public function uploadOptionFile() { ClassLoader::import('application.model.order.OrderedItemOption'); $field = 'upload_' . $this->request->get('field'); $option = ActiveRecordModel::getInstanceById('ProductOption', $this->request->get('id'), true); $validator = $this->getValidator('optionFile'); $this->addOptionValidation($validator, $option->toArray(), $field); if (!$validator->isValid()) { return new JSONResponse(array('error' => $validator->getErrorList())); } // create tmp file $file = $_FILES[$field]; $tmp = 'tmp_' . $field . md5($file['tmp_name']) . '__' . $file['name']; $dir = ClassLoader::getRealPath('public.upload.optionImage.'); $path = $dir . $tmp; if (!file_exists($dir)) { mkdir($dir); chmod($dir, 0777); } move_uploaded_file($file['tmp_name'], $path); // create thumbnail $thumb = null; if (@getimagesize($path)) { $thumb = 'tmp_thumb_' . $tmp; $thumbPath = $dir . $thumb; OrderedItemOption::resizeImage($path, $thumbPath, 1); } return new JSONResponse(array('name' => $file['name'], 'file' => $tmp, 'thumb' => $thumb)); }
public function loadItems() { if (!$this->isExistingRecord()) { return false; } $this->event('before-load'); $itemSet = $this->getRelatedRecordSet('OrderedItem', new ARSelectFilter(), array('Product', 'Category', 'DefaultImage' => 'ProductImage')); $this->orderedItems = $itemSet->getData(); $products = $itemSet->extractReferencedItemSet('product'); ProductPrice::loadPricesForRecordSet($products); $parentIDs = $products->extractReferencedItemSet('parent')->getRecordIDs(); if ($parentIDs) { ActiveRecordModel::getRecordSet('Product', new ARSelectFilter(new INCond(new ARFieldHandle('Product', 'ID'), $parentIDs)), array('Category', 'ProductImage')); } if ($this->orderedItems) { if (!$this->shipments || !$this->shipments->size()) { $this->shipments = $this->getRelatedRecordSet('Shipment', new ARSelectFilter(), array('UserAddress', 'ShippingService')); // @todo: should be loaded automatically foreach ($this->shipments as $shipment) { if ($shipment->shippingAddress->get()) { $shipment->shippingAddress->get()->load(); } } } if (!$this->shipments->size() && !$this->isFinalized->get()) { $this->shipments = unserialize($this->shipping->get()); } OrderedItemOption::loadOptionsForItemSet(ARSet::buildFromArray($this->orderedItems)); ARSet::buildFromArray($this->orderedItems)->extractReferencedItemSet('product', 'ProductSet')->loadVariations(); foreach ($this->orderedItems as $key => $item) { if ($item->parent->get()) { $item->parent->get()->registerSubItem($item); unset($this->orderedItems[$key]); } } Product::loadAdditionalCategoriesForSet(ARSet::buildFromArray($this->orderedItems)->extractReferencedItemSet('product')); } if (!$this->isFinalized->get() && $this->orderedItems) { return $this->updateToStock(); } $this->event('after-load'); }
public function addProductOptionChoice(ProductOptionChoice $choice) { $choice = OrderedItemOption::getNewInstance($this, $choice); $this->optionChoices[$choice->choice->get()->option->get()->getID()] = $choice; if ($this->isFinalized()) { $choice->updatePriceDiff(); $this->price->set($this->price->get() + $this->reduceBaseTaxes($choice->priceDiff->get())); } return $choice; }
public function addOptionChoice(ProductOptionChoice $choice) { if (!$choice->isLoaded()) { $choice->load(); } foreach ($this->optionChoices as $key => $ch) { // already added? if ($ch->choice->get()->getID() == $choice->getID()) { return $ch; } // other choice from the same option - needs removal if ($ch->choice->get()->option->get()->getID() == $choice->option->get()->getID()) { $this->removeOptionChoice($ch->choice->get()); } } $choice = OrderedItemOption::getNewInstance($this, $choice); $this->optionChoices[$choice->choice->get()->option->get()->getID()] = $choice; if ($this->isFinalized()) { $choice->updatePriceDiff(); $this->price->set($this->price->get() + $this->reduceBaseTaxes($choice->priceDiff->get())); } return $choice; }
public function addOptionChoice(ProductOptionChoice $choice) { if (!$choice->isLoaded()) { $choice->load(); } foreach ($this->optionChoices as $key => $ch) { // already added? if ($ch->choice->get()->getID() == $choice->getID()) { return $ch; } // other choice from the same option - needs removal if ($ch->choice->get()->option->get()->getID() == $choice->option->get()->getID()) { $this->removedChoices[] = $ch; unset($this->optionChoices[$key]); } } $choice = OrderedItemOption::getNewInstance($this, $choice); $this->optionChoices[$choice->choice->get()->option->get()->getID()] = $choice; return $choice; }